“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.

Fix this with your agentCopies a prompt for Claude Code, Codex or any agent that can use Terminal.

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.

Applies to: Claude Code in a terminal on all current macOS versions.Checked: 29 October 2026

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_PROXY before 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

  1. Test the API host from the same shell.

    curl -I https://api.anthropic.com
  2. Show the proxy variables.

    env | grep -i proxy
  3. Run the checks inside Claude Code.

    /doctor
  4. Test the host name through macOS.

    dscacheutil -q host -a name api.anthropic.com

How to fix it

  1. If DNS fails, fix it. See DNS not resolving on a Mac.

  2. Behind a corporate proxy, set it before you launch.

    export HTTPS_PROXY=http://proxy.example.com:8080
  3. If you use a gateway, set ANTHROPIC_BASE_URL to its address.

  4. Turn off the VPN for a short test. Turn it on again after.

With Kilobat

  1. 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.com
  2. These Kilobat checks are free. AI agents run them through MCP with diagnose_connection and diagnose_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.