Fix "400 Invalid JSON in request body: Unterminated string in JSON" (request too large)
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Invalid JSON in request body: Unterminated string in JSON at position 10407567 (line 1 column 10407568)"}}If the position in this 400 error is in the millions, your request body was cut off in transit. CCSub accepts up to 50MB per request (413 above that); a ~10MB truncation on www.ccsub.net endpoints was fixed on 2026-10-15. Use /compact, stop re-sending screenshots, and read big files in pieces.
Fix it in 3 steps
- 1
Look at the number after position
Millions (10407567, 8553900…) means the body was too large and got cut off mid-transfer, so the JSON is incomplete. A small number (tens or hundreds) means the JSON you sent was malformed to begin with — usually a hand-written curl command or script.
- 2
Shrink the conversation in Claude Code
Run /context to see what's taking space, then /compact to summarize the history, or /clear to start over. Screenshots stay in the history as base64 and are re-sent every turn, so compress them before pasting and don't paste the same one twice.
- 3
Make individual requests smaller at the source
Don't pull whole log files, minified bundles, or data dumps into the conversation — have the agent grep or tail the parts it needs. In your own code, downscale images before encoding and trim old turns from long conversations.
Other forms of the same error
{"type":"error","error":{"type":"request_too_large","message":"Request body exceeds 50MB limit (got 52.4MB)"}}Request body is too large. Please reduce your message size, remove large images, or shorten the conversation history. | 请求体过大,请缩短对话历史、减小图片大小或减少附件。Invalid JSON in request body: Expected property name or '}' in JSON at position 1 (line 1 column 2)
Why a big request shows up as "Invalid JSON"
Taken literally, the error says a string inside the JSON never ended, which sounds like the client sent garbage. The number after position is the real clue.
CCSub accepts request bodies up to 50MB and returns a 413 with Request body exceeds 50MB limit above that. Below the limit the JSON should arrive intact; when it arrives cut off mid-string, the parser hits the end without a closing quote and you get this 400.
Before 2026-10-15, requests to endpoints on https://www.ccsub.net (including /v1/messages, what Claude Code calls by default) passed through the site's routing layer, which buffered only about 10MB (10,485,760 bytes) of body and dropped the rest. That is why the position usually landed between 8.5 and 10.4 million (lower when the text has lots of multi-byte characters). This has been fixed, and bodies between 10MB and 50MB are now handled in full.
If you still see this 400 with a large position after the fix, the request was most likely interrupted on your side: a local proxy with a body-size limit, an unstable connection dropping the upload, or the client truncating it. Try once with the proxy turned off, then make the request smaller as described below. Separately, if an upstream line rejects a request as too large, CCSub retries on another line first and only then returns a 413 request_too_large asking you to shorten the history, shrink images, or drop attachments.
How requests get that big
- Screenshots and images. Images travel as base64, about a third larger than the original file. A phone screenshot is often 1–2MB. Paste a few, keep chatting for dozens of turns, and every turn re-sends all of them.
- Big file reads. Letting Claude Code read an entire log file, a minified build output, a database export, or a lockfile puts all of it into the context.
- Very long sessions. Claude Code auto-compacts, but when a single file or image is huge, compaction can't get the request under the limit.
Fixing it
- Run
/contextin Claude Code to see what's using the most space. - Run
/compactto summarize the conversation and keep working, or/clearif you've moved on to a new task. - Crop and compress screenshots before pasting, and don't paste the same image repeatedly. When the agent needs a log, ask it to
greportailthe relevant lines instead of reading the whole file. - In your own code: downscale images before encoding them, keep only the most recent turns of long conversations, and send large documents in chunks.
When the position is small
Errors like Expected property name or '}' in JSON at position 1 or Unexpected non-whitespace character after JSON at position 10 have nothing to do with size — the JSON was invalid from the first byte. The most common cause is writing JSON inline in -d '...' on Windows cmd or PowerShell, where the shell mangles the quotes. Save the body to a file and use curl ... -d @body.json. SDKs rarely hit this; if yours does, look for code that builds the JSON string by hand.
FAQ
What's the maximum request size?
Up to 50MB per request, for both the Anthropic-compatible endpoint (Claude Code's default) and the OpenAI-compatible one; above that you get 413 request_too_large. Before 2026-10-15, requests to the Anthropic endpoint at https://www.ccsub.net were cut off at roughly 10MB and failed with this 400. That has been fixed.
Why does it only show up in long sessions?
Claude Code re-sends the full history every turn, including file contents it has read and images you pasted. One phone screenshot is a megabyte or two once base64-encoded, so the body grows each turn until one crosses the limit. /compact replaces the history with a summary and the size drops immediately.
What about Invalid JSON with a small position?
The body isn't valid JSON at all. Typical causes: single-quoted JSON in Windows cmd or PowerShell, a missing comma or quote in a hand-built string, or an empty body. Put the payload in a file and send it with curl -d @body.json to avoid shell escaping.
Are these 400s billed?
No. JSON parsing fails before anything is forwarded.
Still stuck?
- Read the troubleshooting guide (Chinese)
- Contact support: Email support@ccsub.net with the tool and version, your OS, the full error text, and your account email (never send your API key).
- Re-check your setup against the integration guide: Claude Code setup guide, Codex CLI setup guide
Related errors
There's an issue with the selected model (claude-opus-6). It may not exist or you may not have access to it. Run /model to pick a different model.The model ID is wrong — use an id from /api/v1/models (hyphenated). If every model fails and the response is an HTML page, your base URL is wrong instead.API Error: 504 {"type":"error","error":{"type":"timeout_error","message":"Upstream timed out"}}The upstream took too long to start answering. Use streaming (stream: true) in your own code, /compact very long contexts, and split long outputs. A one-off 504 just needs a retry and isn't billed.API Error: 503 {"type":"error","error":{"type":"overloaded_error","message":"上游线路暂时不可用,请稍后重试(不是您账户余额的问题) | Upstream temporarily unavailable, please retry shortly (this is not about your account balance)."}}CCSub already failed over between lines and none was free at that moment. Wait a minute and type "continue", or switch models with /model. Not billed, and not about your balance.
New to CCSub?
Sign up, create an API key in the dashboard, and paste it into Claude Code, Codex CLI or your editor. You pay for what you use.