---
title: "“Unable to connect to API” in Claude Code on Mac · Kilobat Guides"
url: "https://kilobat.app/guides/claude-code-unable-to-connect-to-api"
description: "Claude Code on your Mac prints Unable to connect to API. Check your connection, a VPN that blocks the API host, and a proxy that you must set."
---

# “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 agent**Copies 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](https://kilobat.app/guides/dns-server-not-found).
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](https://kilobat.app/guides/recipes/why-cant-it-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

- [Claude Code: Error reference](https://code.claude.com/docs/en/errors.md)
- [Claude Code: Enterprise network configuration](https://code.claude.com/docs/en/network-config.md)

Checked on 29 October 2026.

## Related guides

- [“Request timed out” in Claude Code on Mac](https://kilobat.app/guides/claude-code-request-timed-out): Claude Code prints Request timed out when the API does not respond before the connection deadline.
- [“Unable to connect to API: SSL certificate verification failed” on Mac](https://kilobat.app/guides/claude-code-ssl-certificate-verification-failed): Claude Code prints this when a certificate comes from an authority that it does not trust.
- [“curl: (6) Could not resolve host” on Mac](https://kilobat.app/guides/curl-could-not-resolve-host): curl exit code 6 means that curl could not get an address for the host name.
- [Proxy settings stop apps from connecting on a Mac](https://kilobat.app/guides/proxy-settings-breaking-apps): A proxy setting sends traffic through another server.
