Claude Sonnet 4 API

Claude Sonnet 4 is Anthropic’s balanced hybrid reasoning model, built for strong coding, reasoning, instruction following, and tool use.
Context
1M tokens
Input
$3.9 / 1M
Output
$19.5 / 1M
Released
May 22, 2025

How to use Claude Sonnet 4 API

Install any OpenAI-compatible SDK, point it at api.aimlapi.com/v1, and set the model to anthropic/claude-sonnet-4.
import requests

r = requests.post(
    "https://api.aimlapi.com/v1/chat/completions",
    headers={"Authorization": "Bearer " + AIMLAPI_KEY},
    json={
      "model": "anthropic/claude-sonnet-4",
      "messages": [
        {
          "role": "user",
          "content": "Hello!"
        }
      ]
    },
)
print(r.json())
const r = await fetch("https://api.aimlapi.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.AIMLAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "anthropic/claude-sonnet-4",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }),
});
console.log(await r.json());
curl -X POST https://api.aimlapi.com/v1/chat/completions \
  -H "Authorization: Bearer $AIMLAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"anthropic/claude-sonnet-4","messages":[{"role":"user","content":"Hello!"}]}'

OpenAI-compatible — swap the base URL and it works with your existing SDK.

Claude Sonnet 4 API Pricing

TypePrice
Input
$3.9 / 1M
Output
$19.5 / 1M
Cached input
$0.39 / 1M

Claude Sonnet 4 documents cache write tokens as billed at 1.25× the base input price for 5-minute caching and 2× for 1-hour caching.

Claude Sonnet 4 vs other models

ModelInputOutputContextBest for
$3.9 / 1M
$19.5 / 1M
1M tokens
Agentic workflows and structured output
$6.5 / 1M
$32.5 / 1M
1M tokens
Complex agentic coding and enterprise workflows
$6.5 / 1M
$32.5 / 1M
1M tokens
Chat + assistants
$13 / 1M
$65 / 1M
1M tokens
Chat + assistants

Start building with Claude Sonnet 4

Get API Key
1000+ models, one API.