claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] API Error: "invalid_request_error" "The request body is not valid JSON"

Open SaptaDey opened this issue 1 year ago • 27 comments

Image

Environment

  • Platform: Anthropic Login
  • Login Method: Claude Pro Account
  • Claude CLI version: v1.0.56
  • Model: Sonnet 4
  • Operating System: Ubuntu 24.04
  • Terminal: Ubuntu

Bug Description

Persistant following error message despite several different edit commands

⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: no low surrogate in string: line 1 column 42462 (char 42461)"}}

Expected Behavior

Not get the following error in midle of a very simple UI color changing task ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: no low surrogate in string: line 1 column 42462 (char 42461)"}}

Actual Behavior

I plot code to change the UI color of my WebApp, which is written in TypeScript And it kept throwing the error after editing for few seconds.

SaptaDey avatar Jul 19 '25 20:07 SaptaDey

I got this also, do you have any quick fix?

vietnguyenunicorn avatar Jul 23 '25 14:07 vietnguyenunicorn

same bug. Please help

olbo22 avatar Jul 23 '25 16:07 olbo22

Whats the fix????

Dezocode avatar Jul 25 '25 13:07 Dezocode

Guys! I figured it out!

When installing claude-code it's recommended you don't use sudo So you'll have to rm -rf _your directory___ lib/node_modules/@anthropic-ai/claude-code

reinsall it using

npm install -g @anthropic-ai/claude-code then claude migrate-installer

AWZRD avatar Jul 25 '25 20:07 AWZRD

I never used sudo was working then suddenly died on me with a similar error:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: no low surrogate in string: line 1 column 360047 (char 
    360046)"}}

I had to exit CC then start again by typing claude in the project directory thankfully I was getting CC to plan everything first and document any/all actions in case similar happens.

trevor-the-developer avatar Aug 04 '25 23:08 trevor-the-developer

Any news on this? I also have this problem now

API Error: 400 {"type":"error","error":{"type":"invalid_request_ error","message":"The request body is not valid JSON: no low surrogate in string: line 1 column 156085 (char 156084)"}}

It does seem that starting a new Claude Code session "fixes" it though

magikMaker avatar Aug 08 '25 10:08 magikMaker

Same here. A workaround for me was to: \export the session and then start a new one and say in the new one Resume the conversation in 2025-08-08-this-session-is-being-continued-from-a-previous-co.txt and let's continue with what we were in the middle of.

This picked up the conversation and got around the error. This suggests that something becomes corrupted in the session itself.

Bug Description I keep getting the following error and I'm not sure what's causing it. API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: no low surrogate in string: line 1 column 54841 (char 54840)"}}

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 1.0.71
  • Feedback ID:

Errors

[{"error":"AxiosError: Request failed with status code 403\n    at VN (file:///Users/username/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:682:1077)\n    at Unzip.J0 (file:///Users/username/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:683:9955)\n    at Unzip.emit (node:events:530:35)\n    at Unzip.emit (node:domain:489:12)\n    at endReadableNT (node:internal/streams/readable:1698:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)\n    at $B1.request (file:///Users/username/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:685:2088)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async uK8 (file:///Users/username/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2289:470)\n    at async Promise.all (index 0)\n    at async file:///Users/username/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2275:19497","timestamp":"2025-08-08T14:48:40.786Z"}]

sammywachtel avatar Aug 08 '25 14:08 sammywachtel

The same just happened to me in Windows 11 with CC 1.0.72. Worked around it with the /export method

alexx-ftw avatar Aug 11 '25 11:08 alexx-ftw

I encountered this exact same error today. The following solution worked for me, and I hope it will be helpful to you as well. Solution:

Step 1 - Type /status to find your claude code Session ID. Note it. Step 2 - CTR+C twice to exit the Claude session Step 3 - Restart terminal (or VS Code) Step 4 - Use one of the following options to resume your Claude session.

Type "claude --resume" (This command will list your previous Claude code conversations for you to select from.) claude -r "session-id" (resume specific session) claude -c (resume most recent session)

I also recorded a video to make it easy for you to follow. https://youtu.be/lAnaIz-uaek

vinodsharma10x avatar Aug 11 '25 21:08 vinodsharma10x

Having same issue no matter how i restart the session, whatever i type in the prompt returns with same error even after restarting session

Malik0712 avatar Aug 13 '25 18:08 Malik0712

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/5889
  2. https://github.com/anthropics/claude-code/issues/1709
  3. https://github.com/anthropics/claude-code/issues/1832

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Aug 16 '25 03:08 github-actions[bot]

Temporar Fix:

  1. Quit claude
  2. In terminal run: rm -rf ~/.claude/cache
  3. Then run: rm -rf ~/.claude/tmp
  4. Then run: file -bi . | grep -v ascii

m3nt0l avatar Aug 16 '25 06:08 m3nt0l

same issue

byliu avatar Aug 18 '25 02:08 byliu

Any news on this? happening here too in the middle of a conversation for no clear reason. Claude developers around?

andreasotto avatar Aug 22 '25 10:08 andreasotto

issue still exists as of Sep 11 2025

TomMaxon avatar Sep 11 '25 21:09 TomMaxon

I’m experiencing the exact same issue.
The only way I can continue working is by starting a new session, as resuming or restarting the current one always fails with the same error:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON..."}}

It seems like the session itself gets corrupted, and I haven’t found any workaround other than creating a fresh session.

echoes-byte avatar Sep 14 '25 13:09 echoes-byte

I have a workaround but to be honest I have not had any similar issues for a while now not since last commenting on this thread.

I suggest as you work ask CC to generate index files these are markdown files that tell it where everything is, what context file(s), where the code is, key points etc (this doc is useful to a developer as well as a jumping in point), then during your sessions when you get a pause ask it to record the session details for its future self to continue should you need to take a break.

This works relatively well for me for example I prompt like this:

Hi buddy can you enable beast mode see claude-code-warp-beast-mode.md then digest your CLAUDE.md context file and any/all documents in this solution finally understand the code base 
  see CODE_INDEX.md for reference then give me a plan of where we are and what was next on the planned sprints and tasks.

"BEAST MODE" is the infamous ChatGPT beast mode script that I adapted for Claude Code found here: LINK.

Its a little clunky but I found I was able to continue just fine most of the time especially when I have documents that capture any plans and the current plan (I plan often, execute a few times), any key points from a previous session e.g. we figured out how to do something or resolve a bug.

I have found since I keep my context sessions smaller I am not having issues (on Claude Code v1.0.113)

trevor-the-developer avatar Sep 15 '25 14:09 trevor-the-developer

Bug is still happening (mac Claude Code v1.0.108), /export worked thanks @sammywachtel

Anima-t3d avatar Sep 16 '25 04:09 Anima-t3d

I just got the same error, even though I tried some of the recommendations from here. The only step that worked was to start a brand-new session.

This is unacceptable for such a high price point.

aalmazzo avatar Sep 23 '25 02:09 aalmazzo

This error repeatedly occurs for me when Claude Code edits files containing emojis on Debian, but I haven’t experienced it on macOS. Looking at the original bug report, it looks like they are also experiencing it on a file with Emojis on a Linux distro.

SamEggert avatar Sep 24 '25 17:09 SamEggert