# Claude Sonnet 4

Claude Sonnet 4 delivers strong coding benchmark performance at Sonnet cost, with a context window of 1M tokens that makes entire large codebases processable in a single request.

- **Model ID:** `anthropic/claude-sonnet-4`
- **Type:** chat
- **Providers:** bedrock, vertexAnthropic
- **Context window:** 1,000,000
- **Maximum output tokens:** 8,192
- **Pricing:** $3.0/1M input tokens, $15.0/1M output tokens
- **Canonical page:** https://vercel.com/ai-gateway/models/claude-sonnet-4

## Supported parameters

Detailed capability metadata has not been reported for this model.

## Example

```ts
import { streamText } from 'ai'

const result = streamText({
  model: 'anthropic/claude-sonnet-4',
  prompt: 'Why is the sky blue?'
})
```

## About

Claude Sonnet 4 launched on May 22, 2025 alongside Claude Opus 4, positioned as a significant upgrade over Claude Sonnet 3.7 with stronger coding, reasoning, and instruction-following precision. It scored 72.7% on SWE-bench Verified, matching or exceeding Opus 4's 72.5% on the coding benchmark central to software engineering teams. GitHub announced it would power the coding agent in GitHub Copilot. Manus highlighted improvements in complex instruction following and aesthetic outputs. iGent reported navigation errors dropping from 20% to near zero.

The context window of 1M tokens lets you process full codebases of approximately 75,000 lines of code or equivalently large document sets in a single request. Enable this by adding the `anthropic-beta: context-1m-2025-08-07` request header and routing through the Anthropic provider specifically.

Claude Sonnet 4 is a hybrid model offering both near-instant standard responses and extended thinking for deeper reasoning. Extended thinking with tool use is also available in beta. Both Claude Sonnet 4 and Opus 4 can use tools in parallel. The Claude 4 generation introduced one-hour prompt caching as an API capability. Steerability was a highlighted design improvement: the model responds more precisely to instructions, reducing the gap between what you ask and what you get.

The 65% reduction in shortcut-taking behavior compared to Sonnet 3.7 also applies to Claude Sonnet 4, improving reliability in production agentic deployments.

## What to consider

The context window of 1M tokens increases per-request token volumes. Monitor cost per request when processing full codebases or large document collections, since a single request can consume tokens equivalent to many standard calls.

## When to use

### Best For

- **Full-codebase analysis:** The context window of 1M tokens lets you pass an entire large repository in a single request
- **Agentic coding at scale:** SWE-bench 72.7% and GitHub Copilot's selection as its coding agent model speak directly to this use case
- **Multi-file refactoring:** Architectural reasoning where the model needs to hold the whole picture simultaneously
- **Instruction-precise applications:** Improved steerability follows complex, nuanced instructions more accurately
- **Agent workflows at Sonnet pricing:** Lower per-token cost than Opus 4 makes Claude Sonnet 4 the right choice when benchmark results are comparable

### Consider Alternatives When

- You need the context window of 1M tokens but don't want to pin to the Anthropic provider specifically. Check whether later model versions support that context size through all providers
- The task requires Claude Sonnet 4.5's improvements: OSWorld computer use performance, 30+ hour agentic task duration, and domain-specific reasoning advances
- Haiku 4.5 covers your capability requirements at lower cost
- You need Opus-level reasoning depth on problems where Sonnet benchmarks don't capture the full difficulty

## Best for

- **Full-codebase analysis:** The context window of 1M tokens lets you pass an entire large repository in a single request
- **Agentic coding at scale:** SWE-bench 72.7% and GitHub Copilot's selection as its coding agent model speak directly to this use case
- **Multi-file refactoring:** Architectural reasoning where the model needs to hold the whole picture simultaneously
- **Instruction-precise applications:** Improved steerability follows complex, nuanced instructions more accurately
- **Agent workflows at Sonnet pricing:** Lower per-token cost than Opus 4 makes Claude Sonnet 4 the right choice when benchmark results are comparable

## Consider alternatives

- **Provider flexibility:** Check whether later model versions support 1M tokens through all providers when you don't want to pin to Anthropic
- **Sonnet 4.5 improvements:** OSWorld computer use performance, 30+ hour agentic task duration, and domain-specific reasoning advances
- **Haiku 4.5 capability match:** Lower-cost option when Haiku 4.5 covers the capability requirements
- **Opus-level reasoning depth:** Sonnet benchmarks don't capture the full difficulty of some problems

## Frequently asked questions

### How do I enable the context window of 1M tokens for Claude Sonnet 4 on AI Gateway?

Add the `anthropic-beta: context-1m-2025-08-07` header to your request. Under `providerOptions.gateway`, set `only` to `['anthropic']` so the request routes through the Anthropic provider, which supports the feature.

### What does the context window of 1M tokens enable in practice?

The context window of 1M tokens lets you process entire codebases, long documents, or extended conversation histories in a single request. This is particularly useful for code review across multiple files, document analysis, and agentic workflows that accumulate context over many steps.

### How did Claude Sonnet 4 perform on SWE-bench Verified?

72.7% on SWE-bench Verified, matching or exceeding Claude Opus 4's 72.5% on that specific benchmark.

### What is enhanced steerability in Claude Sonnet 4?

Sonnet 4 responds more precisely to instructions, reducing misinterpretation of complex or nuanced prompts. Anthropic highlighted steerability as an explicit design improvement for applications where exact specification of behavior matters.

### Does Claude Sonnet 4 support extended thinking?

Yes. Sonnet 4 is a hybrid model that supports both near-instant responses and extended thinking. Extended thinking with tool use, where the model alternates between reasoning and calling tools, is also available in beta.

### What is 1-hour prompt caching and does Sonnet 4 support it?

Yes. The Claude 4 launch introduced one-hour prompt caching as a new API capability, compared to shorter-lived caching in previous generations. This is particularly useful for codebases or large system prompts that appear in many requests.

### Why would I use Sonnet 4 instead of Opus 4 given the SWE-bench scores are similar?

Claude Sonnet 4 is priced at the Sonnet tier, while Opus 4 is priced at the Opus tier. When benchmark results are comparable, the cost gap determines the choice at scale. Check the pricing panel on this page for current rates.

## Links

- [Model page](https://vercel.com/ai-gateway/models/claude-sonnet-4)
- [AI Gateway documentation](https://vercel.com/docs/ai-gateway)
- [Provider model documentation](https://aws.amazon.com/bedrock/claude/)
- [Provider pricing](https://aws.amazon.com/bedrock/pricing/)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
