API Keys
Anthropic API Key
Powers Claude-based agents in apps/mastra.
Quick reference
- Env var:
ANTHROPIC_API_KEY - Required for: scaffold choice
llm: anthropic(default). Skip if you scaffolded withllm: openai. - Permissions / scopes: none — Anthropic API keys are account-scoped, not permission-scoped. Any active key works.
- Validation:
mastrakit doctor --key ANTHROPIC_API_KEY(sends a 1-token test message)
Create one
- Go to console.anthropic.com.
- Sign in (or create an account — you'll need a payment method on file before keys can be created).
- Click API Keys in the left sidebar.
- Click Create Key, give it a name like
mastrakit-<your-slug>-dev, click Create Key. - Copy the key (
sk-ant-api03-...). You can only view it once.
Add to your project
Paste into .env.dev-secrets (gitignored):
ANTHROPIC_API_KEY=sk-ant-api03-...Save the file, then tell your deploy agent you're done. The agent will run mastrakit doctor --key ANTHROPIC_API_KEY and continue if it passes.
Common validation failures
❌ ANTHROPIC_API_KEY: 401 invalid api key— Key was typed/pasted wrong, revoked, or you copied from the wrong workspace. Re-create at console.anthropic.com.❌ ANTHROPIC_API_KEY: 402 payment required— Account has no payment method or has exceeded its free credits. Add a card under Settings → Billing.❌ ANTHROPIC_API_KEY: 429 rate limited— Wait a minute and retry; the validator only sends 1 request.
Workspaces and key scope
Anthropic API keys are scoped to a workspace, not your whole organization. If your org has multiple workspaces, make sure the key is from the workspace you want to bill. The validator output includes the workspace name when it can detect it (✅ ok (workspace: production)).