Short answer
Request too large (max 32MB) means the raw request body Claude Code built was bigger than the Claude API accepts. The limit is on bytes, before anything is counted as tokens, so it is separate from the context window. The usual cause is images, screenshots, PDFs or large pasted content piling up in the conversation, because every turn re-sends the whole conversation.
To keep working:
- Run
/compact. It drops the accumulated images and attachments. - If the message says
compacting cannot make it fit, press Esc twice to step back past the turn that added the large content, or run/clear. - From then on, reference large files by path instead of pasting them, and attach smaller screenshots.
When you call the API yourself, the same limit shows up as HTTP 413 with the error type request_too_large. The fix is to send fewer bytes: smaller images, fewer inline documents, or more requests.
What the error looks like
In Claude Code, according to the Claude Code error reference:
Request too large (max 32MB). Accumulated images and attachments in the conversation pushed the request over the limit. Run /compact, or double press esc to go back and remove attachments.
When the request went straight to the Claude API, Claude Code measures the conversation and words the message by whether a retry can work:
Request too large (max 32MB; 20.1MB of about 33.4MB is images or documents).Images or documents pushed the request over, and Claude Code retries with them stripped.Request too large for the API's 32MB request limit, followed bycompacting cannot make it fit. The messages alone are over the limit, so Claude Code doesn't retry.
Through a proxy, a gateway or a cloud provider, you get the general message above. Versions before v2.1.212 showed Request too large (max 32MB). Double press esc to go back and try with a smaller file.
From the API, as reported in can1357/oh-my-pi#14453:
413 {"error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}
The same body arrives through LiteLLM as an AnthropicException (dgml-io/dgml#158). The Anthropic Python SDK raises anthropic.RequestTooLargeError for a 413.
Why it happens
The Claude API errors page lists these request size limits:
| Endpoint | Maximum request size |
|---|---|
| Messages API | 32 MB |
| Token Counting API | 32 MB |
| Batch API | 256 MB |
| Files API | 500 MB |
Over the limit, the API returns 413 request_too_large. On the direct Claude API, Cloudflare returns this error before the request reaches the API servers, so the request isn't processed at all.
Three things make a Claude Code request grow past 32 MB:
- Every turn re-sends the conversation. A screenshot attached early in a session stays in each later request until it's removed.
- Files travel as base64. Images and PDFs are sent base64-encoded, which is about a third larger than the file on disk.
- Images are cheap in tokens but heavy in bytes. A session can be far from its context limit and still go over the byte limit. That is why
/contextcan look fine when this error appears.
Large pasted logs and tool results that return big outputs add to it too.
This isn't "Prompt is too long". Prompt is too long means the request has too many tokens for the model's context window. Request too large means it has too many bytes. They need different fixes; see Claude Code "Prompt is too long" for the token case.
How to fix it in Claude Code
- Run
/compact. According to the error reference, it drops accumulated images and attachments. Then send your message again. - If the message says
compacting cannot make it fit, the text alone is over the limit. Press Esc twice to go back past the turn that added the large content, or run/clearto start fresh. - Reference files by path. Ask Claude to read
logs/build.loginstead of pasting it, so it can read the file in chunks. - Shrink screenshots. Capture the region you need rather than the full screen. A related message,
Image was too large, means one image is over the API's size or dimension limits. - For PDFs, read a page range. Claude Code rejects a single PDF with
PDF too large (max 100 pages, 20MB). Ask for specific pages, or convert it withpdftotextand point Claude at the text file. - Update Claude Code. Run
claude update. Several versions have changed how Claude Code removes images from long sessions.
If you use a gateway or proxy
- The gateway can have a lower limit. A gateway or reverse proxy may reject bodies well below 32 MB. In hs3180/tidemux#94, a self-hosted proxy rejected anything over 1 MiB with 413
request_too_large, which ended a Claude Code session after two chart images. If the error appears with small sessions, check the gateway's request size limit. - You get the general message. Behind
ANTHROPIC_BASE_URL, Claude Code shows the generalRequest too large (max 32MB)text, so the message alone doesn't tell you whether Claude Code, the gateway or the API set the limit. Check the gateway's logs for the request. - On the first prompt of a new session. In anthropics/claude-code#95654, a user with a custom base URL saw this message on the first prompt with no attachments, and the gateway never received the request. If that matches what you see, update Claude Code and follow that issue.
If you call the Claude API directly
- Check the body size before you send. Measure the serialized JSON, not the token count. Images can make the request large without adding many tokens.
- Resize images first. Send images at the size the task needs. A full-resolution screenshot is rarely necessary.
- Don't keep every image in the history. In a multi-turn app, remove or replace old images once the model has used them.
- Split the work. Send documents in separate requests, or use the Batch API for large jobs. Its limit is 256 MB per batch.
- Catch the 413 separately. Retrying the same body won't help. Reduce it, then retry.
import anthropic
client = anthropic.Anthropic()
try:
msg = client.messages.create(model="claude-sonnet-5", max_tokens=1024, messages=messages)
except anthropic.RequestTooLargeError:
# Drop or shrink images and documents, then send again
...
Running Claude Code through TeamoRouter
TeamoRouter is an API gateway with one key for Claude, GPT, Gemini and DeepSeek. Claude runs on the native Anthropic protocol (/v1/messages), so Claude Code only needs a base URL and a key. Billing is pay-per-use with no subscription. The fixes above apply the same way through TeamoRouter: keep the request body small.
- Create an API key in the TeamoRouter console. It starts with
sk-teamo-. - Top up from $5. The top-up dialog takes cards. You can also click Pay with crypto and pay with USDT, USDC or ETH from any exchange app — the checkout shows which networks your amount supports (BEP20 works from $5). Step by step: Pay with USDT.
- Set two variables (macOS and Linux):
export ANTHROPIC_BASE_URL=https://api.teamorouter.com
export ANTHROPIC_AUTH_TOKEN="your TeamoRouter API key"
claude
Leave /v1 off the base URL. To check the key, call GET /v1/models with Authorization: Bearer sk-teamo-... (or x-api-key). Windows commands and model settings are in Install and connect Claude Code.
FAQ
Is 32MB the same as the context window? No. The context window counts tokens. The 32 MB limit counts the bytes of the request body. A request can fail either one without failing the other.
Will /compact lose my work?
It replaces earlier turns with a summary and drops the accumulated images and attachments. Text details from older turns can be lost, so add a focus, for example /compact keep the API design decisions.
Why did it happen when I only attached a few screenshots? Each screenshot stays in the conversation and is re-sent every turn, base64-encoded. A few full-screen captures over a long session add up. A gateway with a lower size limit than 32 MB makes it happen sooner.
Does a model with a bigger context window help? No. The byte limit is the same for every model on the Messages API.