Error Fix · As of 2026-11-25

Claude Code "Unable to connect to API" (ENOTFOUND, EPROTO, ECONNRESET, ETIMEDOUT): Causes and Fixes

"Unable to connect to API" means Claude Code never got an HTTP answer from the address it was sending requests to. The code in parentheses tells you where it broke: ENOTFOUND is DNS, ECONNREFUSED/ConnectionRefused means nothing answered on that address or proxy, EPROTO and certificate errors are TLS, and ECONNRESET/ETIMEDOUT are a connection dropped or stalled on the way. Claude Code's exact wording has changed between releases: recent documentation and GitHub issues show forms such as Can't reach the API server — check your internet or DNS (ENOTFOUND) and Connection refused — a firewall or proxy may be blocking it (ConnectionRefused), while older builds print Unable to connect to API (ECONNRESET). Match on the code in parentheses, not on the full sentence.

QCode is an independent third-party API service, not affiliated with Anthropic. This page covers ordinary network and configuration problems with a correctly configured, permitted setup. It does not cover getting around any provider's access rules.

Updated 2026-11-26

Key facts

  • Message strings you may see (Claude Code docs and GitHub issues; exact wording differs by version): Unable to connect to API (ECONNRESET), Unable to connect to API (ConnectionRefused), Can't reach the API server — check your internet or DNS (ENOTFOUND), Connection refused — a firewall or proxy may be blocking it (ConnectionRefused), plus prefixes No internet route —, Couldn't connect through your proxy and Connection dropped, each followed by a code.
  • Certificate variants: SSL certificate verification failed, unable to get local issuer certificate, SELF_SIGNED_CERT_IN_CHAIN, Self-signed certificate detected. Claude Code does not retry these, so they appear on the first attempt.
  • Claude Code appends /v1/messages to ANTHROPIC_BASE_URL. For QCode the value is https://api.qcode.cc/api, with no /v1 and no trailing slash.
  • Proxy support: Claude Code reads HTTPS_PROXY, HTTP_PROXY and NO_PROXY (lowercase too) and does not support SOCKS proxies. Custom CAs go in NODE_EXTRA_CA_CERTS; the trust source can be set with CLAUDE_CODE_CERT_STORE=bundled,system.
  • Settings beat the shell: a value in the env block of ~/.claude/settings.json overrides the same variable exported in your shell. /status shows the base URL and proxy actually in use.
  • QCode domains: api.qcode.cc (default endpoint), asia.qcode.cc (Asia), us.qcode.cc (North America / Europe). The same key works on all three.

What each code means

Code / text Layer Plain meaning First thing to check
ENOTFOUND / Can't reach the API server DNS The hostname did not resolve Typo in ANTHROPIC_BASE_URL, VPN split-DNS, corporate DNS
ECONNREFUSED / ConnectionRefused TCP Something actively refused the connection A proxy variable pointing at a local proxy that is not running
EPROTO TLS The TLS handshake hit a protocol mismatch https:// vs http:// in the proxy URL, TLS-inspecting middlebox
Certificate errors TLS The certificate chain is not trusted Corporate TLS inspection without NODE_EXTRA_CA_CERTS
ECONNRESET / Connection dropped TCP / path The connection was cut mid-way Unstable route, VPN, router MTU, firewall idle timeout
ETIMEDOUT TCP / path No reply within the timeout Packet loss, blocked port 443, wrong endpoint for your location
API returned an empty or malformed response (HTTP 200) HTTP Something answered, but not with an API response Base URL points at a web page, captive portal or login page

EPROTO in Node.js usually comes with an OpenSSL detail such as wrong version number, which almost always means TLS was spoken to a port that expects plain HTTP, or the reverse.

Causes, ranked by likelihood

  1. A wrong ANTHROPIC_BASE_URL. Typos in the host give ENOTFOUND. http:// instead of https://, a trailing slash, or an extra /v1 give 404s or odd responses instead of model output. Tools that append their own path show doubled paths such as Invalid URL (POST /v1/v1/messages) (seen in Cline).
  2. Stale proxy variables. A shell profile, IDE terminal or .env loader exports HTTPS_PROXY=http://127.0.0.1:7890 for a proxy app that is closed, so every request is refused. Or the proxy is SOCKS-only, which Claude Code does not support.
  3. TLS inspection on a company network. The corporate proxy re-signs traffic with its own root certificate; Node does not trust it, so you get certificate errors or EPROTO.
  4. DNS problems. VPN clients with split DNS, filtered resolvers or a stale DNS cache.
  5. An unstable network path. ECONNRESET and ETIMEDOUT on specific routers, Wi-Fi, PPPoE links or VPNs. GitHub reports for Claude Code show users fixing this by changing the network or lowering the router MTU.
  6. Configuration not reaching the process. The variable is set in one terminal but Claude Code starts from another, from an IDE launched from the dock, or as a background agent that does not inherit your shell.

