Claude API

The developer endpoint — call Anthropic models from your own code via REST or an Anthropic SDK.

What it is

The Claude API is what you build with when you’re shipping your own product, agent, or backend integration. Authentication is via an API key from the Anthropic Console. SDKs exist for Python and TypeScript; the underlying interface is plain REST.

The API also hosts Claude Managed Agents — long-running agentic sessions Anthropic runs and bills on your behalf, on a separate endpoint family under /v1/agents, /v1/environments, and /v1/sessions (beta header managed-agents-2026-04-01). At Code with Claude on 2026-05-06 Anthropic moved three advanced capabilities into public beta: Outcomes (a self-grading loop — you define a rubric, a separate grader agent evaluates each iteration, the agent revises until the rubric passes) and Multi-agent Orchestration (a lead agent fans tasks to specialist sub-agents in parallel), plus Dreams in research preview (an async job that consolidates a memory store from past session transcripts; beta header dreaming-2026-04-21). The API also supports MCP for tool use, so the same MCP servers you wire into Claude Code or Claude Desktop can be called from your application.

When to use it

  • Building a product, internal tool, or backend service that calls Claude.
  • Running batch or background inference jobs at scale.
  • Programmatic agent loops (the SDK ships an Agent SDK for this).
  • Connecting MCP servers to your own code rather than to Claude.ai or Claude Code.

How to install / enable

  • Create an API key at https://console.anthropic.com (Settings → API keys).
  • Install an SDK.

    pip install anthropic
    # or
    npm install @anthropic-ai/sdk
    
  • Set the key as an environment variable.

    export ANTHROPIC_API_KEY=sk-ant-...
    
  • Make a request — see the SDK README for the current minimal example.
  • For MCP from your code: the SDK exposes tools and supports MCP servers as a tool source. See MCP servers.

Common pitfalls

  • API usage is metered and billed separately from a Pro/Max subscription — even if you’re a Pro user, API calls draw from your API credit balance.
  • The planned Agent SDK / claude -p billing split was paused. Anthropic had announced (2026-05-14) that programmatic usage — Agent SDK, claude -p, Claude Code GitHub Actions, third-party harnesses — would move off subscription limits onto a separate dollar-denominated credit pool on 2026-06-15. On that date Anthropic shelved the change; the Help Center now opens with a pause notice. For now, Agent SDK and claude -p usage still draws from your normal subscription limits. Anthropic says it will give notice before any future change, so treat the separate-credit design as possible-but-not-live.
  • Default model IDs change. The current generally-available line is Opus 5 (claude-opus-5, now the opus alias), Sonnet 5 (claude-sonnet-5, the sonnet alias), and Haiku 4.5. Opus 5 launched 2026-07-24 with a 1M-token context window (default and max), thinking on by default, and pricing unchanged from Opus 4.8 at $5 / $25 per million input / output tokens; it’s available on the Claude API, Bedrock, Vertex, and Foundry. Sonnet 5 (2026-06-30) also has a 1M window and intro pricing of $2 / $10 per million tokens through 2026-08-31 (then $3 / $15). Model IDs are dateless pinned snapshots from the 4.6 generation on. On Bedrock / Vertex / Foundry the aliases lag — pin the full model ID or set ANTHROPIC_DEFAULT_OPUS_MODEL to override.
  • Sonnet 5’s tokenizer produces ~30% more tokens than Sonnet 4.6 for the same text, so the 1M window holds less prose and per-request costs rise even though per-token pricing is unchanged. Sonnet 5 also has adaptive thinking on by default, rejects manual extended thinking with a 400, and (like the Opus 4.x line) rejects any non-default temperature / top_p / top_k with a 400 — omit them.
  • Fable 5 (claude-fable-5) is available again. After a 19-day suspension under a U.S. export-control order, the controls were lifted 2026-06-30 and Fable 5 was redeployed globally on 2026-07-01 across the Claude Platform, Claude.ai, Claude Code, and Cowork; cloud hyperscalers (Bedrock / Vertex / Foundry) are re-enabling on a rolling basis. Mythos 5 remains restricted to approved U.S. organizations. Fable 5 is adaptive-thinking-only, never returns raw chain of thought, costs $10 / $50 per million input / output tokens, supports 1M context / 128k output, and refuses dual-use cybersecurity and biology prompts via HTTP-200 stop_reason: "refusal".
  • claude-sonnet-4-20250514 and claude-opus-4-20250514 retired 2026-06-15 at 9am PT. API calls to those exact IDs (and the claude-opus-4-0 / claude-sonnet-4-0 aliases that resolved to them) now error. Migrate to claude-sonnet-4-6 and claude-opus-4-8; the Opus path also drops temperature / top_p / top_k and budget_tokens (all now 400) — use thinking: {type: "adaptive"} instead. Consumer Claude.ai and Claude Code managed environments pick models automatically and were unaffected.
  • Opus 4.7, 4.8, and 5 reject temperature, top_p, and top_k. Sending any of these — even at a “default” value — returns a 400; rejection is by presence, not value, and the SDK won’t catch it at compile time. Omit them entirely and steer behavior with prompting plus the effort parameter. Watch for OpenAI-compat layers, gateways, or frameworks that inject temperature for you.
  • Opus 5 has thinking on by default. Disabling thinking above high effort returns a 400 — leave adaptive thinking on for xhigh / max runs. On Claude.ai, Claude Code, and Cowork, a request that trips a safety classifier falls back to Opus 4.8; you can also enable that fallback on the API.
  • Prompt caching is opt-in but cheap to enable; turn it on when you reuse the same system prompt or tool schema across many calls. On Opus 4.8 only, you can append a role: "system" entry inside the messages array (immediately after a user turn) to update instructions mid-conversation without restating the top-level system prompt or invalidating the cached prefix — useful for long agentic loops. See mid-conversation system messages. Earlier models 400 on role: "system" in messages. Available on the Claude API and Claude Platform on AWS; not yet on Bedrock, Vertex, or Foundry.
  • Don’t put API keys in client-side code — keys are bearer tokens.
  • Managed Agents lives on its own endpoints; calling /v1/messages won’t give you Outcomes, Dreams, or multi-agent orchestration. Use the SDK’s client.beta.agents namespace (which sets beta headers automatically).

