Claude Code · Certificates and network
Unable to connect to API
Claude Code couldn’t open a network connection to the API at all; the code in brackets says why.
Message
The exact error
Unable to connect to API. Check your internet connectionAlso appears as:
- Connection refused
- Connection refused — a firewall or proxy may be blocking it (ConnectionRefused)
- DNS failure
- Can't reach the API server — check your internet or DNS (ENOTFOUND)
- No route
- No internet route — check your connection or VPN (EHOSTUNREACH)
- Proxy refused the tunnel
- Couldn't connect through your proxy (ERR_PROXY_TUNNEL) — the proxy refused the tunnel: check its credentials and that it allows this host
- Dropped
- Connection dropped (ECONNRESET)
- Before v2.1.227
- Unable to connect to API (ECONNREFUSED)
Meaning
What it means
This is a plain network failure: no response, before any certificate check. The code in brackets tells you the kind of failure: refused (something actively blocked it), not found (DNS), no route (VPN or network down), a proxy refusing the tunnel, or a dropped connection.
Causes
Common causes
- No internet, or a VPN that blocks or reroutes
api.anthropic.com - A required corporate proxy that isn’t configured, or one rejecting your credentials
- A leftover
ANTHROPIC_BASE_URLpointing at a local proxy or gateway that isn’t running - A broken DNS resolver (common in WSL), or Docker Desktop intercepting traffic
Fix
How to fix it
Test the connection from the same terminal
Any HTTP status line means you reached the API. No response,
Could not resolve hostor a timeout points to your network, VPN or firewall.macOS / Linux curl -I https://api.anthropic.comWindows PowerShell (curl.exe, not the Invoke-WebRequest alias) curl.exe -I https://api.anthropic.comConfigure your proxy
Set the proxy before launching Claude Code. Claude Code doesn’t support SOCKS proxies.
macOS / Linux export HTTPS_PROXY=http://proxy.example.com:8080 claudeWindows PowerShell $env:HTTPS_PROXY = 'http://proxy.example.com:8080' claudeIf curl works but Claude Code doesn’t, look for a stale gateway URL
Run
echo $ANTHROPIC_BASE_URL(orecho $env:ANTHROPIC_BASE_URL) and check theenvblock of your settings files. A value pointing at a gateway that’s no longer running produces “Connection refused” even though the internet works. Remove it and start Claude Code from a new terminal.Check DNS and other interceptors
On Linux and WSL, check
/etc/resolv.conffor an unreachable nameserver. Quit Docker Desktop or similar tools and retry, and on macOS look for leftover VPN tunnel interfaces (utun) from an uninstalled VPN.
Related