Claude Code API Key: Setup, Configuration & Provider Options

Set up your Claude Code API key in 2 minutes. We cover Anthropic direct, AWS Bedrock, Google Vertex, and third-party providers like Morph. Plus: spend limits, key rotation, and team key management.

March 5, 2026 · 3 min read

Claude Code needs an API key to work. You have four provider options, each with different pricing, rate limits, and compliance characteristics. This guide covers setup for all of them.

Provider Options

Anthropic Direct

Fastest setup. Best rate limits. Pay-per-token at published rates. Key starts with sk-ant-.

AWS Bedrock

Consolidated AWS billing. Enterprise compliance. Slightly higher per-token cost. Uses AWS credentials.

Google Vertex AI

GCP-native billing. Uses application default credentials. Available in GCP regions.

Third-Party Providers

OpenRouter, Morph, and others. Additional features like caching, fast apply, and model routing.

Quick Setup (Anthropic Direct)

The fastest path from zero to working Claude Code:

3-step setup

# 1. Install Claude Code
npm install -g @anthropic-ai/claude-code

# 2. Set your API key (add to ~/.zshrc or ~/.bashrc)
export ANTHROPIC_API_KEY="sk-ant-your-key-here"

# 3. Start Claude Code
cd your-project && claude

Alternatively, run claude auth for an interactive login flow that stores credentials securely without environment variables.

Environment variable vs claude auth

ANTHROPIC_API_KEY takes priority over stored auth. If you set both, the environment variable wins. Use the environment variable for automation and CI. Use claude auth for personal machines where you do not want keys in your shell profile.

AWS Bedrock Setup

Bedrock lets you use Claude through your AWS account. Billing, compliance, and access control go through AWS.

Bedrock configuration

# Enable Bedrock provider
export CLAUDE_CODE_USE_BEDROCK=1

# Standard AWS credentials
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_REGION="us-east-1"

# Or use AWS SSO / IAM role (recommended)
aws sso login --profile your-profile
export AWS_PROFILE="your-profile"

# Start Claude Code — it auto-detects Bedrock
claude

Prerequisite

You must request model access for Claude in the AWS Bedrock console before your first request. Go to Bedrock > Model access > Request access for Anthropic Claude models. Approval is usually instant for most AWS accounts.

Google Vertex AI Setup

Vertex AI uses your GCP credentials. Claude runs in Google's infrastructure, billed through your GCP project.

Vertex AI configuration

# Enable Vertex provider
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION="us-east5"
export ANTHROPIC_VERTEX_PROJECT_ID="your-gcp-project-id"

# Authenticate with GCP
gcloud auth application-default login

# Start Claude Code
claude

Third-Party Providers

Third-party providers add features on top of Claude's API. Configuring alternative providers is done through environment variables.

ProviderKey FeatureSetup
Anthropic DirectBest rate limits, lowest latencyANTHROPIC_API_KEY
AWS BedrockAWS billing & complianceCLAUDE_CODE_USE_BEDROCK=1 + AWS creds
Google VertexGCP billing & complianceCLAUDE_CODE_USE_VERTEX=1 + GCP creds
MorphFast apply at 10,500 tok/sConfigure as custom provider
OpenRouterMulti-model routingOPENROUTER_API_KEY

Spend Limits & Budgets

Set spending caps before your first session. The Anthropic Console provides daily and monthly limits per API key.

$20/day
Recommended starting daily limit
$500/mo
Recommended starting monthly limit
/cost
Command to check session spend

When a cap is hit, API requests return an error. Claude Code displays a clear message that your spending limit has been reached. No charges beyond the cap. Adjust limits in the Anthropic Console at any time.

For a complete cost optimization guide, see Claude Code Cost.

Key Rotation & Security

API key hygiene prevents unauthorized usage and surprise bills.

Never Commit Keys to Git

Use .env files (gitignored) or environment variables set in your shell profile. If a key lands in version control, revoke it immediately.

Rotate Keys Periodically

Generate a new key in the Anthropic Console, update your environment variable, revoke the old key. Claude Code picks up the new key on the next session.

Use direnv for Per-Project Keys

Create a .envrc file per project with its own API key. Each project gets independent spend tracking and budget limits.

Per-project API key with direnv

# In your project root, create .envrc
echo 'export ANTHROPIC_API_KEY="sk-ant-project-specific-key"' > .envrc

# Allow direnv for this directory
direnv allow

# Now Claude Code uses this project's key automatically
claude

Team Key Management

For teams, create organization-level API keys with per-developer tracking.

StrategyProsCons
One key per developerIndividual spend tracking, easy revocationMore keys to manage
One key per projectProject-level budgets, simple rotationCan't track individual usage
Organization keySingle key, centralized managementNo granular tracking, risky if leaked

The recommended approach: one key per developer with project-level spend limits via direnv. This gives you both individual accountability and project-level budget control.

FAQ

My API key is not working. What should I check?

Four common causes: (1) trailing whitespace in the key (regenerate and copy carefully), (2) key revoked or expired, (3) spending limit reached, (4) ANTHROPIC_API_KEY not exported to the shell running Claude Code. Run echo $ANTHROPIC_API_KEY to verify.

Can I use Claude Code without an API key?

No. Claude Code requires either an API key (Anthropic, Bedrock, or Vertex) or a Max subscription. There is no free tier for Claude Code.

How do I use a different model?

Set CLAUDE_MODEL=claude-sonnet-4-6-20260214 in your environment, or use the /model command inside Claude Code to switch models mid-session.

Faster edits, fewer tokens

Morph's fast apply model handles Claude Code file edits at 10,500 tok/s. Same quality, 70-80% fewer edit tokens. Works with any API provider.