Claude Sonnet 4.5 1M Context Is Being Deprecated on April 30
On April 30, 2026, the 1M token context window beta feature for Claude Sonnet 4.5 and the older Claude Sonnet 4 will be retired. This feature was made available through the context-1m-2025-08-07 beta header that Anthropic introduced in August 2025.
The good news: Claude Sonnet 4.6 and Claude Opus 4.6 now support 1M token context windows as a generally available (GA) standard feature — no beta header required. This guide walks you through exactly what changes, why it matters, and how to migrate your code before the deadline.
What Is Being Deprecated
The beta feature being removed applies to two models:
claude-sonnet-4-5(Claude Sonnet 4.5)claude-sonnet-4-20250514(Claude Sonnet 4)
With these models, developers could include the anthropic-beta: context-1m-2025-08-07 header in API requests to use up to 1 million tokens of context.
After April 30, 2026, this beta header will have no effect. Any request using these models that exceeds the standard 200k token context window will return an error.
# ❌ This header will no longer work after April 30
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=4096,
messages=[{"role": "user", "content": very_long_content}],
extra_headers={
# This header becomes a no-op on April 30, 2026
"anthropic-beta": "context-1m-2025-08-07"
}
)Where to Migrate
Anthropic recommends migrating to either Claude Sonnet 4.6 or Claude Opus 4.6. Both models support 1M token context windows as a standard feature — no beta header needed.
- Claude Sonnet 4.6 (
claude-sonnet-4-6): The best balance of cost and capability. Ideal for most use cases involving large documents, long conversation histories, or extensive codebases. - Claude Opus 4.6 (
claude-opus-4-6): Maximum capability for complex reasoning, multi-step tasks, and high-precision analysis. Higher cost than Sonnet.
Neither model requires the beta header, and there is no additional cost for using the 1M context window — standard pricing applies.
Step-by-Step Migration
The migration is straightforward. In most cases, you only need to update the model ID and remove the beta header.
Step 1: Update Your Model ID
import anthropic
client = anthropic.Anthropic()
# ✅ After migration: use claude-sonnet-4-6
response = client.messages.create(
model="claude-sonnet-4-6", # ← Change this
max_tokens=8096,
messages=[
{
"role": "user",
"content": very_long_content # Up to 1M tokens, no header needed
}
]
# ← No beta header required
)
print(response.content[0].text)Step 2: Remove the Beta Header
If you were explicitly passing the context-1m-2025-08-07 header via extra_headers or extra_body, simply delete it:
# Before (needs to be removed)
extra_headers={
"anthropic-beta": "context-1m-2025-08-07"
}
# After (no extra headers needed)
# claude-sonnet-4-6 handles 1M context by defaultStep 3: TypeScript / Node.js Migration
The process is identical in TypeScript:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
// ✅ After migration
const response = await client.messages.create({
model: 'claude-sonnet-4-6', // ← Update model ID
max_tokens: 8096,
messages: [
{
role: 'user',
content: veryLongContent, // Up to 1M tokens supported
},
],
// ← No beta header needed
});
console.log(response.content[0].text);Step 4: Verify Your Migration
After updating, run a quick test with a long-context request to confirm everything works:
import anthropic
client = anthropic.Anthropic()
# Confirm token usage in the response
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Please summarize the following document..."
}
]
)
# Check usage details
print(f"Input tokens: {response.usage.input_tokens}")
print(f"Output tokens: {response.usage.output_tokens}")
# Expected output:
# Input tokens: 15
# Output tokens: 42What Changes Between Sonnet 4.5 and Sonnet 4.6
Claude Sonnet 4.6 is an upgrade in several meaningful ways:
- Improved performance: Better accuracy on coding, math, and instruction-following benchmarks
- 1M context window is now GA: No more beta limitations — it's a first-class feature
- Extended Thinking support: Available when you need deeper reasoning for complex tasks
- API compatibility: Nearly identical interface to Sonnet 4.5, making migration low-effort
You typically won't need to rewrite your prompts, but it's worth testing your outputs after migration and fine-tuning your system prompt if needed.
Real-World Use Cases That Require Action
To help you quickly assess your exposure, here are the most common scenarios where the 1M context beta is in use.
Large Document Processing
If your application uploads entire PDFs, legal contracts, research papers, or code repositories in a single API call, you're almost certainly using extended context. Any prompt over 200k tokens will break after April 30 unless you migrate.
# Example: processing a large PDF as text
with open("annual_report.txt", "r") as f:
document_text = f.read()
# If this document is > ~150,000 words, you need the 1M context window
response = client.messages.create(
model="claude-sonnet-4-6", # ← Supports 1M natively
max_tokens=4096,
messages=[
{
"role": "user",
"content": f"Summarize the key financial highlights from this report:\n\n{document_text}"
}
]
)Long Conversation Histories
Chatbots or assistants that maintain extensive conversation history may accumulate hundreds of thousands of tokens over time. If you're passing the full history on each turn, verify the cumulative token count.
# Monitor total context size before sending
def count_message_tokens(messages: list[dict]) -> int:
"""Rough estimate: 1 token ≈ 4 characters"""
total_chars = sum(len(m.get("content", "")) for m in messages)
return total_chars // 4
conversation_history = [...] # Your accumulated messages
estimated_tokens = count_message_tokens(conversation_history)
print(f"Estimated input tokens: {estimated_tokens:,}")
# If > 200,000, ensure you're on claude-sonnet-4-6
if estimated_tokens > 200_000:
model = "claude-sonnet-4-6"
else:
model = "claude-sonnet-4-5" # Fine for smaller contextsCodebase Analysis
Developers who send entire repositories for analysis, refactoring suggestions, or documentation generation often exceed 200k tokens with larger codebases. This is one of the most common 1M context use cases.
import os
def load_codebase(root_dir: str) -> str:
"""Concatenate all Python files in a directory."""
code_parts = []
for dirpath, _, filenames in os.walk(root_dir):
for fname in filenames:
if fname.endswith(".py"):
fpath = os.path.join(dirpath, fname)
with open(fpath, "r", encoding="utf-8", errors="ignore") as f:
code_parts.append(f"# File: {fpath}\n{f.read()}")
return "\n\n".join(code_parts)
codebase_content = load_codebase("./my_project")
response = client.messages.create(
model="claude-sonnet-4-6", # Required for large codebases
max_tokens=8096,
messages=[
{
"role": "user",
"content": f"Review this codebase for security vulnerabilities:\n\n{codebase_content}"
}
]
)Common Errors and Fixes
Here are the errors you're most likely to encounter during or after migration, along with how to fix them.
ContextWindowExceededError
anthropic.BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long"}}
Cause: You sent a request to claude-sonnet-4-5 with a context larger than 200k tokens after the deprecation date.
Fix: Update the model ID to claude-sonnet-4-6.
Beta Header Has No Effect
After April 30, including context-1m-2025-08-07 in the headers for Sonnet 4.5 or Sonnet 4 will not enable 1M context. The only fix is migrating to a model that supports it natively.
max_tokens Limit Has Changed
Claude Sonnet 4.6 supports up to 64k output tokens per request (Sonnet 4.5 was capped at 8,192). If your code hardcodes this limit, you may want to update it to take advantage of longer outputs.
For teams running high-volume batch workloads on top of 1M context, Claude API Messages Batches Implementation Guide covers how to reduce costs by up to 50% through asynchronous batch processing.
Looking back
The April 30 deadline is fast approaching. If you're using Claude Sonnet 4.5 or Sonnet 4 with the 1M context beta, here's your action checklist:
- Find any code that passes the
context-1m-2025-08-07beta header - Update the model ID to
claude-sonnet-4-6 - Remove the beta header (it's no longer needed)
- Test your application with real-world long-context inputs
Sonnet 4.6 delivers better performance at the same price point, making this an upgrade worth doing proactively rather than waiting for the deadline. If you're building RAG pipelines or document processing systems that depend on large context windows, Building a RAG System with Claude API covers the full implementation pattern with vector search and prompt caching.