# ANTHROPIC_API_KEY

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** ANTHROPIC_API_KEY environment variable

## Think of it like

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

## 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

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.

## Example code

```bash
export ANTHROPIC_API_KEY=sk-ant-your-key
claude -p "Explain this repo"
```

Run on an API key, not a plan.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [API Key](https://learn.benibix.com/term/development/api-key)
- [ANTHROPIC_AUTH_TOKEN](https://learn.benibix.com/term/ai/anthropic-auth-token-variable)
- [/login Command](https://learn.benibix.com/term/ai/login-command)
- [Non-Interactive Mode](https://learn.benibix.com/term/ai/non-interactive-mode)

## Told apart from

- [ANTHROPIC_API_KEY vs ANTHROPIC_AUTH_TOKEN](https://learn.benibix.com/compare/anthropic-api-key-variable-vs-anthropic-auth-token-variable): People think ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are two names for one key. They send different headers to different checkers. The API key is a Console key. It goes out as X-Api-Key, and Anthropic checks it. The token goes out as a Bearer header, and a gateway checks it. When both are set, the token wins. Use the key to reach Anthropic, and the token to reach your gateway.

![When many sign-ins are set, Claude Code uses the first one it finds in this list.](https://learn.benibix.com/diagrams/env-auth-order.svg)

---

Source: https://learn.benibix.com/term/ai/anthropic-api-key-variable
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
