← Back to Blog

How to Use Claude Code Without an Anthropic API Key

(Unofficial)

This guide is independently community-maintained. It is not affiliated with, endorsed by, or sponsored by the vendor of the third-party tool it covers. All third-party trademarks are the property of their respective owners.

November 5, 2026
A laptop connects across a glowing bridge portal to cloud server towers in a purple night landscape.

TL;DR: The first screen after installing Claude Code usually says "log in to an Anthropic account or enter an API key". If you are stuck there, the problem is usually not the tool — it is the "official key" step. Conclusion first: Claude Code works without an official Anthropic key. This article covers the applicability boundaries of three real paths, the minimal working configuration, the triage order for common errors, and key-leak hygiene.

1. Why you get stuck at the "no official key" step

Separate the concepts first — every judgment below depends on it: Claude (the web and app subscription), Anthropic Console (the API platform), and Claude Code (the terminal tool) are three different things. Signing up for Claude on the web and then being asked for a different set of credentials when you open Claude Code is a common misunderstanding.

What actually blocks people usually falls into three categories:

  • Payment and regional restrictions: registering and topping up on Anthropic Console requires a foreign payment method, and some regions additionally hit risk-control blocks

  • No suitable entity: individual developers do not have a corporate card and do not want to bind a foreign card just for a trial

  • An unclear cost model: assuming subscription quota can be spent as API quota

The third one is worth clearing up first because it is the cheapest to fix: the Claude Code terminal CLI does not accept official credentials only. The official docs state on the Claude Code overview page that all three forms — Terminal CLI, VS Code, and JetBrains — support third-party providers at the same time; the cost page also states that Pro / Max subscribers get "usage included in their subscription". In other words, subscription and third-party access are both officially supported paths, and "subscription is not API quota" does not conflict with either.

2. Three real paths: find yours first

Path

What you need

Who it fits

Main limitation

Official subscription (Pro / Max)

A Claude subscription account

Individual users with a fixed budget and mostly interactive usage

No programmatic API quota beyond the subscription; account signup itself may hit regional restrictions

Anthropic Console direct

A foreign payment method + a Console account

Teams that want the shortest path and can complete foreign payment

Registration and top-up impose payment-method requirements — exactly where most people get stuck

Anthropic-compatible gateway

A gateway account + one gateway key

Developers without a foreign card, or those managing multiple vendors' models together

Billing and auth happen on the gateway side; you need to watch your own usage

How to choose: if you already have a subscription, just log in with the account — simplest. If you can complete foreign payment and are sure you will only use Anthropic long-term, go Console direct. If neither works, use a compatible gateway — expanded in section 3.

3. The minimal working configuration for the gateway path

The official Claude Code environment variables doc (code.claude.com/docs/en/env-vars) defines several key variables; three form the minimal set:

  • `ANTHROPIC_BASE_URL`: overrides the API endpoint and routes requests to a proxy or gateway. The official wording is "route requests through a proxy or gateway".

  • `ANTHROPIC_AUTH_TOKEN`: the value of a custom Authorization header, prefixed with `Bearer` automatically. Use it for gateways.

  • `ANTHROPIC_API_KEY`: sent as the X-Api-Key header. Use it for direct official access.

One precedence rule you must know: once `ANTHROPIC_API_KEY` is set, it overrides your Pro / Max / Team / Enterprise subscription — even if you are already logged in. In interactive mode Claude Code prompts you to confirm once; in non-interactive mode (-p) it just uses the key. To keep using your subscription, the official approach is unset ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN.

So connecting a gateway needs only the first two; the minimal config looks like this:

json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.codegateway.dev",
"ANTHROPIC_AUTH_TOKEN": "sk-cg-YOUR_KEY"
}
}

Put this into the env field of ~/.claude/settings.json; for a quick check you can also export the two variables directly. Do not add a `/v1` suffix to `ANTHROPIC_BASE_URL` — the client appends /v1/messages itself, and the extra segment returns 404.

After writing the config, send a small request first (a single short message) to verify — do not start a long task right away. For complete snippets (Claude Code / Codex CLI / Claude Desktop / generic OpenAI-compatible), use the client config generator; this page only covers how to choose and debug the no-key path.

One boundary worth drawing: the CLI and the desktop client are two different mechanisms. The block above configures the terminal CLI. If you are configuring the Claude desktop client, it uses claude_desktop_config.json and developer mode — a different config file path, different fields, and a different activation flow; see Claude desktop developer mode for a custom API endpoint and the claude_desktop_config.json configuration guide. Do not copy settings across the two.

4. Where settings live and which one wins

Claude Code reads settings from several locations; the official docs give the full precedence (checked 2026-10-30):

Managed settings > command line (`--settings`) > project local (`.claude/settings.local.json`) > project shared (`.claude/settings.json`) > user-level (`~/.claude/settings.json`)

Two details people trip on:

  1. Environment variables are not inside this hierarchy. The official docs state explicitly: when a behavior has both a shell variable and a settings key, they are compared pairwise — not overridden wholesale by level. So "I exported the variable but it did not take effect" is usually not a hierarchy problem; in that particular pair, the settings key happened to win.

  2. Same-named lists are merged, not overridden. If permissions.allow is set in several files, Claude Code merges the lists instead of keeping only one of them — every file can add entries without wiping the others.

