Claude Files API — Upload, Reference, and Manage Files

How to use Anthropic's Files API to upload documents, images, and PDFs once and reference them across multiple Claude API requests. Python and TypeScript examples.

🔥 Launch tonight — Power Prompts PDF 50p (just 50p tonight)30 battle-tested Claude Code prompts · 8 pages · paste into CLAUDE.md · price reverts to £5

Anthropic's Files API lets you upload a file once and reference it by ID in multiple API requests. Instead of re-sending a large PDF or image as base64 on every call, you upload it once, get a file_id, and attach it by reference. This reduces bandwidth and, combined with prompt caching, cuts cost dramatically for repeated large-document workflows.

Supported file types

TypeExtensionsMax size
Documents.pdf, .txt, .md, .html, .csv, .xml, .json32 MB
Images.jpg, .png, .gif, .webp20 MB

Total storage per workspace: 100 GB. Files expire after 30 days of non-use.

Upload a file (Python)

import anthropic

client = anthropic.Anthropic()

with open("contract.pdf", "rb") as f:
    response = client.beta.files.upload(
        file=("contract.pdf", f, "application/pdf")
    )

file_id = response.id
print(f"Uploaded: {file_id}")  # file_01ABC...

Reference the file in a message

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "document",
                "source": {
                    "type": "file",
                    "file_id": file_id
                }
            },
            {
                "type": "text",
                "text": "Summarise the key obligations in this contract."
            }
        ]
    }]
)
print(message.content[0].text)

TypeScript example

import Anthropic from "@anthropic-ai/sdk";
import fs from "fs";

const client = new Anthropic();

const upload = await client.beta.files.upload({
    file: new File([fs.readFileSync("report.pdf")], "report.pdf", { type: "application/pdf" })
});

const msg = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 1024,
    messages: [{
        role: "user",
        content: [
            { type: "document", source: { type: "file", file_id: upload.id } },
            { type: "text", text: "What are the main findings?" }
        ]
    }]
});
console.log(msg.content[0].text);

List and delete files

# List all uploaded files
files = client.beta.files.list()
for f in files.data:
    print(f.id, f.filename, f.size)

# Delete a file
client.beta.files.delete(file_id)

Cost comparison: Files API vs base64 inline

ApproachBandwidth per requestTokens billedBest for
Base64 inline (no cache)Full file each callFull file each callOne-off, small files
Base64 + prompt cacheFull file each call10% on cached readsRepeated use, API caller controls caching
Files APIZero (after upload)Normal input tokensMultiple workspaces, large files
Files API + cacheZero10% on cached readsBest: large doc used many times

When to use the Files API

Estimate total cost including Files API usage with the Claude Cost Calculator. For document-heavy pipelines, the Prompt-Pricing Recommender helps choose between Haiku, Sonnet, and Opus for document analysis tasks.

Frequently asked questions

How long do files stay in the Anthropic Files API?
Files expire after 30 days of non-use. Any API call that references a file_id resets the 30-day clock. For permanent retention, re-upload before expiry or store the original locally.
Can I use Files API files across different API keys?
Files are scoped to your workspace (organisation). Multiple API keys within the same Anthropic workspace can reference the same file_id. Files are not shared across organisations.
Does the Files API work with Claude's prompt caching?
Yes. Attach the file as a document block with cache_control: {type: 'ephemeral'} to cache the file's token representation. After the first request (cache write), subsequent requests use the cached version at 10% of the normal input token price.
What is the maximum file size for the Anthropic Files API?
32 MB for documents (PDF, TXT, CSV, etc.) and 20 MB for images (JPEG, PNG, GIF, WebP). Total workspace storage is 100 GB. Files exceeding these limits must be chunked before upload.
Can I update an uploaded file?
No — files are immutable once uploaded. To update a document, delete the old file_id and upload the new version. The new upload gets a fresh file_id that you must reference in subsequent requests.

Free tools

Cost Calculator → Prompt-Pricing Recommender → Diff Summarizer → Skills Browser →

Related

Claude Opus 4.7 vs Sonnet 4.6 Pricing (2026 Comparison)How Much Does Claude Cost? (2026 API Pricing Guide)Claude Prompt Caching: 90% Cost Savings Explained (2026)Claude API Cost Calculator: Estimate Your Anthropic BillClaude vs GPT-4 Pricing: 2026 API Cost Comparison