How to Fix 'Unable to Connect to API' in Claude Code
The Unable to connect to API error means Claude Code couldn’t reach the API server.
To fix it, run curl -I https://api.anthropic.com to test your connection, then check your VPN, proxy, and firewall. If curl works, look for a leftover ANTHROPIC_BASE_URL value.
The error can show up in a few different forms:
Unable to connect to API. Check your internet connection
Connection 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)
Connection dropped (ECONNRESET)
Request timed out. Check your internet connection and proxy settings
Let’s go through the fixes, starting with the test that tells you where the problem is.
Step 1: Test the connection
Run this command in the same terminal where you run Claude Code:
curl -I https://api.anthropic.com
On Windows PowerShell, use curl.exe, because plain curl runs a different PowerShell command:
curl.exe -I https://api.anthropic.com
The result decides what you do next:
curlshows an HTTP response, even an error status: your network can reach the API. Go to step 4curlfails or hangs: the problem is your network. Continue with steps 2 and 3
Step 2: Check your VPN and firewall
A VPN or firewall can block the connection to api.anthropic.com. To find out, turn your VPN off and try again.
If you’re on a company network, ask your network team to allow the hosts Claude Code needs. At minimum, that includes api.anthropic.com and platform.claude.com. The network access requirements page has the full list.
Step 3: Set your proxy
If your network requires a proxy, set HTTPS_PROXY before you start Claude Code:
export HTTPS_PROXY=https://proxy.example.com:8080
claude
Replace the address with your company’s proxy. If you see Couldn't connect through your proxy (ERR_PROXY_TUNNEL), the proxy refused the connection, so check its credentials and whether it allows this host.
Step 4: Check ANTHROPIC_BASE_URL
If curl works but Claude Code still fails, check this variable first. When it’s set, Claude Code sends requests to that address instead of api.anthropic.com.
echo $ANTHROPIC_BASE_URL
On PowerShell:
echo $env:ANTHROPIC_BASE_URL
A leftover value pointing at a local proxy that’s no longer running causes Connection refused, even though curl reaches the API just fine.
If you don’t need it, unset it:
unset ANTHROPIC_BASE_URL
Also look for it in the env block of your settings files, and remove the line from your shell profile if you set it there.
Step 5: Check for other local causes
If it still fails, these are the other common causes:
- Linux and WSL: check
/etc/resolv.conffor an unreachable nameserver. WSL can inherit a broken resolver from Windows - macOS: a VPN you disconnected or uninstalled can leave a tunnel behind. Run
ifconfigto look for staleutuninterfaces, and remove the VPN’s network extension in System Settings - Docker Desktop: container tools can intercept outbound traffic. Quit Docker and try again
“Unable to connect to Anthropic services”
This similar error appears during first-time setup, before you sign in:
Unable to connect to Anthropic services
Failed to connect to api.anthropic.com: ECONNREFUSED
Claude Code checks that it can reach api.anthropic.com and platform.claude.com, and exits if either check fails.
Work through the same steps above. If the message names a proxy variable like HTTPS_PROXY, check that value first.
If your network is open and the error doesn’t go away, Claude Code may not be available in your country.
Is Claude Code down?
Check status.claude.com to see if there’s an outage.
Note that a capacity problem looks different from a connection problem. It shows a message like this:
API Error: Repeated 529 Overloaded errors. The API is at capacity — this is usually temporary.
This isn’t caused by your network and doesn’t count against your usage. Wait a few minutes, or run /model to switch to a different model.
Conclusion
Start with curl -I https://api.anthropic.com. If it fails, check your VPN, firewall, and proxy. If it works, look for a leftover ANTHROPIC_BASE_URL.
Claude Code retries brief connection failures automatically, so a one-off error usually fixes itself.