ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY: which one to use in Claude Code

Coding with AIClaude Code·· 23 views· 3 min read

Claude Code has two variables for the key. Our API accepts both, so the choice does not change what you pay. It changes the header the key travels in and how Claude Code treats it.

The difference

Variable How the key is sent What the Claude Code documentation says
ANTHROPIC_AUTH_TOKEN In the Authorization: Bearer ... header A custom value for the Authorization header. Claude Code adds Bearer in front.
ANTHROPIC_API_KEY In the x-api-key header When set, it is used instead of your Claude subscription, even if you are signed in. In interactive mode, Claude Code asks you once to approve the key.

Which one we recommend

ANTHROPIC_AUTH_TOKEN, as in the docs examples. Set only one of the two: that way you always know which key Claude Code sends.

export ANTHROPIC_AUTH_TOKEN="$INTERWEB_API_KEY"

$INTERWEB_API_KEY copies the key from the variable where you already keep it. In settings.json it works differently: there, the key is written exactly as it is. See saving the setup in settings.json.

If you use ANTHROPIC_API_KEY

1 Set it to your key: export ANTHROPIC_API_KEY="$INTERWEB_API_KEY".
2 Open Claude Code. It asks you, once, whether to use this key. Accept: it is your Interweb key.
3 To go back to your Claude subscription, remove the variable and our address: unset ANTHROPIC_API_KEY ANTHROPIC_BASE_URL.

Neither one works for the MCP server

In the header of a remote MCP server, Claude Code reads ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY as empty, so that a project file cannot send your credentials to another server. In .mcp.json, use ${INTERWEB_API_KEY}, even if it holds the same key. See sharing the MCP setup in .mcp.json.

A 401 means the key did not arrive or is wrong. Check that the variable exists in the terminal where you opened Claude Code, without showing it on screen:

test -n "$ANTHROPIC_AUTH_TOKEN" && echo OK || echo missing

If it says "missing", set the variable and open Claude Code again.

Want to code with AI in Claude Code? Visit the Coding with AI page.

See Coding with AI

SEE ALSO

Using Claude Code with All in One AI: the variables, the model and common errors

Saving the Claude Code setup in settings.json so you do not set the variables every time

Sharing the MCP setup with your team in .mcp.json without sharing the key

Creating an API key: name, mode, permissions, validity, IP list and spending limit

Coding with AI in All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.