Claude Code API Key Login vs Subscription Login: How to Switch
Claude Code supports two common ways to sign in: with a Claude subscription account, or with an API key from the Anthropic Console. Subscription usage counts against your plan's allowance, while an API key is billed per token to your Console account. You can switch between them, but if both a subscription login and an API key are present in your environment, Claude Code warns about a conflict and you need to keep just one. This article covers the differences, how to tell which one you are using, and how to switch.
UI text and commands here follow the official Claude Code documentation, which may differ from what you see after a version update.
What is the difference between the two login methods?
| Item | Subscription login | API key login |
|---|---|---|
| Credential source | Claude account (personal or team subscription) | A key created in the Anthropic Console |
| Billing | Included within the plan's usage limits | Billed per token, deducted from the Console account balance |
| Usage cap | Limited by the plan's usage window; see the official docs for exact rules | Limited by the Console balance and organization limits |
| Best for | Everyday interactive development with fairly steady usage | Spiky usage, precise cost accounting, scripts and CI |
| Terms | The terms of service for that subscription | The API commercial terms |
This table is only a summary. What a plan includes and how limits are calculated can change at any time, so confirm on Anthropic's official pages. If you are still deciding, read Claude Code: subscription or API billing, how to choose and Claude Code subscription login or API key: trade-offs between the two billing models.
How do I check which login I'm using?
Check three places, in this order.
- In a Claude Code session, run
/statusand look at the authentication details. The output varies by version; see the official docs. - In your terminal, check whether a key is set in the environment:
# Only check that the variable exists; never print the key to the screen or logs
[ -n "$ANTHROPIC_API_KEY" ] && echo "ANTHROPIC_API_KEY is set" || echo "not set"
[ -n "$ANTHROPIC_AUTH_TOKEN" ] && echo "ANTHROPIC_AUTH_TOKEN is set" || echo "not set"
- Check whether the
envfield insettings.jsondefines either variable. Settings files exist at several levels (user, project, and so on); for precedence, see Claude Code settings.json: levels, precedence, and env configuration.
The key may have been set in a project's .claude/settings.json or in your shell profile, and it is easy to forget, so check all of these places.
How do I switch from subscription login to an API key?
- Create a key in the Console and make sure the account has available balance. For setup and permissions, see How to get a Claude API key: Console setup, top-up, and permissions.
- In a session, run
/logoutto sign out of the subscription login. - In the shell where you start Claude Code, set
ANTHROPIC_API_KEY:
export ANTHROPIC_API_KEY="your key"
claude
- After startup, in interactive mode Claude Code may ask whether to use this key. Follow the prompt; the exact wording is in the official docs.
- Run
/statusagain to confirm.
Do not put the key in any file that gets committed to a repository. If a team shares access, use one key per person; see How teams manage API keys: one key per person, budget splits, and rotation.
How do I switch from an API key back to subscription login?
Do the reverse:
- Run
unset ANTHROPIC_API_KEY, and also delete the corresponding lines from your profile and from theenvfield insettings.json. Otherwise it takes effect again on the next launch. - Open a fresh terminal and start
claude. - Run
/loginand choose to sign in with a Claude account. - Confirm with
/status.
What should I do about an auth conflict warning?
The typical case: you signed in with a subscription earlier, and later ANTHROPIC_API_KEY showed up in your environment. At startup you see an auth conflict message, sometimes along with a 401. The cause is that both credentials exist and Claude Code cannot tell which to use.
The fix is simple:
- To use the subscription: remove the key from your environment variables and
settings.json, then run/login. - To use the API key: run
/logoutfirst and keep the key. - If you get a 401: confirm the key is not mistyped or revoked, that the Console account has a balance, and that the organization is in good standing.
A full breakdown of the error is in Claude Code auth conflict warning and 401 errors: how to fix them. If the Console says your organization is disabled, that is a different class of problem; see Anthropic API organization disabled: causes, scope, and what to do.
If you suspect a server-side problem rather than a misconfiguration, check cdnping's Anthropic API status and whether Claude Code is down to rule out an official outage before changing your configuration.
Do you know what each option will cost?
The biggest risk with API key login is an unpredictable bill: long-running agent tasks can burn through a lot of tokens in a row. Do two things before you start:
- Set a spending limit in the Console and turn on balance alerts. The exact options depend on the Console page.
- Estimate usage from your own habits first. See How to estimate Claude Code token usage: calculate monthly cost from your own usage.
If you keep hitting the usage cap on a subscription, don't switch to an API key right away. Work out where the usage is going first; see Claude Code quota not enough: check usage first, then decide whether to upgrade or change billing.
What if I have no Claude account or overseas payment method?
For some readers the problem is not which login to pick but that neither is convenient: no usable Claude subscription, and no non-Chinese credit card to top up the Console. Another route worth knowing about is a compatible gateway. AGI Plan is a business partner of cdnping, and what follows is a brief summary based on its public website: AGI Plan is a multi-provider LLM aggregation gateway sold as a monthly subscription, paid in RMB, with no overseas credit card required. It is compatible with both the OpenAI and Anthropic API formats. To use it with Claude Code you point the endpoint at the address it provides and swap in a key it issues; no Claude account is needed.
A few points to be clear about:
- The service states plainly that it is not an officially authorized channel. It is a third-party service, and whether it suits you is your call.
- One subscription covers several capability groups, and some models are marked "overseas only." See the AGI Plan models page for specifics.
- For prices, see the official pricing page.
- Before using any relay or gateway, read Are Claude API relays reliable? Four main risks and checks you can run yourself.
The setup uses the same mechanism as the env field in settings.json described above; see Custom API endpoints for Claude Code, Codex, and OpenCode. For getting started, see the AGI Plan quick start.
What should I do next?
- Run the check commands above to confirm which login you are actually using right now.
- Pick one based on your usage, and estimate the monthly cost.
- Clean up the other method's credentials completely, including environment variables, your profile, and
settings.json. - If you see a 401 or a conflict warning, work through the auth conflict article item by item.