Skip to content
BENIBIX Learn

ANTHROPIC_API_KEY

AI⌨️ Claude CodeConfiguration

Also known as ANTHROPIC_API_KEY environment variable

It gives Claude Code an API key to sign in and pay with.

Think of it like

It is like a key card. If you carry it, the door uses it before your name.

Example

Jack's CI job sets ANTHROPIC_API_KEY from a secret. Each run then signs in with the team's key, with no browser and no login.

Why it matters

It is the plain way to run Claude Code in a script, and it decides who pays.

Definition

ANTHROPIC_API_KEY gives Claude Code a key from the Claude Console. Claude Code sends it in the X-Api-Key header and bills that account. When it is set, it is used in place of your Pro or Max plan, even if you are logged in. In a chat you are asked once to allow it. With -p it is always used.

Example code

bash
export ANTHROPIC_API_KEY=sk-ant-your-key
claude -p "Explain this repo"
Run on an API key, not a plan.
ANTHROPIC_API_KEY is third in the list.

Common mistake

Leaving it set in your shell and then wondering why your plan is not used. Run unset ANTHROPIC_API_KEY.

Key takeaways

  1. 1
    X-Api-Key header. A Console key.
  2. 2
    Beats your plan. Even when logged in.
  3. 3
    Asked once. Always used with -p.

Compare