# prefill

Also called: prefilling, assistant prefill, response prefill, prefill phase, prefill stage, chunked prefill

Prefill means two different things. In an API request, it is a partial assistant message you put last in the conversation so the model continues from your text; Claude 4.6 and later models reject it with a 400 error. In inference serving, it is the first phase of every call, where the server processes the whole prompt in one pass before decoding output one token at a time. Prefill time largely sets time to first token.

## What does prefill mean in an API request?

In the Anthropic Messages API, if the final message in messages has the assistant role, the response continues immediately from that text. Anthropic's reference calls this prefill and gives the example of a user question followed by an assistant message reading The best answer is (, so the model's next tokens are the letter of its choice.

Developers used it to pin output formats such as JSON or YAML, skip preambles like Here is the requested summary:, steer around unnecessary refusals, resume a response that was cut off, and re-inject context into long conversations. The reply picks up mid-sentence from your text, so you fix the opening of the answer yourself.

## Which models still accept a prefilled assistant message?

Starting with Claude 4.6 models and Claude Mythos Preview, a prefilled last assistant turn returns a 400 invalid_request_error with the message "This model does not support assistant message prefill. The conversation must end with a user message." Earlier models still accept it. Assistant messages earlier in the conversation, such as replayed turns from history, are unaffected.

Anthropic's migration guide maps each old use to a replacement:

Output format: structured outputs, or a tool with an enum field for classification.Preambles: a system prompt instruction to respond without one, XML tags, or stripping the preamble in post-processing.Continuations: a user message that quotes the end of the interrupted response and asks the model to continue, or a plain retry.Context hydration: inject reminders in the user turn, expose context through tools, or use context compaction.

## What is the prefill phase of inference?

Serving engineers use the same word for the first half of every model call. During prefill the server runs your entire prompt through the model at once, building the key value cache and producing the first output token. Decode follows and generates the remaining tokens one at a time. The DistServe paper (OSDI 2024) ties each phase to its own metric: time to first token for prefill and time per output token for decode. See latency for how you measure both.

The vLLM documentation describes prefill as compute-bound and decode as memory-bound. vLLM's chunked prefill splits a long prompt into pieces and batches them with pending decode requests; vLLM schedules decode first, which its docs say improves inter-token latency. DistServe instead runs prefill and decode on different GPUs.

In your code, this meaning shows up as the wait before the first token. A longer prompt means more prefill work before anything streams back, and prompt caching lets a request that starts with a cached prefix skip most of that work.

## A prefilled assistant turn sent to a model that no longer accepts it

POST /v1/messages
{
  "model": "claude-opus-5-5",
  "max_tokens": 64,
  "messages": [
    {"role": "user",
     "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"},
    {"role": "assistant",
     "content": "The best answer is ("}
  ]
}

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

The request is Anthropic's own prefill example. A model older than Claude 4.6 would continue from "The best answer is (". Claude 4.6 and later models reject the request because the conversation ends on an assistant turn, so move the constraint into structured outputs or the prompt.

## Frequently asked

Q: Why does my request fail with "does not support assistant message prefill"?
A: Your messages array ends with an assistant message, and the model is Claude 4.6 or later, or Claude Mythos Preview. Those models require the conversation to end with a user message. Remove the trailing assistant turn and move what it did into structured outputs, a system prompt instruction or the user message.

Q: How do I continue a response that was cut off without prefill?
A: Anthropic's migration guide says to put the continuation in the user message. Quote the end of the interrupted response and ask the model to continue from where it left off. If the cut-off happened in error handling and a fresh attempt costs your users nothing, retry the request instead.

Q: Is prefill the same thing as prompt caching?
A: No. Prompt caching stores the result of the prefill phase for a prefix of your prompt, so a later request that starts with the same tokens can skip most of that compute. Assistant prefill is a message you write into the request, which is a separate idea that happens to share the name.

Q: Why does a long prompt delay the first token?
A: The server has to finish the prefill pass over the whole prompt before it can emit the first output token. DistServe measures prefill with time to first token for this reason. Shortening the prompt or reusing a cached prefix cuts that work.

## Sources

- Anthropic API reference: Messages: https://platform.claude.com/docs/en/api/messages
  a final assistant message makes the response continue from its content, this is called prefill, the Greek name for Sun example, and the 400 error on models that do not support it
- Anthropic API reference: Errors, Prefill not supported: https://platform.claude.com/docs/en/api/errors
  Claude 4.6 and later models and Claude Mythos Preview reject a prefilled last assistant message with a 400 invalid_request_error, the exact error message, and the structured outputs and system prompt alternatives
- Anthropic docs: Prompting best practices, Migrating away from prefilled responses: https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
  the common prefill uses (output format, preambles, refusals, continuations, context hydration), the replacement for each, and that assistant messages elsewhere in the conversation are unaffected
- DistServe: Disaggregating Prefill and Decoding for Goodput-optimized LLM Serving (OSDI 2024): https://arxiv.org/abs/2401.09670
  the prefill and decoding phases, TTFT as the prefill metric and TPOT as the decode metric, interference when the two are colocated, and assigning them to different GPUs
- vLLM docs: Optimization and tuning, Chunked prefill: https://docs.vllm.ai/en/latest/configuration/optimization.html
  prefill as compute-bound and decode as memory-bound, chunked prefill batching prompt chunks with decode requests, and its effect on inter-token latency

## Related terms

- latency: https://ai.developertools.io/latency/index.md
- prompt caching: https://ai.developertools.io/prompt-caching/index.md
- structured outputs: https://ai.developertools.io/structured-outputs/index.md
- prompt: https://ai.developertools.io/prompt/index.md
- context compaction: https://ai.developertools.io/context-compaction/index.md
- streaming: https://ai.developertools.io/streaming/index.md

Canonical page: https://ai.developertools.io/prefill/
Edited by Derek Wonk. Last updated 2026-10-26.
