๐ŸŒ

Claude Sonnet

Claude Sonnet is Anthropic's mid-tier, balanced large language model line โ€” the default choice for most Claude API usage and the model behind Claude Code. It's currently the #2 most-used AI model line at roughly 42.8% usage share, second only to OpenAI's GPT family. Sonnet is tuned to be strong at coding and long-context reasoning while staying faster and cheaper than Anthropic's largest Opus tier, making it the practical everyday pick for developers.

Quick facts
Made by: Anthropic
Access: Proprietary โ€” paid usage-based API (console.anthropic.com), also available via Amazon Bedrock and Google Vertex AI, plus a free tier inside Claude.ai
Context window: 200K tokens standard (1M-token context available in beta on newer Sonnet versions โ€” check the exact model's docs)
Strengths: Coding and agentic tool use, long-context document analysis, careful instruction-following, strong cost/performance balance
Primary use case: Software development assistance (Claude Code), agentic workflows, and general-purpose reasoning at production scale
Jump to: ExampleGetting startedBest for

Example

The Claude API is called through Anthropic's official Python SDK. This sends a prompt to claude-sonnet-4-5 using the Messages API and prints the reply.

import anthropic

client = anthropic.Anthropic(api_key="YOUR_API_KEY")

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain what a REST API is in two sentences."}
    ]
)

print(message.content[0].text)

Getting started

Create an Anthropic Console account, generate an API key, install the SDK, then make your first call.

# 1. Create an account and API key at console.anthropic.com

# 2. install the SDK
pip install anthropic

# 3. set your key as an environment variable
export ANTHROPIC_API_KEY="your-key-here"
Best for: Coding-heavy projects and agentic tools โ€” Sonnet is the model behind Claude Code and most autonomous coding agents, and its long context window makes it well suited to reasoning over large codebases or lengthy documents.