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

Claude Code: constantly seeing 'API Error (Request timed out...)' - Retrying in .. seconds.. (attempt x/10)'

Open 0spinboson opened this issue 6 months ago • 2 comments

roughly in the past 48 hours, since about my update to claude code 0.3.5, I'm getting these error messages most of the time I make requests. Pressing escape often doesn't keep the error messages from continuing to appear, counting to attempt 10/10 after which it stops trying to do anything. Logging out and back in didn't help, rebooting server didn't help. there are no connectivity issues of which I'm aware.

I was mostly using Opus lately, but Sonnet seems to have the same issues.

● Read(tests/utils/factories.py) ⎿  Read 459 lines (ctrl+r to expand) ⎿  API Error: Request timed out.

/model sonnet ⎿  Set model to sonnet (claude-sonnet-4-20250514)

please continue ⎿  API Error: Request timed out.

(running on ubuntu 24.04 x64) Claude Code Status v1.0.35

L Session ID: 3824b60a-912c-4fad-8492-ad4c76098456

Account • /login L Login Method: Claude Max Account L Organization:

Memory • /memory L project: CLAUDE.md

Model • /model L sonnet (claude-sonnet-4-20250514)

Currently running: npm-local (1.0.35) Invoked: /home/user/.claude/local/node_modules/.bin/claude Auto-updates: Yes Config install method: local Config auto-updates: true

0spinboson avatar Jun 29 '25 18:06 0spinboson

I also am fighting with this issue, only happening on Linux dev machine, MacOS not affected or WSL.

`

great, continue with remaining collections ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 5 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 9 seconds… (attempt 5/10) ⎿ API Error (Request timed out.) · Retrying in 17 seconds… (attempt 6/10) ⎿ API Error (Request timed out.) · Retrying in 36 seconds… (attempt 7/10) ⎿ API Error (Request timed out.) · Retrying in 40 seconds… (attempt 8/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 4 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 40 seconds… (attempt 9/10) ⎿ API Error (Request timed out.) · Retrying in 8 seconds… (attempt 5/10) ⎿ API Error (Request timed out.) · Retrying in 20 seconds… (attempt 6/10) ⎿ API Error (Request timed out.) · Retrying in 34 seconds… (attempt 10/10) ⎿ API Error (Request timed out.) · Retrying in 39 seconds… (attempt 7/10) ⎿ API Error (Request timed out.) · Retrying in 39 seconds… (attempt 8/10) ⎿ API Error (Request timed out.) · Retrying in 37 seconds… (attempt 9/10) ⎿ API Error (Request timed out.) · Retrying in 35 seconds… (attempt 10/10) `

amarkulo avatar Jun 30 '25 15:06 amarkulo

I also am fighting with this issue, only happening on Linux dev machine, MacOS not affected or WSL.

`

great, continue with remaining collections ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 5 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 9 seconds… (attempt 5/10) ⎿ API Error (Request timed out.) · Retrying in 17 seconds… (attempt 6/10) ⎿ API Error (Request timed out.) · Retrying in 36 seconds… (attempt 7/10) ⎿ API Error (Request timed out.) · Retrying in 40 seconds… (attempt 8/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 4 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 40 seconds… (attempt 9/10) ⎿ API Error (Request timed out.) · Retrying in 8 seconds… (attempt 5/10) ⎿ API Error (Request timed out.) · Retrying in 20 seconds… (attempt 6/10) ⎿ API Error (Request timed out.) · Retrying in 34 seconds… (attempt 10/10) ⎿ API Error (Request timed out.) · Retrying in 39 seconds… (attempt 7/10) ⎿ API Error (Request timed out.) · Retrying in 39 seconds… (attempt 8/10) ⎿ API Error (Request timed out.) · Retrying in 37 seconds… (attempt 9/10) ⎿ API Error (Request timed out.) · Retrying in 35 seconds… (attempt 10/10) `

I just tossed the whole local config and install in ~/.claude/, npm uninstalled and reinstalled everything and the problem is gone, so I guess the issue is local profile corruption.

0spinboson avatar Jun 30 '25 15:06 0spinboson

I've got the same problem, I'm using Mac OS.

