> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/api-reference/completion-1/messages.md).

# Messages

Data models for the Anthropic Messages API

The Messages API types are Pydantic models used by `any_llm.api.messages()` and `any_llm.api.amessages()`.

### Primary Types

#### `MessageResponse`

Full response from the Messages API.

**Import:** `from any_llm.types.messages import MessageResponse`

| Field                | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Description                                                 |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| `request_id`         | `str \| None`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Provider request identifier, when exposed by the transport. |
| `container`          | `BetaContainer \| None`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                             |
| `content`            | `list[ThinkingBlock \| TextBlock \| ThinkingBlock \| RedactedThinkingBlock \| ToolUseBlock \| ServerToolUseBlock \| WebSearchToolResultBlock \| WebFetchToolResultBlock \| CodeExecutionToolResultBlock \| BashCodeExecutionToolResultBlock \| TextEditorCodeExecutionToolResultBlock \| ToolSearchToolResultBlock \| ContainerUploadBlock \| BetaTextBlock \| BetaThinkingBlock \| BetaRedactedThinkingBlock \| BetaToolUseBlock \| BetaServerToolUseBlock \| BetaWebSearchToolResultBlock \| BetaWebFetchToolResultBlock \| BetaAdvisorToolResultBlock \| BetaCodeExecutionToolResultBlock \| BetaBashCodeExecutionToolResultBlock \| BetaTextEditorCodeExecutionToolResultBlock \| BetaToolSearchToolResultBlock \| BetaMCPToolUseBlock \| BetaMCPToolResultBlock \| BetaContainerUploadBlock \| BetaCompactionBlock \| BetaFallbackBlock]` |                                                             |
| `stop_reason`        | `Literal['end_turn', 'max_tokens', 'stop_sequence', 'tool_use', 'pause_turn', 'compaction', 'refusal', 'model_context_window_exceeded'] \| None`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                             |
| `usage`              | `MessageUsage`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                             |
| `context_management` | `BetaContextManagementResponse \| None`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                             |
| `diagnostics`        | `BetaDiagnostics \| None`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                                                             |

#### `MessageContentBlock`

Content block in a Messages API response.

**Import:** `from any_llm.types.messages import MessageContentBlock`

#### `MessageUsage`

Token usage information for Messages API.

**Import:** `from any_llm.types.messages import MessageUsage`

| Field        | Type                                                                                                                                                                                                                           | Description |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- |
| `iterations` | `list[Annotated[MessageIterationUsage \| BetaCompactionIterationUsage \| BetaAdvisorMessageIterationUsage \| BetaFallbackMessageIterationUsage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] \| None` |             |
| `speed`      | `Literal['standard', 'fast'] \| None`                                                                                                                                                                                          |             |

#### `MessageStreamEvent`

Union of stream event types. Each one subclasses the matching Anthropic SDK `Raw*` event and widens it so beta responses (context management, compaction) round-trip without loss:

* `MessageStartEvent`: `type: 'message_start'`, `message: MessageResponse`
* `MessageDeltaEvent`: `type: 'message_delta'`, `delta: MessageDelta`, `usage: MessageDeltaUsage`, `context_management: BetaContextManagementResponse | None`
* `MessageStopEvent`: `type: 'message_stop'`, `message: MessageResponse | None`
* `ContentBlockStartEvent`: `type: 'content_block_start'`, `index: int`, `content_block: MessageContentBlock`
* `ContentBlockDeltaEvent`: `type: 'content_block_delta'`, `index: int`, `delta: RawContentBlockDelta | CompactionDelta`
* `ContentBlockStopEvent`: `type: 'content_block_stop'`, `index: int`, `content_block: MessageContentBlock | None`

`message` on `MessageStopEvent` and `content_block` on `ContentBlockStopEvent` are populated only by providers with a native Anthropic Messages API; the Chat Completions bridge leaves them unset.

**Import:** `from any_llm.types.messages import MessageStreamEvent`

### Internal Types

#### `MessagesParams`

Normalized parameters for the Anthropic Messages API, used internally to pass structured parameters from the public API to provider implementations.

**Import:** `from any_llm.types.messages import MessagesParams`

| Field                | Type                                  | Description                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `model`              | `str`                                 | Model identifier                                                                                                                                                                                                                                                                                                                                                                                                         |
| `messages`           | `list[dict[str, Any]]`                | List of messages for the conversation                                                                                                                                                                                                                                                                                                                                                                                    |
| `max_tokens`         | `int`                                 | Maximum number of tokens to generate (required by Anthropic API)                                                                                                                                                                                                                                                                                                                                                         |
| `system`             | `str \| list[dict[str, Any]] \| None` | System prompt (string or list of content blocks with optional cache\_control)                                                                                                                                                                                                                                                                                                                                            |
| `temperature`        | `float \| None`                       | Controls randomness in the response (0.0 to 1.0); Anthropic deprecates this for current Claude models.                                                                                                                                                                                                                                                                                                                   |
| `top_p`              | `float \| None`                       | Controls diversity via nucleus sampling; Anthropic deprecates this for current Claude models.                                                                                                                                                                                                                                                                                                                            |
| `top_k`              | `int \| None`                         | Only sample from the top K options for each subsequent token; Anthropic deprecates this for current Claude models.                                                                                                                                                                                                                                                                                                       |
| `stream`             | `bool \| None`                        | Whether to stream the response                                                                                                                                                                                                                                                                                                                                                                                           |
| `stop_sequences`     | `list[str] \| None`                   | Custom text sequences that will cause the model to stop generating                                                                                                                                                                                                                                                                                                                                                       |
| `tools`              | `list[dict[str, Any]] \| None`        | List of tools in Anthropic format ({name, description, input\_schema})                                                                                                                                                                                                                                                                                                                                                   |
| `tool_choice`        | `dict[str, Any] \| None`              | Controls which tool the model uses                                                                                                                                                                                                                                                                                                                                                                                       |
| `metadata`           | `dict[str, Any] \| None`              | Request metadata                                                                                                                                                                                                                                                                                                                                                                                                         |
| `thinking`           | `dict[str, Any] \| None`              | Thinking/reasoning configuration                                                                                                                                                                                                                                                                                                                                                                                         |
| `cache_control`      | `dict[str, Any] \| None`              | Cache control configuration for prompt caching                                                                                                                                                                                                                                                                                                                                                                           |
| `prompt_cache_key`   | `str \| None`                         | A key to use when reading from or writing to a provider's prompt cache.                                                                                                                                                                                                                                                                                                                                                  |
| `service_tier`       | `str \| None`                         | The service tier to use for this request.                                                                                                                                                                                                                                                                                                                                                                                |
| `container`          | `str \| dict[str, Any] \| None`       | Container identifier, or an object with optional `id` and `skills`. A string reuses an existing container. An object selects Skills for a fresh container (`skills` without `id`) or reuses a container while attaching Skills (`id` plus `skills`). Each skill requires `type` (`anthropic` or `custom`) and `skill_id`; `version` is optional. This matches Anthropic SDK `MessageCreateParamsContainerParam` (\`\`str |
| `context_management` | `dict[str, Any] \| None`              | Anthropic context management configuration                                                                                                                                                                                                                                                                                                                                                                               |
| `betas`              | `list[str] \| None`                   | Anthropic beta identifiers                                                                                                                                                                                                                                                                                                                                                                                               |
| `output_format`      | `type \| dict[str, Any] \| None`      |                                                                                                                                                                                                                                                                                                                                                                                                                          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mozilla.ai/api-reference/completion-1/messages.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
