---
title: "Anthropic API Key"
description: "Powers Claude-based agents in apps/mastra."
source: "/docs/keys/anthropic-api-key"
---


Quick reference [#quick-reference]

* Env var: `ANTHROPIC_API_KEY`
* Required for: scaffold choice `llm: anthropic` (default). Skip if you scaffolded with `llm: 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 [#create-one]

1. Go to [console.anthropic.com](https://console.anthropic.com).
2. Sign in (or create an account — you'll need a payment method on file before keys can be created).
3. Click **API Keys** in the left sidebar.
4. Click **Create Key**, give it a name like `mastrakit-<your-slug>-dev`, click **Create Key**.
5. Copy the key (`sk-ant-api03-...`). You can only view it once.

Add to your project [#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 [#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 [#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)`).