epireve avatar Jul 01 '25 04:07 epireve

oh, we're 24h later and I'm seeing this again with my new install:
⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 4 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 9 seconds… (attempt 5/10)

0spinboson avatar Jul 01 '25 08:07 0spinboson

I don't think it's bugged install, it's something on their side, as I just left it and it continued after some time, so probably backend related.

amarkulo avatar Jul 01 '25 08:07 amarkulo

I'm experiencing the same issue. Working with Claude Code is often unworkable because of it. I haven’t found a solution yet, other than repeatedly trying again.

YenK260 avatar Jul 02 '25 06:07 YenK260

I just leave it retrying and if usually continues after some time which tell me it's backend/server related.

amarkulo avatar Jul 02 '25 06:07 amarkulo

After deleting WSL ubuntu and reinstalling claude, it didn't work, but after rebooting Windows, it worked. I don't know the cause at all. I think I'll try rebooting next time.

mannago avatar Jul 02 '25 11:07 mannago

anyone solved the problem?? I use macOS and having the same problem...tried restarting and uninstalling and reinstalling. Nothing changed, still the error persists.

jpalepu avatar Jul 02 '25 13:07 jpalepu

Using Ubuntu WSL on Windows. Confirming same issue.

ASDrew94 avatar Jul 02 '25 15:07 ASDrew94

After extensive debugging throughout the day, I've identified what appears to be the root cause of my API errors. The issue rendered Claude Code essentially non-functional for my workflow. My investigation led me to implement Cloudflare AI Gateway as a proxy layer to gain better observability into the API request/response cycle. While this didn't directly resolve the issue, it provided crucial diagnostic data. Note that Cloudflare AI Gateway works with Claude Code subscriptions as well - I'm mentioning this purely as a debugging tool, not endorsing any particular service. My sole focus was resolving the issue.

Analysis of the request logs revealed that ~40% of API calls were failing with the following error: json{ "type": "error", "error": { "type": "invalid_request_error", "message": "max_tokens: 150000 > 32000, which is the maximum allowed number of output tokens for claude-opus-4-20250514" } } This revealed the issue: I had previously modified the max_tokens parameter to 150000 while troubleshooting the API issues. This value exceeds the model's maximum output token limit of 32000. After reverting to max_tokens: 32000, the API errors ceased immediately. The same operations that previously triggered consistent failures have now been running stable for 60+ minutes.

I'm sharing this in hopes it provides a concrete troubleshooting vector for others experiencing similar issues. I recommend either:

  1. Verifying your max_tokens configuration as a first diagnostic step
  2. Implementing Cloudflare AI Gateway (or similar proxy) to gain visibility into the actual API errors

Since making this adjustment, I haven't encountered a single API error in my logs.

YenK260 avatar Jul 02 '25 16:07 YenK260

right, in my case as well, i have solved it with this method.

jpalepu avatar Jul 02 '25 16:07 jpalepu

Nice. Does anyone know how to change this for the WSL Ubuntu CLI?

Don't see anything like max_tokens within the /config .

ASDrew94 avatar Jul 02 '25 17:07 ASDrew94

Nice. Does anyone know how to change this for the WSL Ubuntu CLI?

Don't see anything like max_tokens within the /config .

I use the same WSL Ubuntu setup and had trouble finding this too. The max_tokens setting is actually configured through an environment variable in your .bashrc file, not in the config directory. Check your .bashrc file for this line: bashexport CLAUDE_CODE_MAX_OUTPUT_TOKENS=

YenK260 avatar Jul 02 '25 18:07 YenK260

okay, thank you. would be nice if claude respected this setting itself as well though, I've had a few occurrences of claude chewing on answers for a very long time and then erroring by saying "oh I can't tell you now" rather than chunking better.

0spinboson avatar Jul 02 '25 18:07 0spinboson

After extensive debugging throughout the day, I've identified what appears to be the root cause of my API errors. The issue rendered Claude Code essentially non-functional for my workflow. My investigation led me to implement Cloudflare AI Gateway as a proxy layer to gain better observability into the API request/response cycle. While this didn't directly resolve the issue, it provided crucial diagnostic data. Note that Cloudflare AI Gateway works with Claude Code subscriptions as well - I'm mentioning this purely as a debugging tool, not endorsing any particular service. My sole focus was resolving the issue.