Step-by-step fixes

Step 1: Check what Claude Code is actually using

env | grep -i -E 'anthropic|proxy'
# PowerShell
Get-ChildItem Env: | Where-Object Name -match 'ANTHROPIC|PROXY'

Then start claude and run /status. Confirm the Anthropic base URL line and the Proxy row. If they differ from what you exported, look at the env block in ~/.claude/settings.json and .claude/settings.local.json, which override shell exports.

Step 2: Fix the base URL

export ANTHROPIC_BASE_URL=https://api.qcode.cc/api   # correct
# wrong: http://api.qcode.cc/api
# wrong: https://api.qcode.cc/api/
# wrong: https://api.qcode.cc/api/v1
export ANTHROPIC_AUTH_TOKEN=cr_your_key

In ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.qcode.cc/api",
    "ANTHROPIC_AUTH_TOKEN": "cr_your_key"
  }
}

Never put the key in a project's committed .claude/settings.json. For more on the variable itself see the ANTHROPIC_BASE_URL setup guide.

Step 3: Test connectivity outside Claude Code

These tests separate network problems from Claude Code problems.

# DNS
nslookup api.qcode.cc

# TCP + TLS timing (any HTTP status code proves the path works)
curl -sS -o /dev/null \
  -w 'dns=%{time_namelookup}s connect=%{time_connect}s tls=%{time_appconnect}s total=%{time_total}s code=%{http_code}\n' \
  https://api.qcode.cc/api/v1/messages

# Real request with a 1-token answer
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5-5","max_tokens":1,"messages":[{"role":"user","content":"."}]}'

On Windows PowerShell:

Resolve-DnsName api.qcode.cc
Test-NetConnection api.qcode.cc -Port 443

