Fix Claude Code "Unable to connect to API" errors
Claude Code Unable to connect to API (ENOTFOUND, ECONNREFUSED) means no connection to the API. Run curl -I in the same shell to split DNS, proxy and VPN causes.
Unable to connect to API. Check your internet connectionConnection refused — a firewall or proxy may be blocking it (ConnectionRefused)Can't reach the API server — check your internet or DNS (ENOTFOUND)No internet route — check your connection or VPN (EHOSTUNREACH)Couldn't connect through your proxy (ERR_PROXY_TUNNEL) — the proxy refused the tunnel: check its credentials and that it allows this hostConnection dropped (ECONNRESET)Request timed out. Check your internet connection and proxy settingsThe Unable to connect to API family means Claude Code could not open a TCP connection to the API. The cause is usually internet access, DNS, a VPN or a corporate proxy, and running curl -I https://api.anthropic.com in the same shell that runs Claude Code tells you which. As of v2.1.227, a plain-language description precedes the code in parentheses (ENOTFOUND and so on).
[1] Use the code in parentheses to pick where to look.
| Message (code) | Look at first |
|---|---|
Can't reach the API server (ENOTFOUND, FailedToOpenSocket) | DNS: the name does not resolve |
No internet route (EHOSTUNREACH) | Routing: a dropped VPN or a leftover route |
Connection refused (ConnectionRefused, ECONNREFUSED) | Firewall or proxy, or a leftover ANTHROPIC_BASE_URL |
Couldn't connect through your proxy (ERR_PROXY_TUNNEL) | The proxy refused the tunnel: proxy credentials and allowed hosts |
Connection dropped (ECONNRESET) | Cut mid-connection: proxy or gateway |
Claude Code retries intermittent failures automatically, so when you see this message the retries failed too.
[2] Check that the API host is reachable from the shell that runs Claude Code. A 404 is fine: any HTTP response means DNS, routing and TLS all work.
$ curl -sS -I --max-time 15 https://api.anthropic.comHTTP/2 404 date: Tue, 27 Oct 2026 03:42:09 GMTserver: cloudflare…In Windows PowerShell, curl is an alias for Invoke-WebRequest, so run curl.exe -I https://api.anthropic.com.
[3] If curl fails too, its error number splits the causes. Below are the results in a container with networking off, and with a proxy that is not listening.
$ curl -sS -I --max-time 15 https://api.anthropic.comcurl: (6) Could not resolve host: api.anthropic.com$ HTTPS_PROXY=http://127.0.0.1:9 curl -sS -I --max-time 15 https://api.anthropic.comcurl: (7) Failed to connect to api.anthropic.com port 443 via 127.0.0.1 after 0 ms: Could not connect to server(6) Could not resolve host is DNS. On Linux and WSL, check that the nameserver in /etc/resolv.conf is reachable; WSL in particular can inherit a broken resolver from the host. A (7) with via <proxy address> means the proxy itself is unreachable, so check the HTTPS_PROXY value left in the shell first.
[4] On a network that requires a corporate proxy, export the proxy variables before starting Claude Code.
$ export HTTPS_PROXY=http://proxy.example.com:8080$ export NO_PROXY="localhost,example.com"$ claudeLowercase variables work too; Claude Code uses the first one set in the order https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY. SOCKS proxies are not supported. The basic hosts to allow in the firewall are api.anthropic.com, claude.ai and platform.claude.com; the full list is in Network access requirements. For certificate errors from a TLS-inspecting proxy, see the certificate step in Claude Code error messages and fixes.
[5] If curl works but Claude Code does not, look between Claude Code and the network, not at the network. Check for a leftover ANTHROPIC_BASE_URL first. When it is set, model requests go to that address instead of api.anthropic.com, so a value pointing at a local proxy or gateway that is no longer running gives Connection refused while curl succeeds.
$ echo $ANTHROPIC_BASE_URL$ grep -n ANTHROPIC_BASE_URL ~/.claude/settings.json .claude/settings.json .claude/settings.local.jsonIf a value shows up, first work out who set it.
- A gateway address set by your company or administrator (a company-distributed settings file or shell profile, an internal gateway host name): do not remove it. Removing it sends requests around the company gateway and changes the authentication, billing and audit path. Only check whether the address answers with
curl -I "$ANTHROPIC_BASE_URL"; if it does not, the gateway is down, so tell your administrator. - A local proxy or gateway you started yourself and no longer run (an address such as
localhostor127.0.0.1): it is a leftover. Write the value down before removing it (to undo, put it back in the same place), remove it from your shell profile or theenvblock of the settings file, and start Claude Code from a new terminal.
If that does not help, check these:
- On macOS, a disconnected or uninstalled VPN can leave a
utuninterface or a routing rule behind. Look for staleutunentries withifconfig, and in System Settings remove the network extension only of a VPN you already uninstalled or no longer use. Removing the extension of a VPN you still use cuts the connections that go through it, and undoing that means reinstalling the VPN client. For a company VPN, ask your administrator first. - Docker Desktop and similar container runtimes can intercept outbound traffic. Quitting the runtime also stops the containers and services running in it, so check what is running with
docker psfirst, then quit it briefly at a time when that is acceptable and retry to rule it out. After the test, start Docker Desktop again and bring the containers you need back up.
[6] If you use a gateway through ANTHROPIC_BASE_URL and every request ends in Connection dropped, test whether the gateway rejects tool search fields with ENABLE_TOOL_SEARCH=false claude (on by default behind gateways since v2.1.304).
[7] Unable to connect to Anthropic services before the first sign-in is the startup check from the same family. It probes api.anthropic.com and platform.claude.com for 10 seconds each, and when the probe went through a proxy it names the variable, as in A proxy is configured via HTTPS_PROXY. Check that variable and the proxy's allowlist; if the network is open and it still fails, check the supported countries list.
No response from API, where the connection opens but response headers never arrive, is covered in No response from API timeout.
Check it with the dig output explainer tool ↗ — calculated in your browser.