Analysis of the request logs revealed that ~40% of API calls were failing with the following error: json{ "type": "error", "error": { "type": "invalid_request_error", "message": "max_tokens: 150000 > 32000, which is the maximum allowed number of output tokens for claude-opus-4-20250514" } } This revealed the issue: I had previously modified the max_tokens parameter to 150000 while troubleshooting the API issues. This value exceeds the model's maximum output token limit of 32000. After reverting to max_tokens: 32000, the API errors ceased immediately. The same operations that previously triggered consistent failures have now been running stable for 60+ minutes.

I'm sharing this in hopes it provides a concrete troubleshooting vector for others experiencing similar issues. I recommend either:

  1. Verifying your max_tokens configuration as a first diagnostic step
  2. Implementing Cloudflare AI Gateway (or similar proxy) to gain visibility into the actual API errors

Since making this adjustment, I haven't encountered a single API error in my logs.

I'm having the same issue, but doens't matter the size of my requisition (1k or 50k tokens), the problem keeps happening

tiagocarnin avatar Jul 02 '25 21:07 tiagocarnin

same problem here at MacOS. My solution is to escape the running process and switch /model to sonnet. After that tell Claude to continue.

visioncode avatar Jul 03 '25 11:07 visioncode

same problem here at MacOS. My solution is to escape the running process and switch /model to sonnet. After that tell Claude to continue.

Thanks for sharing. I tried it as I had the same issue: ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10) ⎿ API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10) ⎿ API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10) ⎿ API Error (Request timed out.) · Retrying in 4 seconds… (attempt 4/10) ⎿ API Error (Request timed out.) · Retrying in 9 seconds… (attempt 5/10) ⎿ API Error (Request timed out.) · Retrying in 17 seconds… (attempt 6/10) ⎿ API Error (Request timed out.) · Retrying in 34 seconds… (attempt 7/10) ⎿ API Error (Request timed out.) · Retrying in 33 seconds… (attempt 8/10)

I tried that, ESC, switched model to sonnet (even though pro only has access to it) and asked to continue., On my end, it stayed stuck on: Progressing… (18s · 5 tokens · esc to interrupt · offline)

And eventually, out of nowhere, it started to work Progressing… (357s · ↓ 5.8k tokens · esc to interrupt · offline)

But then, I got it again: API Error (Request timed out.) · Retrying in 40 seconds… (attempt 10/10)

So, I guess that sort of worked for me so it finished it task, 🙏🥳

Theory: I had Claude Code opened for a few days now working on the same project. Perhaps it's because I don't close it? I'll try that to see if I get time out again.

alexricher avatar Jul 03 '25 14:07 alexricher

removing the increased limit definitely seems to have helped, but Opus is still unstable as hell atm generally, so idk if this solves all.

0spinboson avatar Jul 03 '25 16:07 0spinboson

Same issue here, specifically it works fine in WSL, but in my linux dev vm it times out...

zroman88 avatar Jul 03 '25 17:07 zroman88

Same issue here, specifically it works fine in WSL, but in my linux dev vm it times out...

I have exactly the same thing.... but performance with wsl is hell - not claudes fault. So i tried a ubuntu VM

reikla avatar Jul 03 '25 19:07 reikla

Same issue here, specifically it works fine in WSL, but in my linux dev vm it times out...

I have exactly the same thing.... but performance with wsl is hell - not claudes fault. So i tried a ubuntu VM

Funny thing is if I reboot my machine and thus Hyper-V, it works for a brief moment, I can see token begin to move and then it disconnects again...

While in WSL, it works just fine...

What Node.js versions are you running? I'm on 20.11.0....tried 18, same story

zroman88 avatar Jul 03 '25 19:07 zroman88

I found a fix for the above issue, at least for me it started working flawlessly after this.

