Claude Code · Certificates and network
Unable to connect to API
Fix “Unable to connect to API” in Claude Code: ConnectionRefused, ECONNREFUSED, ECONNRESET, ENOTFOUND and proxy errors, with checks for each OS.
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 does “Unable to connect to API” mean?
“Unable to connect to API” means Claude Code couldn’t open a network connection to api.anthropic.com at all: no response arrived, before any certificate check. To fix it, run curl -I https://api.anthropic.com from the same terminal. If curl fails, fix your network, VPN or proxy. If curl works, look for a stale ANTHROPIC_BASE_URL, a broken resolver or a tool intercepting traffic. The code in brackets says what kind of failure it was.
Causes
What causes it?
- 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 do I test and fix the connection?
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 and remove the VPN’s network extension in System Settings.Rule out project settings
Start Claude Code from a different folder. If it works there, a project-level
.claude/settings.jsonorsettings.local.jsonis settingANTHROPIC_BASE_URLor a proxy variable in itsenvblock: remove the stale value. The settings.json builder shows what each file sets.
Explained
What do ConnectionRefused, ENOTFOUND, EHOSTUNREACH and ECONNRESET mean?
ConnectionRefused / ECONNREFUSED: something actively refused the connection, often a stopped local gateway named in ANTHROPIC_BASE_URL, or a firewall. ENOTFOUND / FailedToOpenSocket: DNS couldn’t resolve the host. EHOSTUNREACH: no route, typically a VPN or the network being down. ERR_PROXY_TUNNEL: your proxy refused the tunnel; check its credentials and that it allows the host. ECONNRESET: the connection was dropped part-way, often by a proxy, VPN or unstable Wi-Fi.
Claude Code retries dropped connections automatically, so a persistent ECONNRESET means the path keeps failing: try another network or disconnect the VPN, and ask IT to raise the proxy’s idle timeout for *.anthropic.com. If the request reaches the API but gets no answer in time, you see Request timed out instead; a certificate message means a TLS-inspecting proxy or a hostname mismatch.
Explained
What if setup says “Unable to connect to Anthropic services”?
During first-run setup Claude Code checks that it can reach api.anthropic.com and platform.claude.com, giving each check 10 seconds, and exits with the reason, such as Failed to connect to api.anthropic.com: ECONNREFUSED. The checks go through the same proxy settings, so the steps on this page apply. If your network is open and it still fails, Claude Code may not be available in your country.
FAQ
Questions people ask
Why can’t Claude Code connect to the API when my browser works?
Your browser may use system proxy settings or a different network path. Claude Code uses HTTPS_PROXY and its own settings, so a required proxy that isn’t set, a leftover ANTHROPIC_BASE_URL, or a VPN that routes terminals differently can block it. Test with curl -I https://api.anthropic.com in the same terminal, then check those settings.
Is “Unable to connect to API” an Anthropic outage?
Rarely. It is reported before any HTTP response arrives, so it normally points to your connection, proxy, DNS or VPN. Outages usually show as API Error 500 or 529 instead. Check status.claude.com to be sure, but if curl to api.anthropic.com fails from your machine, the problem is local.
Does reinstalling Claude Code fix ConnectionRefused?
Usually not, because the cause is the network or a setting, not the program. Before reinstalling, check ANTHROPIC_BASE_URL in your shell and in the env block of your user and project settings files, and start Claude Code from a different folder to rule out project settings.
Related
Related errors
- SSL certificate hostname mismatch (ERR_TLS_CERT_ALTNAME_INVALID)Certificates and network
- Request timed outCertificates and network
- Claude Code SSL certificate error: verification failed (UNABLE_TO_GET_ISSUER_CERT_LOCALLY)Certificates and network
- API Error: 500 Internal server errorServer and limits
- API Error: No response from APICertificates and network
Keep exploring