Guide

Claude Code API key and login

Harrowtech.ai · last checked 13 October 2026

Most people sign in to Claude Code with a Claude subscription. An API key from the Claude Console is the other route: it bills by usage, and a key left in your environment can take over from your subscription. This guide covers signing in, using a key on purpose, and the fix for each common error.

Harrowtech.ai is independent of Anthropic. Quick check: run /status inside Claude Code. It shows which credential is active, and when a login and an API key are both set up it marks the one not in use.

Signing in with a subscription

Pro, Max, Team and Enterprise accounts all sign in this way. Team and Enterprise members use the claude.ai account their admin invited.

Using an API key on purpose

A Claude Console account is Anthropic's route for usage-based billing. Anthropic's authentication page describes it as the option for organisations that prefer API-based billing. There are two ways in.

Option 1: let Claude Code sign in to the Console

Run /login and choose the Anthropic Console account. From v2.1.242, Claude Code then asks how to sign in:

Unset ANTHROPIC_API_KEY before choosing the first route. If your admin invited you to the Console, they gave you one of two roles: the Claude Code role can only create Claude Code keys, and the Developer role can create any kind.

Option 2: create a key yourself and set it

  1. Sign in at platform.claude.com, or create an account.
  2. Go to Settings, then API keys.
  3. Click Create key. Name it, choose when it expires, set Linked account to yourself or a service account, and optionally pick a workspace.
  4. Copy the key. It starts sk-ant- and the Console shows it only once. Anthropic suggests keeping it somewhere safe such as a secrets manager. A lost key cannot be viewed again; create a new one.

Anthropic recommends a personal key for your own development and a service account key for anything shared, such as a CI pipeline. A personal key stops working if you leave the organisation. If the Create key button is greyed out, your role may not allow it; an organisation admin can change the role or create a service account key.

Then set the key in the shell you start Claude Code from:

export ANTHROPIC_API_KEY="sk-ant-api03-..."
claude

How Claude Code picks the key up

Which credential wins

When several are present, Anthropic's authentication page gives this order, highest first:

1. Cloud providerWhen CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX or CLAUDE_CODE_USE_FOUNDRY is set.
2. ANTHROPIC_AUTH_TOKENA bearer token, for an LLM gateway or proxy.
3. ANTHROPIC_API_KEYA Console key, once approved.
4. apiKeyHelperThe output of your key script.
5. CLAUDE_CODE_OAUTH_TOKENA one-year token made with claude setup-token, for CI and scripts. It needs a Pro, Max, Team or Enterprise plan.
6. Anthropic profileProfile and federation credentials, as used by Anthropic's ant CLI and Workload Identity Federation. Some profiles rank below /login; Anthropic's page has the detail.
7. /loginYour subscription login, the default for Pro, Max, Team and Enterprise.

That order is why an old key in a shell profile overrides a working subscription. Anthropic notes that a signed-in Claude apps gateway sits outside this list and outranks all of it.

How billing differs

SubscriptionUsage is included in the plan, up to its usage limits. On Team and Enterprise, Claude Code draws on each member's seat allowance, which it shares with Claude chat. Usage credits can take you past a limit, and /usage-credits manages them.
Console API keyBilled per token to your organisation, from prepaid credits. On first Console sign-in, a workspace called "Claude Code" is created for cost tracking, and admins can set workspace spend limits. When the credits run out, requests fail with Credit balance is too low.

Other differences Anthropic lists:

Per-token prices are on Anthropic's pricing page. Claude Code pricing lists them alongside the subscription plans.

Errors and fixes

Your ANTHROPIC_API_KEY belongs to a disabled organization, or API Error: 400 ... This organization has been disabledAn old ANTHROPIC_API_KEY is overriding your subscription. Run unset ANTHROPIC_API_KEY (PowerShell: Remove-Item Env:ANTHROPIC_API_KEY) and remove the export line from ~/.zshrc, ~/.bashrc or ~/.profile. On Windows, also check $PROFILE and your User environment variables. If the message says "Update or unset", there is no saved login to fall back to, so run /login as well. Then check /status.
Invalid API key · Fix external API keyCheck for typos and that the key has not been revoked in the Console. Run env | grep ANTHROPIC (PowerShell: Get-ChildItem Env:ANTHROPIC*). Anthropic warns that tools such as direnv and IDE terminals can load a stale key from a .env file. To use your subscription instead, unset the key and run /login.
Credit balance is too lowEither the Console organisation has run out of prepaid credits, or an approved ANTHROPIC_API_KEY is sending requests through the Console when you meant to use your plan. Check the API key row in /status. Add credits under Billing in the Console, or unset the key.
Your organization has disabled API key authenticationThe Console admin has turned keys off. Unset ANTHROPIC_API_KEY or remove the apiKeyHelper setting, as the message says, then run /login. /login alone does not help while a key is still set.
Not logged in · Please run /loginRun /login. If you expected a key to sign you in, check ANTHROPIC_API_KEY is set and exported in the shell that started claude.
Login expired · Please run /loginClaude Code could not renew your saved claude.ai login and cleared it. Run /login. Claude Code warns three days before a login expires.
OAuth token revoked · Please run /login, or API Error: 401 OAuth token has expiredRun /login. If you use CLAUDE_CODE_OAUTH_TOKEN, make a fresh token with claude setup-token, or unset the variable and log in.
API Error: 401 Invalid authentication credentialsThe account or organisation behind the credential was revoked, disabled or removed. Run /status first. If an API key is active, rotate it in the Console or unset it. If only your login is active, run /login once; if the error returns, ask your admin to restore access.
OAuth error: Invalid code. Please make sure the full code was copiedThe code expired or was cut short. Retry quickly, or press c to copy the full URL. Over SSH, open that URL in your local browser.
API Error: 403 Request not allowedPro or Max: check the subscription is active at claude.ai/settings. Console users: confirm the account has the Claude Code or Developer role, which admins set on the Console's Members page. Behind a corporate proxy, check the network set-up.
Claude Code access has not been granted for this accountOn Enterprise, your role is Custom and none of your custom roles includes Claude Code. An Owner must assign one that does, or change your role to a standard one such as User. Then log in again.

If you are asked to log in again and again, Anthropic suggests checking the system clock, because token checks depend on correct time. On a Mac, a locked Keychain can also cause it; claude doctor reports that case.

What this guide does not cover

It does not cover Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry set-up, LLM gateways, or the managed settings admins use to restrict which login people may use. Anthropic's authentication page covers those. Installing Claude Code is covered in How to install Claude Code.

Sources

Related: All Harrowtech.ai guides · Claude Code pricing · Claude Code CLI and headless mode · Claude Code commands