Claude Code API key setup: from first login to a cloud server A developer guide details how to configure Claude Code with an Anthropic API key, showing that setting the ANTHROPIC_API_KEY environment variable (or placing it under env in ~/.claude/settings.json) switches billing from a Pro or Max subscription to per-token charges against the key's Console organization. The writeup explains credential precedence—an approved API key overrides a saved subscription login—and notes that API-key sessions do not support Anthropic's official cloud sessions or Remote Control. It also distinguishes ANTHROPIC_API_KEY (X-Api-Key header) from ANTHROPIC_AUTH_TOKEN (Authorization: Bearer) for gateways, and recommends sticking to one configuration method to avoid 401 errors. Originally published at alwaysagent.app https://alwaysagent.app/claude-code-api-key . The original is kept up to date. Setting an API key in Claude Code takes one environment variable, but the details decide whether you get billed per token, which credential wins, and whether Anthropic's own cloud features still work. Here is the full picture, with copy-paste config. To use an API key with Claude Code, export ANTHROPIC API KEY or put it under env in ~/.claude/settings.json , start claude , approve the key when asked, and confirm with /status . Requests are then billed per token to the account that owns the key, not drawn from a Pro or Max subscription. bash export ANTHROPIC API KEY="