Skip to content
AI Dev Toolkit.
Esc
  • AI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.Tool
  • LLM API Cost CalculatorEstimate per-request, daily and monthly API costs.Tool
  • AI Model ComparisonCompare prices, context windows and features across models.Tool
  • AI Model Pricing PagesSpecs, real costs and cheaper alternatives for popular models.Tool
  • Context Window CheckerSee whether your text fits each model's context window.Tool
  • Subscription vs API CalculatorFind out whether a chat plan or the API is cheaper for you.Tool
  • GPU / VRAM CalculatorCheck how much VRAM a local model needs and which GPUs fit.Tool
  • Claude Code Error DatabaseExact Claude Code error messages with tested fixes.Tool

Claude Code · Certificates and network

Unable to connect to API

Claude Code couldn’t open a network connection to the API at all; the code in brackets says why.

Message

The exact error

Claude Code
Unable to connect to API. Check your internet connection

Also appears as:

Connection refused
Connection refused — a firewall or proxy may be blocking it (ConnectionRefused)
DNS failure
Can't reach the API server — check your internet or DNS (ENOTFOUND)
No route
No internet route — check your connection or VPN (EHOSTUNREACH)
Proxy refused the tunnel
Couldn't connect through your proxy (ERR_PROXY_TUNNEL) — the proxy refused the tunnel: check its credentials and that it allows this host
Dropped
Connection dropped (ECONNRESET)
Before v2.1.227
Unable to connect to API (ECONNREFUSED)

Meaning

What it means

This is a plain network failure: no response, before any certificate check. The code in brackets tells you the kind of failure: refused (something actively blocked it), not found (DNS), no route (VPN or network down), a proxy refusing the tunnel, or a dropped connection.

Causes

Common causes

  • No internet, or a VPN that blocks or reroutes api.anthropic.com
  • A required corporate proxy that isn’t configured, or one rejecting your credentials
  • A leftover ANTHROPIC_BASE_URL pointing at a local proxy or gateway that isn’t running
  • A broken DNS resolver (common in WSL), or Docker Desktop intercepting traffic

Fix

How to fix it

  1. Test the connection from the same terminal

    Any HTTP status line means you reached the API. No response, Could not resolve host or a timeout points to your network, VPN or firewall.

    macOS / Linux
    curl -I https://api.anthropic.com
    Windows PowerShell (curl.exe, not the Invoke-WebRequest alias)
    curl.exe -I https://api.anthropic.com
  2. Configure your proxy

    Set the proxy before launching Claude Code. Claude Code doesn’t support SOCKS proxies.

    macOS / Linux
    export HTTPS_PROXY=http://proxy.example.com:8080
    claude
    Windows PowerShell
    $env:HTTPS_PROXY = 'http://proxy.example.com:8080'
    claude
  3. If curl works but Claude Code doesn’t, look for a stale gateway URL

    Run echo $ANTHROPIC_BASE_URL (or echo $env:ANTHROPIC_BASE_URL) and check the env block of your settings files. A value pointing at a gateway that’s no longer running produces “Connection refused” even though the internet works. Remove it and start Claude Code from a new terminal.

  4. Check DNS and other interceptors

    On Linux and WSL, check /etc/resolv.conf for an unreachable nameserver. Quit Docker Desktop or similar tools and retry, and on macOS look for leftover VPN tunnel interfaces (utun) from an uninstalled VPN.

Related

Search all Claude Code errors