5. Triage order for common errors

Error texts below are copied from real responses, not invented. Five classes by status code (per the in-site troubleshooting guide, checked 2026-10-30):

401 Unauthorized | `invalid x-api-key` — authentication failure. Three common sources: the key copied with whitespace or missing characters, the key disabled or deleted, or using an official Anthropic key by mistake (the gateway side requires a key issued by the gateway). Triage order: check the key's enabled state on the Dashboard → use the on-page "Copy" button instead of retyping → confirm the header form (x-api-key or Authorization: Bearer).

403 — in this site's terms, insufficient balance. Top up and retry; only contact support if 403 persists while the balance is sufficient.

429 Too Many Requests — rate limiting, with RPM and TPM windows. Retry cadence per the site's terms: wait 1s after the 1st failure, 2s after the 2nd, 4s after the 3rd, at most 3 retries. For a new key's first calls, use a small payload and do not burst concurrent requests.

5xx (500 / 502 / 503) — transient upstream unavailability; retrying the same request is enough. Site terms: contact support only if Anthropic's status is normal but 5xx persists for 10 consecutive minutes.

400 Bad Request | `messages: missing required field` — the request parameters are wrong; fix them yourself: missing model / messages / max_tokens, or a mistyped model name.

Disconnects without an HTTP status (`ECONNRESET` / `ETIMEDOUT`) — network layer: check whether your machine can reach the target domain; a corporate proxy is a frequent culprit; SSE streaming needs a long-lived connection — make sure no proxy in the middle enforces a 60-second timeout.

Where is the "regional restriction"? To be clear: regional and payment restrictions happen at the official registration and top-up stage, not as runtime error codes. Once you are on the gateway path, errors fall back into the five classes above — there are no region-class failures anymore.

Two more traps that only appear when connecting a gateway, worth knowing in advance:

  • The first session may miss feature flags. The official docs point out: if you authenticate with ANTHROPIC_AUTH_TOKEN without an API key, and ANTHROPIC_BASE_URL points at a non-Anthropic host (a gateway, for example), Claude Code has no credentials to fetch feature flags. The symptom: in the first session after install or upgrade, a flag-gated feature is missing.

  • The model selector does not list gateway models by default. The official escape hatch is CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY: set it to 1 and Claude Code pulls models from the gateway's /v1/models into the /model selector; it is off by default.

6. Key-leak hygiene

Once you have a key, a few cheap and effective rules:

  • One key per project. Usage splits naturally by key; how much each project spent is visible at a glance, which simplifies accounting and reimbursement; when something goes wrong you revoke only one key.

  • Never commit keys to the repo. The project-shared .claude/settings.json is readable by teammates and cloud sessions — to keep config in project files, inject it via environment variables instead of hardcoding the key.

  • Local files are plaintext too. A key sits in plaintext in your own settings.json, on your machine only; when picking a provider, look at its policy on key storage and logging first (CodeGateway shows the key plaintext only once at creation; the server stores only a hash).

  • Do not share keys. The official docs note that keys under managed settings do not automatically reach teammates; do not send your key to others either.

  • Revoke regularly. Keys in finished projects, one-off scripts, and CI should not stay valid indefinitely.

7. Reading cost and usage

Billing is per token, and the bill is visible in real time on the Dashboard: the overview shows balance, recent usage, and a per-model spend breakdown, and the top-up checkout page itemizes the top-up amount and the service fee. CodeGateway applies a flat multiplier of 1.07× on top of upstream official list prices and charges a 2% service fee on top-ups; see the multiplier explained page for the composition.

Also, Smart Routing is off by default and enabled on demand: by default, requests go to the model you specify; it takes effect only when you explicitly turn it on, and you can turn it back off. Details in the Smart Routing docs.

8. FAQ

Are third-party gateways safe? Your key is stored only in your local config file. When choosing a provider, look at its policy on key storage and logging — that matters more than "cheap".

Can I use a subscription and a gateway at the same time? Yes. Put the gateway config in the project-level .claude/settings.local.json so it affects only that project; other projects keep using subscription login.

Do I still need to install official Claude Code? Yes. The gateway replaces only the endpoint and auth; the tool itself installs and upgrades as usual, with no feature impact.

Where do most people fail earliest? At the "no key" step, not in the tool itself. Treat this section as a multiple-choice question — subscription, Console, or gateway — everything after that is configuration.

9. Get a key now

No official key, or you would rather not bind a foreign card? ⇒ Get one at CodeGateway. Sign up and start using it right away — one key reaches Claude / GPT / Gemini and other model families; billed per use: pay for what you consume, balance visible, no monthly minimum. Billing and top-up details are on the pricing page and in the top-up and fees guide.

Suggested order: create a key on the Dashboard → set the two environment variables with the Claude Code quick script → send one small request to verify → then start real tasks.

Author:CodeGateway Team

Solve API Key & Billing limits with CodeGateway

Lacking an official API key or facing overseas card payment issues? Create an sk-cg- key instantly. One key for Claude, GPT, Gemini, and DeepSeek: Claude and Gemini text models use the Anthropic Messages protocol (/v1/messages) — the OpenAI-compatible text endpoints do not accept them. Built-in smart routing and free trial credits included.

Sign up free
Use Claude Code Without an Anthropic API Key