“Unable to connect to API” in Claude Code on Mac
Claude Code prints Unable to connect to API when a request does not reach api.anthropic.com. The Claude Code documentation names no internet access, a VPN that blocks the host, or an unset corporate proxy as common causes.
My Mac has this problem: “Unable to connect to API” in Claude Code on Mac. Read https://kilobat.app/guides/claude-code-unable-to-connect-to-api.md and work through it with me. Install the Kilobat CLI if it’s missing: brew install seifip/kilobat/kilobat. Run the guide’s Terminal and kilobat checks yourself and tell me what you find. List the steps only I can do. Ask before you change any setting.
Symptoms
- Claude Code prints
Unable to connect to API. Check your internet connection. - The message can end with a code, such as ENOTFOUND, EHOSTUNREACH or ECONNRESET.
- Requests fail, but other apps may work.
Likely causes
- No internet access. The Mac is offline or has no DNS.
- A VPN that blocks the API host. The Claude Code documentation lists this as a common cause.
- A proxy that is not set. A required corporate proxy needs
HTTPS_PROXYbefore launch. - A proxy that refuses the tunnel. ERR_PROXY_TUNNEL means that the proxy refused the tunnel. Check its credentials and that it allows this host.
How to check
Test the API host from the same shell.
curl -I https://api.anthropic.comShow the proxy variables.
env | grep -i proxyRun the checks inside Claude Code.
/doctorTest the host name through macOS.
dscacheutil -q host -a name api.anthropic.com
How to fix it
If DNS fails, fix it. See DNS not resolving on a Mac.
Behind a corporate proxy, set it before you launch.
export HTTPS_PROXY=http://proxy.example.com:8080If you use a gateway, set
ANTHROPIC_BASE_URLto its address.Turn off the VPN for a short test. Turn it on again after.
With Kilobat
Kilobat's connection doctor tests the API host layer by layer: network, proxy, DNS, rules, IPv4, IPv6, TLS and the server.
kilobat why https://api.anthropic.comThese Kilobat checks are free. AI agents run them through MCP with
diagnose_connectionanddiagnose_network. See Find why one site or API won't connect.
Questions
Is the code in brackets important?
Yes. ENOTFOUND points to DNS, EHOSTUNREACH to a route, ECONNRESET to a reset, ERR_PROXY_TUNNEL to a proxy.
Do I restart Claude Code after I set a variable?
Yes. The network configuration page says that a running session does not pick up later shell changes.
Sources
Checked on 29 October 2026.