This issue was with my /etc/resolv.conf entry for one of the nameservers. I had nameserver 192.168.0.2 and nameserver 8.8.8.8 as the 2nd. The first entry leads nowhere and was causing the issue. What I did was (i'm running RedHat, might be different for other distros):

  1. Modify /etc/resolv.conf
  2. If there are any strange nameservers listed here besides 8.8.8.8 or 8.8.4.4 you need to change it. to one of these two and get rid of the other line or have two entries from Google.
  3. Save the file, but it will get ovewritten when restarting NetworkManager, so we need to configure that, too.
  4. Run sudo nano /etc/NetworkManager/NetworkManager.conf and in the [main] section add dns=none. Save the file.
  5. Now run sudo systemctl restart NetworkManager.
  6. Hopefully enjoy working Claude Code!

zroman88 avatar Jul 03 '25 23:07 zroman88

Constantly hitting API Error (Request timed out.) on MacOS.

ivnle avatar Jul 05 '25 06:07 ivnle

I found a fix for the above issue, at least for me it started working flawlessly after this.

This issue was with my /etc/resolv.conf entry for one of the nameservers. I had nameserver 192.168.0.2 and nameserver 8.8.8.8 as the 2nd. The first entry leads nowhere and was causing the issue. What I did was (i'm running RedHat, might be different for other distros):

  1. Modify /etc/resolv.conf
  2. If there are any strange nameservers listed here besides 8.8.8.8 or 8.8.4.4 you need to change it. to one of these two and get rid of the other line or have two entries from Google.
  3. Save the file, but it will get ovewritten when restarting NetworkManager, so we need to configure that, too.
  4. Run sudo nano /etc/NetworkManager/NetworkManager.conf and in the [main] section add dns=none. Save the file.
  5. Now run sudo systemctl restart NetworkManager.
  6. Hopefully enjoy working Claude Code!

Thanks so much, It works

barissucuoglu avatar Jul 05 '25 11:07 barissucuoglu

I found a fix for the above issue, at least for me it started working flawlessly after this.

This issue was with my /etc/resolv.conf entry for one of the nameservers. I had nameserver 192.168.0.2 and nameserver 8.8.8.8 as the 2nd. The first entry leads nowhere and was causing the issue. What I did was (i'm running RedHat, might be different for other distros):

  1. Modify /etc/resolv.conf
  2. If there are any strange nameservers listed here besides 8.8.8.8 or 8.8.4.4 you need to change it. to one of these two and get rid of the other line or have two entries from Google.
  3. Save the file, but it will get ovewritten when restarting NetworkManager, so we need to configure that, too.
  4. Run sudo nano /etc/NetworkManager/NetworkManager.conf and in the [main] section add dns=none. Save the file.
  5. Now run sudo systemctl restart NetworkManager.
  6. Hopefully enjoy working Claude Code!

You naild it man, it's working for my right now. Thanks!

tiagocarnin avatar Jul 05 '25 18:07 tiagocarnin

oddly changing dns fixed it for me as well. I was running a simple forwarder on my router with adguard, nothing was getting blocked though so not really sure why dns would be a problem.

Dwayne75 avatar Jul 05 '25 22:07 Dwayne75

From Anthropic Support to me:

"The timeout issues with long todo lists appear to be related to the extended processing time required for complex multi-step tasks, which can exceed the default API timeout limits. As a workaround, you can increase the API timeout by setting the API_TIMEOUT_MS environment variable before launching Claude Code. For example, you can use the export API_TIMEOUT_MS=600000 command to set it for 10 minutes. The default appears to be 30 seconds (30000ms), but you can increase it significantly for complex tasks like long todo lists."

This worked for me personally.

NellInc avatar Jul 06 '25 16:07 NellInc

Thanks everyone! All the talk of DNS lead me to my own fix. I run pi-hole with Cloudflared for DoH. However, my fallback if the pi-hole is offline is to use 1.1.1.2. It seems claude code does not play nicely with 1.1.1.2. Once I fixed my pi-hole, the Request timeouts in claude code went away.

boomshadow avatar Jul 07 '25 13:07 boomshadow

The fix was to check your DNS settings. In my case, I had set Pi-hole as the DNS server. After removing it and reverting to the default DNS, the issue was resolved.

TheNilesh avatar Jul 07 '25 15:07 TheNilesh