GrepBoard/Manuals
605 manuals ·

Fix Claude API 400 "does not support assistant message prefill"

·Tested on Claude API official docs · 2026-10·Test scope ↓·5 steps

Claude 4.6 and later models return a 400 when messages ends with an assistant turn. Remove it and set the format with structured outputs or a system prompt.

text
This model does not support assistant message prefill. The conversation must end with a user message.

The model rejected a request whose last messages entry has role: "assistant". It shows up when code that pre-fills the first characters of the reply (prefill) is sent to a Claude 4.6 or later model. It is a request-shape problem, not a key or quota problem.

[1] Confirm the response shape. The official errors page shows this body. The status is 400 and error.type is invalid_request_error.

json
{  "type": "error",  "error": {    "type": "invalid_request_error",    "message": "This model does not support assistant message prefill. The conversation must end with a user message."  }}

[2] Check the model. The docs say "Claude 4.6 and later models" and Claude Mythos Preview do not support prefilling assistant messages. If the same code worked on Claude 4.5 or earlier and broke after you switched to 4.6+, this is the cause. How older models treat prefill is not described on the errors page, so it is not covered here.

[3] Look at the last message in the request. The typical form pre-fills { to force JSON:

json
"messages": [  {"role": "user", "content": "Hi"},  {"role": "assistant", "content": "{"}]

Delete the last assistant entry and the conversation ends on a user message, so the error goes away. The guarantee that the reply starts with { goes away too, so pick a replacement in step 4.

[4] Replace prefill with another way to set the format. The docs name structured outputs (output_config.format) and system prompt instructions:

What prefill was doingReplacement (official docs)
Make the reply start as JSONStructured outputs: set output_config.format
Fix tone or layoutInstructions in the system prompt

The docs do not describe an official way to force an exact opening string. A structured-outputs request looks like this (shortened from the docs example; the supported-model list includes claude-sonnet-5-5, claude-opus-5-5 and claude-haiku-5-5):

json
{  "model": "claude-opus-5-5",  "max_tokens": 1024,  "messages": [    {"role": "user", "content": "Extract the key information from this email: ..."}  ],  "output_config": {    "format": {      "type": "json_schema",      "schema": {        "type": "object",        "properties": {          "name": {"type": "string"},          "email": {"type": "string"}        },        "required": ["name", "email"],        "additionalProperties": false      }    }  }}

Per the docs, the JSON comes back in the response's text block. Schema rules and limits are in the structured outputs docs.

[5] Resend and confirm the 400 is gone. If the output shape is off, fix the schema, not the prompt wording.

The other model-specific 400 (thinking settings) is covered in Fix Claude API 400 "thinking.type.enabled is not supported". For truncated replies see Check stop_reason to Tell If a Claude Response Was Cut Off; for JSON-only prompts see Get JSON-only output from Claude when json.loads fails.

#claude#api#prefill#troubleshooting