See also

Sources

  • Anthropic Console — verified 2026-05-23 (this run).
  • Anthropic API documentation — Anthropic docs; verified 2026-05-23.
  • Claude Agent SDK — Anthropic docs; verified 2026-05-23.
  • Prompt caching — Anthropic docs; verified 2026-05-23.
  • Define outcomes — Anthropic API docs; verified 2026-05-23 — Outcomes self-grading loop, rubric and grader semantics, managed-agents-2026-04-01 beta header.
  • Dreams — Anthropic API docs; verified 2026-05-23 — async memory-consolidation job, research preview, dreaming-2026-04-21 beta header.
  • New in Claude Managed Agents: dreaming, outcomes, and multi-agent orchestration — Anthropic blog; published 2026-05-06 — Code with Claude 2026 launch announcement.
  • Live blog: Code w/ Claude 2026 — Simon Willison; published 2026-05-06 — independent coverage of the keynote announcements.
  • Introducing Claude Opus 4.8 — Anthropic news; published 2026-05-28 — Opus 4.8 ship date, 1M context default, no premium pricing, available on Claude API / Bedrock / Vertex / Foundry.
  • What’s new in Claude Opus 4.8 — Anthropic API docs; verified 2026-06-09 (this run) — opus alias resolution per surface, claude-opus-4-8 model ID, ANTHROPIC_DEFAULT_OPUS_MODEL env var; temperature / top_p / top_k rejected with 400 (by presence, inherited from Opus 4.7); adaptive thinking replaces budget_tokens.
  • Mid-conversation system messages — Anthropic API docs; verified 2026-05-29 — Opus 4.8 accepts role: "system" in messages after a user turn; placement constraints and prompt-cache benefit.
  • Use the Claude Agent SDK with your Claude plan — Anthropic help center; verified 2026-06-20 (this run) — opening notice confirms the planned Agent SDK / claude -p billing split is paused as of 2026-06-15; usage still draws from subscription limits; planned (not-live) per-plan credit amounts listed.
  • Anthropic puts Claude agents on a meter across its subscriptions — InfoWorld; published 2026-05-14 — original announcement of the (now-paused) 2026-06-15 Agent SDK billing split and per-plan credit amounts.
  • Model deprecations — Anthropic API docs; verified 2026-06-20 (this run) — claude-sonnet-4-20250514 and claude-opus-4-20250514 retired 2026-06-15 at 9am PT (along with the -4-0 aliases); recommended replacements claude-sonnet-4-6 / claude-opus-4-8; adaptive thinking replaces budget_tokens.
  • Claude Fable 5 and Claude Mythos 5 — Anthropic news; published 2026-06-09 — Fable 5 = public model, Mythos 5 = Project Glasswing only; $10/$50 per Mtok; adaptive-thinking-only; 1M context / 128k output; HTTP-200 stop_reason: "refusal".
  • Redeploying Claude Fable 5 — Anthropic news; published 2026-06-30; verified 2026-07-04 (this run) — export controls lifted 2026-06-30; Fable 5 redeployed globally 2026-07-01 on Claude Platform / Claude.ai / Claude Code / Cowork, hyperscalers rolling; Mythos 5 restricted to approved U.S. orgs.
  • Introducing Claude Sonnet 5 — Anthropic news; published 2026-06-30; verified 2026-07-04 (this run) — claude-sonnet-5, default for Free / Pro / Claude Code, intro pricing $2/$10 per Mtok through 2026-08-31 (then $3/$15), available on API / Bedrock / Vertex / Foundry.
  • What’s new in Claude Sonnet 5 — Anthropic API docs; verified 2026-07-04 (this run) — claude-sonnet-5 = sonnet alias; 1M context (default and max), 128k output; adaptive thinking on by default, manual extended thinking → 400, non-default temperature/top_p/top_k → 400; new tokenizer produces ~30% more tokens than Sonnet 4.6.
  • Introducing Claude Opus 5 — Anthropic news; published 2026-07-24; verified 2026-07-25 (this run) — claude-opus-5, $5 / $25 per Mtok (unchanged from Opus 4.8), 1M context, effort ladder up to max, available on Claude API / Bedrock / Vertex / Foundry / claude.ai / Claude Code / Cowork; new default on Max, strongest on Pro; safety-classifier fallback to Opus 4.8 (default on consumer surfaces, opt-in on API); fast mode research preview at ~2.5× speed for 2× price.
  • Anthropic claims its new Claude Opus 5 delivers near-Fable 5 performance at half the token price — The Decoder; published 2026-07-24 — secondary confirmation of claude-opus-5 ID, $5/$25 pricing, 1M context, thinking on by default (disabling above high effort → 400), opus alias, Bedrock/Vertex/Foundry availability.