# 30.3 Images, documents and the Files API (/building-ai-workers/shipping-claude-applications/images-documents-and-files)

---
type: Document
title: "30.3 Images, documents and the Files API"
description: "How Claude reads an image or a PDF, how the Files API lets you upload once and reuse an id, which faults come from the file, and why a file id cannot cross a workspace."
status: stable
order: 330.03
ksor:
  owner: team:panaversity
  audience:
    - public
  approval:
    by: process:panaversity
    at: 2026-11-30T10:58:03Z
chapter: '30'
part: III
expert_status: builder-only
concepts: [ "30.3" ]
last_verified: '2026-11-30'

sources:
  - id: anthropic-vision
    title: Vision (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/vision
  - id: anthropic-bedrock
    title: Claude in Amazon Bedrock (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock
  - id: anthropic-google-managed
    title: Claude Models on Google Cloud, Google managed (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/google-managed
  - id: anthropic-files-api
    title: Files API (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/files
  - id: anthropic-errors
    title: Errors (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/api/errors
  - id: anthropic-pdf-support
    title: PDF support (Claude API docs, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/pdf-support
generated:
  at: 2026-11-30T10:58:03Z
  by: esl-rewrite/1.2.0+ksor.1
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** A clerk who receives the same contract every week does not photocopy it each time. She files it once and says "the contract in drawer 4". But "drawer 4" means something only in her own office. Say it to the branch office across town, and they open their own drawer 4 and find nothing there. Sending a file once and naming it after that is what the Files API does. And the name works only in the place where the file was filed.

**What you will learn.** You practice this in Lab 30, Tasks 1 to 3.

- How does Claude read an image or a PDF?
- What does uploading once give you?
- Which faults come from the file, not the model?
- Who can read a file?
- Which file ids work in which environment?

**Why it matters.** Many of Brightline's small vendors still send paper invoices, and Ana photographs them on her phone.<!-- EDITOR: proposed in the spec, not yet in specs/labs/part-2-facts.md (paper invoices from Brightline's small vendors, photographed by Ana) --> An application that reads only typed text cannot read them. And a file sent once is named by an id that only one place can read. So the id that works on your laptop can fail in production.

**At work.** It is Monday, May 17, 2027.<!-- EDITOR: proposed in the spec, not yet in specs/labs/part-2-facts.md (the chapter's clock: Monday, May 17 and Tuesday, May 18, 2027) --> The photo and the scan work on your laptop, by their ids. <!-- OPEN: the photo's and the scan's invoice numbers and sizes, from the kit and a recorded run (spec point 22: whether D2's INV-9101 to INV-9103 stay, since they sit next to Cedar Ridge's INV-9001) --> Nobody has said which workspace their ids belong to in production.

### How does Claude read an image or a PDF?

**In a content block that holds the file.** A message can hold more than text. An **image block** holds a picture. A **document block** holds a PDF, which Claude reads as the text of each page plus an image of each page.[^anthropic-pdf-support]

Claude reads four image types: JPEG, PNG, GIF and WebP.[^anthropic-vision] A HEIC photo is not one of them. A document block also takes plain text, such as a `.csv` file, but it refuses Word and Excel files, which must be converted first.[^anthropic-pdf-support]

A **media type** is the label that says what kind of file the bytes are, such as `image/jpeg` or `application/pdf`. Each block takes its content in one of three ways:[^anthropic-vision][^anthropic-pdf-support]

| Way | What you send | Fits when |
| --- | --- | --- |
| Inline | The file's bytes, encoded as text (**base64**), with its media type | A small file, used once |
| A web address | A URL the API fetches | A public file. Never a private invoice |
| A file id | The id the Files API gave you when you uploaded the file | A file used in many requests, or by many steps |

<!-- FIGURE 30.3: Two halves, left and right, divided by a vertical dashed line labeled "workspace". Left half, headed "Staging workspace": one invoice photo at the top, with three arrows pointing down from it to three boxes in a row, labeled "inline bytes (base64)", "a web address" and "a file id". The arrow to "a web address" is dashed, with a small label "public files only, never a private invoice". Each of the three boxes has an arrow pointing down to one box "Claude". Under the "a file id" box, a small box "file_abc..., workspace: staging". Right half, headed "Production workspace": a key labeled "the production key". An arrow from the production key crosses the dashed line, pointing left at the box "file_abc..., workspace: staging", and ends in a red mark labeled "404". Under the right half, a note: "a file id works only in the workspace that uploaded it". Alt text must say: the three ways a file reaches Claude (inline bytes, a web address, a file id), that a web address fits only a public file and never a private invoice, that the file id was uploaded in the staging workspace, that the line between the halves is the workspace boundary, and that the production key asking for the staging id gets a 404. -->

*Figure 30.3. Three ways in, and the workspace line. A file id belongs to the workspace that uploaded it, so the production key gets a 404 for a staging id.*

### What does uploading once give you?

**An id you name in every later request, instead of the bytes.** You upload the file, get back an id, and put the id in the image or document block. You send the bytes once, not on every turn of the loop. The Files API is out of beta and needs no beta header, and both SDKs call it as `client.files`.[^anthropic-files-api]

The file is not free each time you use it. File operations are free, but "file content used in Messages requests is priced as input tokens."[^anthropic-files-api] So an id makes each request smaller to send. It does not make the model read less. <!-- OPEN: the two request sizes and their input tokens, from a recorded run of `scripts/ingest.ts` with and without `--inline` -->

A file stays until you delete it, or until an expiry you set when you upload it. [30.2](#302-what-crosses-the-application-boundary) says what that means for what is kept.

### Which faults come from the file, not the model?

**Each one in this table. The fix is always to change the request.** The SDK does not retry a 400, a 404 or a 413, so those reach your code at once.[^anthropic-errors]

| What you see | Cause | Fix |
| --- | --- | --- |
| An error for a type the API does not support <!-- OPEN: the status and error type the API returns for a HEIC photo labeled as JPEG. No vendor page states it. Fill from the recorded response in `tests/fixtures/errors/` --> | A HEIC photo labeled as JPEG, or a Word file sent as a PDF | Check the media type before you send. Convert the file to a supported type, and send the type that matches the bytes |
| 404 for a file id | The file was deleted, or it was uploaded with another workspace's key[^anthropic-files-api] | Upload it with this environment's key, and store the id with the workspace it belongs to |
| The request fails before the model runs <!-- OPEN: the status for a Messages request that names an expired file. The Files API page says only that it "fails before inference" --> | The file's expiry has passed[^anthropic-files-api] | Upload it again, with an expiry that lasts longer than the invoice is in use |
| 413 `request_too_large`, or an error about pages <!-- OPEN: the status for a PDF over its page limit. The PDF page gives no status --> | The request is over 128 MB, a file is over 500 MB, or a PDF has more pages than the limit[^anthropic-errors][^anthropic-files-api][^anthropic-pdf-support] | Split the PDF, shrink the image, or send fewer files in one request |
| 400 that names the content block | A file id sent in the wrong kind of block, such as a PDF's id in an image block[^anthropic-files-api] | Send an image's id in an image block, and a PDF's or a text file's id in a document block |
| 400 when you download a file | You asked for the content of a file you uploaded. Only files made by skills or code execution can be downloaded[^anthropic-files-api] | Keep your own copy of what you upload |
| A good-looking answer with wrong amounts | A blurred or tiny scan, read without complaint[^anthropic-vision] | Not an API fault. Check the amounts against the purchase order, and send unreadable scans to a person |

Each of the first six is a fault in what was sent, not in the model. Most are **integration faults** ([21.9](../agent-loop-by-hand/when-the-loop-goes-wrong.md)), which means your code sent the wrong thing. The 404 for another workspace's id is a fault in configuration, the cell this section's last part fills. Retrying sends the same request again, and fails the same way. The last row is not an error at all. So a scan Claude misread is a case for Chapter 24's suite, not for an error handler.

The cheapest place to catch a bad type is before any request. The worker's **media-type check** is a few lines of its own code. They read each file's type and refuse anything but the four image types and PDF. It refuses [INV-9103] on the laptop, and a test proves it.

### Who can read a file?

**Any key for the workspace that uploaded it.** "Files are not scoped to an end user, conversation, or session. Any API key with access to a workspace can access any files uploaded to that workspace."[^anthropic-files-api] So never accept a file id from a user or from a document. Keep your own table of which company and which person uploaded each file, and check it on every request before the id reaches Claude.

Brightline's worker keeps that table in `data/file-ids.json`: each id with its workspace and its company. Brightline's portal also serves Cedar Ridge Supply. Suppose a Cedar Ridge file id reaches the worker during a Brightline question. The worker's own table refuses it before any request. In Lab 30, Task 3, a test sends that id, and a second test proves the first one fails if the check is removed.

If each company must be kept fully apart, give each its own workspace. Anthropic calls the workspace "the isolation boundary for files".[^anthropic-files-api] Delete a file when its invoice is closed, or set an expiry when you upload it. An expiry sets how long the file lives. It is not proof that the content is gone.[^anthropic-files-api]

### Which file ids work in which environment?

**Only the ids uploaded in the workspace that environment's key reads.** This is the third row of `docs/environments.md`. Each environment's credential reads one workspace, and staging and production each have one ([23.4](../hosted-agents/resources-as-code.md)).

Your laptop uses the staging key in `.secrets/anthropic.env`, so development and staging share the staging workspace. Production has its own. "The portal's production key never sits on your computer" ([Chapter 23's reference](../hosted-agents/reference.md)). So an id you uploaded on the laptop answers 404 in production.

The trap is in the kit. The portal's morning job reads stored ids from `data/file-ids.json`. Unless production uploads its own files, it would reuse staging's ids, and every one would fail.

| Row | Development: the laptop | Staging: CI and the staging workspace | Production: the portal |
| --- | --- | --- | --- |
| 3 Which workspace the file ids belong to | Staging, through the key in `.secrets/anthropic.env`. Proof: `data/file-ids.json[*].workspace` | Same. CI's live job: [its credential] <!-- OPEN: which credential CI's live suite job uses, and so which workspace it reads (spec point 19, Lab 24's EDITOR note at evaluating-ai-workers/lab.md:232) --> | Production, through the portal's production key. Proof: `config/prompts.yaml#production.workspace` is `production`, and the ingestion reads only ids whose workspace matches it |

This is the cell Tuesday's check failed on ([the point](#the-point)). You never record production's 404 yourself, because you never hold the production key.

Amazon Bedrock and Claude Models on Google Cloud (Google managed) have no Files API, and take images and PDFs as base64 only.[^anthropic-vision][^anthropic-bedrock][^anthropic-google-managed] If one environment ran there, its row-3 cell would say "inline only", and code that sends file ids would fail there. [30.8](#308-how-todays-tools-realize-it) lists each platform.

**The operating rule:** send a file once and reuse its id, and check the media type before you send. Treat a file error as yours to fix. Never take a file id from outside your own table, and store each id with the workspace that can read it.

**Do this now.** Ask your coding agent to find every file this project sends to Claude. Copy this line:

> Find every place this project sends Claude an image or a PDF. For each one, say whether it sends the bytes, a web address or a file id, and what checks the file's type before it is sent. Then, for each file id the project stores, say which workspace it belongs to, which company it belongs to, and which environment's key can read it. Name any environment that would use an id it cannot read. Change no file.

**Read next.** [30.4](#304-errors-by-class-retry-fall-back-or-fix) sorts every error by its class, and decides which ones may go to another model.

[^anthropic-pdf-support]: PDF support, Claude API docs, Anthropic.
[^anthropic-vision]: Vision, Claude API docs, Anthropic.
[^anthropic-files-api]: Files API, Claude API docs, Anthropic.
[^anthropic-errors]: Errors, Claude API docs, Anthropic.
[^anthropic-bedrock]: Claude in Amazon Bedrock, Claude API docs, Anthropic.
[^anthropic-google-managed]: Claude Models on Google Cloud, Google managed, Claude API docs, Anthropic.
