Claude Code · Troubleshooting

Claude Code API connection error: timeouts and fixes

A connection error means Claude Code never got a response from the API: the request did not reach it, or the answer took too long. Unlike 4xx and 5xx errors, the cause is usually the network path or the endpoint address.

Last checked

The error text

Claude Code
API Error (Connection error.) · Unable to connect to API (ECONNREFUSED) · Request timed out

Step-by-step fix

  1. 1. Check the address

    Run /status. The endpoint must be api.aicodewith.ai over https, without /v1 or typos.

    ~/.claude/settings.json
    {
      "env": {
        "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
        "ANTHROPIC_API_KEY": "",
        "ANTHROPIC_BASE_URL": "https://api.aicodewith.ai"
      }
    }
  2. 2. Test the network

    Run curl -I https://api.aicodewith.ai in the same terminal. If it hangs or fails, the problem is the network, not Claude Code.

  3. 3. Proxy and firewall

    If you use a proxy, export HTTPS_PROXY in that terminal (or add it to the env block). Corporate firewalls may need api.aicodewith.ai allowed.

  4. 4. Raise the timeout

    On slow or long requests, add "API_TIMEOUT_MS": "600000" to the env block and restart.

Common causes

SymptomLikely cause
ECONNREFUSED or ENOTFOUNDWrong host, or DNS/proxy blocks it
Fails only on VPN or office networkFirewall or proxy rules
Times out on long answers onlyTimeout too short for the network
Works with curl, fails in Claude CodeDifferent proxy settings between shells or the IDE

Are failed requests charged?

Failed requests (4xx/5xx, timeouts, dropped connections) are not charged — you're only billed for requests that complete successfully. If an upstream failure is automatically retried and succeeds, you're billed once.

Still failing?

  • Check the model's page on aicodewith: it shows recent health for each channel.
  • Look up the request in your dashboard usage records to see its model, status and cost.
  • Email support@aicodewith.com with the time of the error, the model and the error text (never your full API key).

Model status and pricesContact supportDocs

FAQ

What does "API Error (Connection error)" mean in Claude Code?

Claude Code could not reach the API or got no answer in time. Check the base URL, then the network, proxy and firewall.

How do I set a proxy for Claude Code?

Export HTTPS_PROXY in the terminal you start Claude Code from, or add it to the env block in ~/.claude/settings.json.

How do I increase the Claude Code timeout?

Set API_TIMEOUT_MS (in milliseconds) in the env block of settings.json and restart Claude Code.

Is a connection error my key's fault?

No. Key problems return 401. A connection error means no HTTP response arrived.

Why does it work in curl but not in my IDE?

The IDE may not inherit your shell proxy settings. Put HTTPS_PROXY in the env block of settings.json so every Claude Code client uses it.

Am I charged for failed requests?

Failed requests (4xx/5xx, timeouts, dropped connections) are not charged — you're only billed for requests that complete successfully. If an upstream failure is automatically retried and succeeds, you're billed once.

Ready to try it?

Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.

Related

Sources

Claude and Claude Code are trademarks of Anthropic PBC. aicodewith is an independent platform and is not affiliated with or endorsed by Anthropic. Error formats are quoted from Claude Code and may change. Checked 2026-10-10.