Unable to connect to API (ConnectionRefused) in Claude: causes and fixes
Claude Code cannot open a connection to the API. We check the address, proxy, DNS and network with three curl commands and find the cause from the result.
6 min · · errors · API keys
The message "Unable to connect to API (ConnectionRefused)" in Claude Code means the program could not even open a connection to the address it was given. This is not a key error (that would be a 401) and not a balance error (402): the request simply never reached a server. Below are the causes from most to least common and a curl-based diagnostic order that shows in five minutes where the break is.
What ConnectionRefused means
"Connection refused" is a rejection at the connection level: nothing accepts connections at that address and port, or a proxy between you and the server refuses them. If a server had received the request and rejected it, you would see an HTTP code with a response body. So the first rule of diagnosis is to find out whether you get any HTTP response at all. If you do, the network works and the problem is the key, the model or the balance. If you do not, look at the address, proxy, DNS or network.
Causes by frequency
- Wrong
ANTHROPIC_BASE_URL. A typo in the domain,http://instead ofhttps://, a stray port, the address of a local proxy that was once set up and is no longer running (for examplehttp://localhost:3456). - The variable does not reach Claude Code. You wrote it into
~/.zshrcbut launch the editor or terminal from a graphical shell that does not read it. Or the variable is set in a different terminal window. - A dead or wrong proxy.
HTTPS_PROXYorHTTP_PROXYis set to an address where nothing listens. - DNS does not resolve the domain. A resolver problem, a corporate DNS issue, or the hosts file.
- The network cuts outbound connections. A corporate firewall or organization network limits. A network administrator helps here.
- The address with or without
/v1. For Claude Code this usually gives a 404, not a refusal, but extra path segments in the address are worth removing too.
Diagnostics in five minutes
Step 1. What is actually set
In the same terminal where you run claude:
echo "$ANTHROPIC_BASE_URL"
echo "${ANTHROPIC_AUTH_TOKEN:0:9}" # first characters of the key, should be fetch_...
env | grep -i proxyFor Zukko the right values are ANTHROPIC_BASE_URL=https://api.zukko.pro (without /v1, with https) and ANTHROPIC_AUTH_TOKEN=fetch_.... Empty output means the variable is not set in this session. In PowerShell use $env:ANTHROPIC_BASE_URL and Get-ChildItem Env:*proxy*. If you set variables in the Claude Code settings file (an env block in settings.json), check the Claude Code documentation and look at that file too: it can override environment variables. Inside a session you can also try the /status command, if your version has it.
Step 2. Is the server reachable
curl -sS -o /dev/null -w "%{http_code}\n" https://api.zukko.pro/v1/modelsThe model list is public and does not check the key, so this command only answers the network question. We check the key in step 3. In PowerShell call curl.exe, because curl there is an alias for another command. Read the result:
| curl result | Meaning | Where to look |
|---|---|---|
200 | the server is reachable, the network is fine | go to step 3 |
| another HTTP code | the server is reachable and answered | not the network: check the address and see step 3 |
curl: (7) Failed to connect ... Connection refused | connection refused | proxy in env, wrong address, a network filter |
curl: (6) Could not resolve host | DNS cannot find the domain | resolver, hosts, corporate DNS |
curl: (28) timed out | packets do not arrive | firewall, route, network problems |
curl: (35) or (60) | TLS error | proxy certificate substitution, wrong system time |
Step 3. Check the key and the messages format
If GET /v1/models answers, test the same path Claude Code uses. This request does check the key:
curl -sS https://api.zukko.pro/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-sonnet-5-5","max_tokens":20,"messages":[{"role":"user","content":"ping"}]}'A response with model text means the key and the API work and the error lies in the Claude Code environment. 401 means a wrong key, 402 not enough balance, model_not_found a wrong model name (the list of available ones comes from GET /v1/models). Other codes are described in the authentication docs.
Fixes by cause
Wrong address. Change it to https://api.zukko.pro, without /v1 and without a trailing path. If you doubt where /v1 is needed and where not, read the article Base URL with or without /v1.
A local proxy address is left over. Run unset ANTHROPIC_BASE_URL (or remove the line from ~/.zshrc, or from system variables on Windows), open a new terminal and set the correct address. Check whether the old value sits in the Claude Code settings file.
Variables are not visible. Set them in your shell profile (~/.zshrc, ~/.bashrc) and start Claude Code from a new terminal. If you launch from an editor, open it from a terminal or set the variables in its terminal settings. On Windows you need to restart the terminal after changing system variables.
A wrong proxy. If you need a proxy (for example, in an organization), fix its address. If you do not, remove HTTPS_PROXY and HTTP_PROXY for this session: unset HTTPS_PROXY HTTP_PROXY. If the network is corporate and outbound connections are restricted, ask the administrator: they know which addresses are allowed.
DNS. Check nslookup api.zukko.pro. If the domain is not found, change the system DNS server to another one available to you or check the hosts file for stale entries.
Certificates and time. TLS errors are often caused by a wrong system clock or an organization proxy substituting its own certificate. In an organization the proxy's root certificate is added to the trusted store according to your IT department's rules.
If the error persists after the fixes
- Repeat step 2 from another network (for example a mobile hotspot): if it returns
200there, the cause is in your main network. - Try the request from another computer. That separates a problem on your machine from a network problem.
- If curl returns
503, that is already a server response, not a refused connection: the model provider is unavailable or the model is switched off (model_disabled); pick another model fromGET /v1/models. - If Claude Code instead asks you to log in to an Anthropic account, that is a different situation: Claude Code asks to log in to Anthropic.
FAQ
Is "Unable to connect to API" a key problem?
No. A wrong key makes the server answer 401, while here the connection is not established at all. Still, check the key with the request from step 3: if it returns 401, the network is fine and the key needs replacing.
Does Claude Code work from Russia?
Access from Russia goes through a gateway: set https://api.zukko.pro in ANTHROPIC_BASE_URL, create a key in the dashboard, pay by SBP, MasterCard or crypto. If ConnectionRefused still appears after setup, the diagnostics above will show where the break is.
Should I add /v1 to ANTHROPIC_BASE_URL?
No. Claude Code appends /v1/messages itself, so for it the address has no /v1. Adding it by mistake usually leads to a 404.
How do I quickly check that the key and balance are fine?
Run the request from step 3: a model reply means the key is valid and the balance is sufficient (otherwise you would get 401 or 402). The remaining balance and usage are visible in the dashboard under "Usage".
The key and Claude Code settings live in the dashboard: create a key, set the two environment variables and repeat the check.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- OpenAI API Keys in the Open: Why You Should Not Use ThemWhere free keys on GitHub come from, why using them is dangerous for you and for the owner, and how to protect your own key from the same leak.
- GLM API Errors: Why the Request Fails and How to Fix ItA wrong model id, an overflowing 128K context, the key, the balance, limits: the typical causes of GLM API errors and a quick way to find yours.
- This organization has been disabled in the Claude API: What to DoAn Anthropic key suddenly answers "organization has been disabled". What the error is, what to check, and how to move the SDK and Claude Code to another provider.
- Gemini API not working: region, key, limits and model nameStep-by-step Gemini API diagnostics: from checking status and region to a leaked key, 429 and 503 errors and a typo in the model name.