Fix Claude Opus Prefill Not Supported (2026)
Claude Opus 4.6 does not support prefilling assistant messages. If you send a request with a prefilled last assistant message, the API returns a 400 error. This guide shows the alternatives.
The Error
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Prefilling assistant messages is not supported for this model."
}
}
Quick Fix
- Remove the prefilled assistant message from your request.
- Use
output_config.formatwithjson_schemafor structured JSON output. - Use system prompt instructions to control the output format.
What Causes This
Prefilling is a technique where you add a partial assistant message at the end of the messages array to steer Claude’s response format. For example, starting the response with { to force JSON output.
Claude Opus 4.6 (and Claude Mythos Preview) do not support this technique. The API rejects the request with a 400 invalid_request_error.
Full Solution
Remove the Prefilled Message
import anthropic
client = anthropic.Anthropic()
# WRONG: Prefilled assistant message
messages = [
{"role": "user", "content": "List 3 colors as JSON"},
{"role": "assistant", "content": "{"} # Error on Opus 4.6!
]
# CORRECT: No prefill
messages = [
{"role": "user", "content": "List 3 colors as JSON"}
]
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1024,
messages=messages
)
Use Structured Outputs (Best Alternative)
The output_config.format parameter guarantees valid JSON output without prefilling:
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "List 3 colors with their hex codes"}],
output_config={
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"colors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"hex": {"type": "string"}
},
"required": ["name", "hex"],
"additionalProperties": False
}
}
},
"required": ["colors"],
"additionalProperties": False
}
}
}
)
import json
data = json.loads(response.content[0].text)
print(data)
TypeScript with Structured Outputs
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "List 3 colors with hex codes" }],
output_config: {
format: {
type: "json_schema",
schema: {
type: "object",
properties: {
colors: {
type: "array",
items: {
type: "object",
properties: {
name: { type: "string" },
hex: { type: "string" }
},
required: ["name", "hex"],
additionalProperties: false
}
}
},
required: ["colors"],
additionalProperties: false
}
}
}
});
const data = JSON.parse(
response.content[0].type === "text" ? response.content[0].text : "{}"
);
console.log(data);
Use System Prompts for Format Control
For simpler format requirements, system prompts work well without prefilling:
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1024,
system="Always respond with valid JSON. No markdown, no explanations, just the JSON object.",
messages=[{"role": "user", "content": "List 3 colors with hex codes"}]
)
Model Compatibility
Prefilling works on these models but NOT on Opus 4.6:
| Model | Prefill Supported |
|---|---|
| Claude Opus 4.6 | No |
| Claude Mythos Preview | No |
| Claude Sonnet 4.6 | Yes |
| Claude Sonnet 4.5 | Yes |
| Claude Haiku 4.5 | Yes |
| Claude Opus 4.5 | Yes |
If your code depends on prefilling and you need to use Opus 4.6, switch to structured outputs.
Prevention
- Use structured outputs by default:
output_config.formatwithjson_schemais more reliable than prefilling on ALL models and is the only option on Opus 4.6. - Check model compatibility: Before using prefilling, verify the model supports it.
- Write model-agnostic code: Use structured outputs or system prompts so your code works across all Claude models without modification.
Which model? → Take the 5-question quiz in our Model Selector.
Related Guides
Try it: Estimate your monthly spend with our Cost Calculator.
- Claude API Error 400 invalid_request_error Fix – the error type returned when prefill is used on unsupported models.
- Claude Extended Thinking API Guide – Opus 4.6 capabilities beyond prefilling.
- Claude API Tool Use Function Calling Deep Dive Guide – full parameter reference including output_config.
- Claude Python SDK Getting Started – basic SDK setup.
- Claude TypeScript SDK Installation Guide – TypeScript SDK setup for structured outputs.
See Also
Common Questions
What causes fix claude opus prefill not supported issues?
Common causes include misconfigured settings, outdated dependencies, and environment conflicts. Check your project configuration and ensure all dependencies are up to date.
How do I prevent this error from recurring?
Set up automated checks in your development workflow. Use Claude Code’s built-in validation tools to catch configuration issues before they reach production.
Does this fix work on all operating systems?
The core fix applies to macOS, Linux, and Windows. Some path-related adjustments may be needed depending on your OS. Check the platform-specific notes in the guide above.