How to read the result:

  • curl fails with the same code: the problem is the network, proxy or DNS, not Claude Code.
  • curl succeeds but Claude Code fails: the variables do not reach Claude Code, or Claude Code's runtime does not trust a certificate that curl trusts.
  • JSON starting with {"id":"msg_: URL and key are fine. A 401 means the key is wrong (see 401 with a custom base URL).

Step 4: Fix proxy variables

If you do not need a proxy, remove the variables for the session and test again:

unset HTTPS_PROXY HTTP_PROXY ALL_PROXY https_proxy http_proxy all_proxy
curl --noproxy '*' -sS -o /dev/null -w '%{http_code}\n' https://api.qcode.cc/api/v1/messages

If you do need a corporate proxy, set it explicitly with the scheme the proxy really speaks (most corporate proxies are plain HTTP even for HTTPS traffic):

export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY="localhost,127.0.0.1,.internal.example.com"

A mismatch here (writing https:// for a plain-HTTP proxy port) is a classic source of EPROTO. If your proxy offers only SOCKS, Claude Code cannot use it; ask your IT team for an HTTP proxy endpoint.

Step 5: Fix TLS and certificate errors

If curl works only with your company's CA bundle, give the same bundle to Claude Code:

export NODE_EXTRA_CA_CERTS=/path/to/corporate-ca.pem
claude --debug

In the debug log (~/.claude/debug/<session-id>.txt) look for CA certs: Appended extra certificates from NODE_EXTRA_CA_CERTS. You can also control the trust source with CLAUDE_CODE_CERT_STORE=system or bundled. Do not leave NODE_TLS_REJECT_UNAUTHORIZED=0 set; it disables verification for every request and is only acceptable as a seconds-long diagnostic.

Step 6: Try another QCode endpoint

If DNS and TLS are fine but you see ECONNRESET or ETIMEDOUT, the route to one node may be poor. Switch domains and compare:

for h in api asia us; do
  curl -sS -o /dev/null -w "$h connect=%{time_connect}s tls=%{time_appconnect}s total=%{time_total}s code=%{http_code}\n" \
    https://$h.qcode.cc/api/v1/messages
done
export ANTHROPIC_BASE_URL=https://asia.qcode.cc/api   # or https://us.qcode.cc/api

Run it a few times at different hours before deciding. The endpoint selection and latency test guide explains how to measure time to first token properly.

Step 7: If only one network fails

Community reports on the Claude Code GitHub tracker describe ECONNRESET that disappears on a phone hotspot or after lowering the router's MTU (for example to 1492 on PPPoE). If a different network fixes it, the issue is the local path, not your configuration.

Fixes for other tools

Codex CLI. QCode's config is base_url = "https://api.qcode.cc/openai" with wire_api = "responses" in ~/.codex/config.toml. Test with curl -I https://api.qcode.cc, and try https://asia.qcode.cc/openai if one domain is slow. For TLS inspection, Codex reads CODEX_CA_CERTIFICATE (a PEM bundle, which takes precedence over SSL_CERT_FILE). Retry and idle behaviour can be tuned per provider with request_max_retries, stream_max_retries and stream_idle_timeout_ms.

Anthropic and OpenAI SDKs. Pass the base URL explicitly (https://api.qcode.cc/api for the Anthropic SDK, https://api.qcode.cc/openai/v1 for the OpenAI SDK) instead of relying on stray environment variables. Connection failures surface as APIConnectionError in both SDK families; log the underlying exception to see the code (ENOTFOUND, ECONNRESET).

VS Code extension and other IDE plugins. The Claude Code VS Code extension reads gateway variables from claudeCode.environmentVariables in VS Code's user settings, not from your terminal profile. Cline uses its own "Use custom base URL" field; set it to exactly https://api.qcode.cc/api. An IDE started from the dock or Start menu does not see variables exported in a terminal.

Background agents. Claude Code's background sessions run under a supervisor process that may not inherit your shell. Put the base URL, proxy and CA variables in ~/.claude/settings.json so every session gets them.

How to confirm it is fixed

  1. The curl POST returns JSON starting with {"id":"msg_.
  2. In Claude Code, /status shows the expected base URL and proxy, and a short prompt gets an answer without "Retrying in … seconds".
  3. Repeat once from the IDE you actually use, since it may have a different environment.

Prevention

  • Keep one source of truth for ANTHROPIC_BASE_URL and proxy variables, preferably ~/.claude/settings.json.
  • Remove proxy exports from shell profiles if the proxy app is not always running.
  • Install your company CA once and point NODE_EXTRA_CA_CERTS at it.
  • Bookmark the three QCode domains and know how to switch.
  • After network changes (new VPN, new router), rerun the curl tests before blaming the tool. For other gateway-related errors see Claude Code gateway errors.

FAQ

What does ENOTFOUND mean in Claude Code?

The hostname in your base URL could not be resolved by DNS. Check ANTHROPIC_BASE_URL for typos, then run nslookup api.qcode.cc; if that fails too, the problem is your DNS or VPN, not Claude Code.

Why do I get EPROTO behind a proxy?

EPROTO means the TLS handshake failed at the protocol level, usually because the proxy URL scheme is wrong (https:// for a plain-HTTP proxy) or a middlebox interferes with TLS. Use the scheme your proxy actually speaks and, for inspection proxies, add its CA via NODE_EXTRA_CA_CERTS.

Should ANTHROPIC_BASE_URL end with /v1?

No. Claude Code adds /v1/messages itself, so for QCode use https://api.qcode.cc/api. Adding /v1 or a trailing slash produces doubled paths and 404s.

Does Claude Code support SOCKS5 proxies?

No. Claude Code's documentation states that SOCKS proxies are not supported. Use an HTTP or HTTPS proxy through HTTPS_PROXY.

curl works but Claude Code still cannot connect. Why?

Either the variables do not reach the Claude Code process (check /status and settings files), or Claude Code's runtime does not trust a certificate that curl trusts. Set NODE_EXTRA_CA_CERTS to the same bundle curl uses.

Is it safe to set NODE_TLS_REJECT_UNAUTHORIZED=0?

Only for a quick diagnostic. It turns off certificate checks for all traffic, which exposes your key and code to interception. Fix the CA bundle instead.

Which QCode domain should I use?

Start with api.qcode.cc, the default endpoint. If you see timeouts or resets, compare asia.qcode.cc and us.qcode.cc with the curl timing loop and keep the most stable one; the same key works on all three.

ECONNRESET happens only on one Wi-Fi network. What now?

That points to the local path. Try another network or a hotspot, restart the router, and check its MTU setting. If another network works, your Claude Code configuration is fine.

Try it with a low-cost plan

Once the connection works, the Trial plan lets you use Claude Opus 5.5, Sonnet 5.5 and GPT-6.2 Sol on one key from $9 for 30 days, with a $5 daily quota billed at official price × 1.0. Current terms are on /pricing.

Try it with a low-cost plan

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack