ANTHROPIC_API_KEY vs ANTHROPIC_AUTH_TOKEN
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.
ANTHROPIC_API_KEY
It gives Claude Code an API key to sign in and pay with.
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.
ANTHROPIC_AUTH_TOKEN
It sends a token that a gateway can check.
ANTHROPIC_AUTH_TOKEN sets a token for Claude Code to send in the Authorization header. Claude Code puts Bearer in front of it. It is for a gateway or proxy that checks tokens, not Anthropic keys. When both are set, it wins over the API key.
In one line
- ANTHROPIC_API_KEY
- It gives Claude Code an API key to sign in and pay with.
- ANTHROPIC_AUTH_TOKEN
- It sends a token that a gateway can check.