Troubleshooting

Fix a Claude Code Connection Error or Timeout: A Diagnostic Ladder

2026-06-06 7

TL;DR — Most of the time a Claude Code connection error is one of three boring things: a doubled base path producing a 404, a malformed API key producing a 401, or a corporate proxy/VPN silently dropping the request. Before you assume the network is broken, rule out the most common cause: a long pause before the first token on a hard prompt is the model thinking, not a hang. Walk this ladder top to bottom and stop at the first check that fails.

Is it actually a claude code connection error, or just thinking?

Start here, because it's the cheapest check and the most common false alarm. Claude Code streams its response. On a hard prompt — a big refactor, a long file to read, a multi-step plan — there can be a noticeable pause before the first token arrives. That pause is the model working, not a dead connection.

How to tell them apart:

  • Thinking: the spinner is alive, then text starts flowing and keeps flowing. Give a heavy prompt several seconds before you call it stuck.
  • A real fault: you get an explicit error string (a 4xx/5xx, request timed out, fetch failed, ECONNREFUSED), or the spinner sits with zero bytes ever arriving and then errors out.

If tokens are arriving, even slowly, nothing is broken — let it finish. If you see an actual error message, keep going down the ladder.

Check 1: the base URL (the #1 cause of fake "connection errors")

The single most common self-inflicted failure. Your base URL must be exactly:

export ANTHROPIC_BASE_URL=https://llmapi.pro
export ANTHROPIC_API_KEY=sk-relay-...

The trap: Claude Code appends /v1/messages itself. If you set the base URL to https://llmapi.pro/v1, the actual request can become https://llmapi.pro/v1/v1/messages — a path that doesn't exist. That returns a 404, and a 404 in the middle of a tool run often looks like a generic connection error in the UI.

Fix: set the Claude Code base URL to the host only. Claude Code appends /v1/messages; do not add /v1 or /messages yourself. If you're setting this up from scratch, our Claude Code API key setup guide walks through the full env-var config.

Check 2: read the HTTP status code — it tells you exactly what's wrong

If you get a numeric error, it's not a mystery. The status code is a precise diagnosis:

Status Meaning Fix
401 Bad or missing key Key must be sk-relay-... with no stray quotes, spaces, or newlines. Re-paste it.
404 Wrong model ID or wrong base path Re-check the base URL (Check 1) and that the model ID is valid.
429 Rate limit / saturated session Not a dead key — you're being throttled. Back off and retry.

A 401 almost always means the key got mangled. A common failure: copying the key with surrounding quotes into a shell, so the literal " becomes part of the value. Echo it back and look:

echo $ANTHROPIC_API_KEY
# should print sk-relay-... with no quotes, no leading space

A 404 sends you back to Check 1, or means you asked for a model ID that isn't advertised. The current IDs are claude-opus-4-8, claude-opus-4-7, claude-sonnet-4-6, and claude-haiku-4-5-20251001; older Claude IDs are accepted and routed to the closest model in the same series. You can confirm what's live with GET /v1/models.

A 429 is its own topic — it means the session is saturated, not that anything is misconfigured. See fixing Claude Code's 429 rate limit error for how to back off cleanly.

Check 3: smoke-test outside Claude Code with curl

When you're not sure whether the fault is in Claude Code, your shell config, or the network, take the tool out of the equation. A raw curl to the Messages endpoint isolates the problem:

curl https://llmapi.pro/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "max_tokens": 64,
    "messages": [{"role": "user", "content": "reply with the word: ok"}]
  }'

Read the result:

  • A normal JSON response — your key, base URL, and network are all fine. The problem is in Claude Code's config or env. Re-check the two env vars from Check 1.
  • A 401/404/429 — jump back to Check 2; the status code is your answer.
  • curl itself hangs or fails to connect (no HTTP status at all) — this is a genuine network problem. Go to Check 4.

Note the headers: this endpoint expects x-api-key and anthropic-version: 2023-06-01. That's the same shape Claude Code sends, so a passing curl proves the path is good.

Check 4: proxy, VPN, and firewall — the silent blockers

If curl can't even establish a connection, the request is probably being dropped before it leaves your machine or your network. Corporate proxies, VPNs, and firewalls routinely block outbound API endpoints, and they tend to fail silently — you get a timeout or a connection reset rather than a helpful message.

Quick isolation steps:

  • Test off the corporate network. Run the same curl from a phone hotspot or a network you control. If it works there and not on the office network, a proxy or firewall is the culprit.
  • Check for a proxy env var. Some setups route everything through HTTPS_PROXY/HTTP_PROXY. Print them and confirm they're what you expect:
echo $HTTPS_PROXY $HTTP_PROXY
  • VPN on/off. Toggle the VPN and re-run the curl. Split-tunnel VPNs sometimes route API traffic into a dead path.

The goal of Check 4 is just to answer one question: can a plain HTTPS request from this machine reach the endpoint at all? If the answer is no, the fix is on your network, not in Claude Code.

A note on timeouts on heavy prompts

If you're driving a long-context model on a big task and the request feels slow, that's expected for a hard prompt — streaming can take a few seconds to emit the first byte, and large outputs take longer to complete. That's distinct from a timeout error, which gives you an explicit message. If you're working with the 1M-context model and want to understand its behavior on large tasks, see our writeup on running Claude Opus 4.8 in Claude Code.

The ladder in one glance

  1. Tokens arriving slowly? Not an error — the model is thinking. Wait.
  2. Base URL = https://llmapi.pro, with no /v1 or /messages suffix. (Fixes most fake connection errors.)
  3. Read the status code: 401 = key, 404 = path/model, 429 = rate limit.
  4. curl smoke test to isolate Claude Code vs. config vs. network.
  5. Proxy / VPN / firewall: test from a network you control.

Nine times out of ten the answer is in the first three rungs, and you never had a network problem at all.

If you don't have a key yet, you can grab one at /register and point Claude Code at https://llmapi.pro.

llmapi.pro is an independent, Claude-compatible API relay; we are not affiliated with Anthropic. Claude Code is used for identification only.

Share this article

Start using LLM API

Free tier available. One-line configuration for Claude Code.

Get Started Free