> ## Documentation Index
> Fetch the complete documentation index at: https://openrouter-d02e98a0-dev-127-conversation-state-store.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MessagesRequest

Request schema for Anthropic Messages API endpoint

## Example Usage

```typescript theme={null}
import { MessagesRequest } from "@openrouter/sdk/models";

let value: MessagesRequest = {
  messages: [
    {
      content: "Hello, how are you?",
      role: "user",
    },
  ],
  model: "anthropic/claude-4.5-sonnet-20250929",
};
```

## Fields

| Field                 | Type                                                                                  | Required             | Description                                                                                                                                                                                                                                                                                                                                                                                                          | Example                                                                                                                                                     |
| --------------------- | ------------------------------------------------------------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cacheControl`        | [models.AnthropicCacheControlDirective](../models/anthropiccachecontroldirective.mdx) | :heavy\_minus\_sign: | Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models.                                                                                                                                                                                                          | \{<br />"type": "ephemeral"<br />}                                                                                                                          |
| `contextManagement`   | [models.ContextManagement](../models/contextmanagement.mdx)                           | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `fallbacks`           | [models.MessagesFallbackParam](../models/messagesfallbackparam.mdx)\[]                | :heavy\_minus\_sign: | Fallback models to try if the primary model fails or refuses, in order. Handled by OpenRouter multi-model routing rather than Anthropic server-side fallbacks; cannot be combined with `models`. Each entry accepts only `model`. Maximum of 3 entries.                                                                                                                                                              | \[<br />\{<br />"model": "claude-opus-4-8"<br />}<br />]                                                                                                    |
| `maxTokens`           | *number*                                                                              | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `messages`            | [models.MessagesMessageParam](../models/messagesmessageparam.mdx)\[]                  | :heavy\_check\_mark: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `metadata`            | [models.MessagesRequestMetadata](../models/messagesrequestmetadata.mdx)               | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `model`               | *string*                                                                              | :heavy\_check\_mark: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `models`              | *string*\[]                                                                           | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `outputConfig`        | [models.MessagesOutputConfig](../models/messagesoutputconfig.mdx)                     | :heavy\_minus\_sign: | Configuration for controlling output behavior. Supports the effort parameter and structured output format.                                                                                                                                                                                                                                                                                                           | \{<br />"effort": "medium"<br />}                                                                                                                           |
| `plugins`             | *models.MessagesRequestPlugin*\[]                                                     | :heavy\_minus\_sign: | Plugins you want to enable for this request, including their settings.                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                             |
| `provider`            | [models.ProviderPreferences](../models/providerpreferences.mdx)                       | :heavy\_minus\_sign: | When multiple model providers are available, optionally indicate your routing preference.                                                                                                                                                                                                                                                                                                                            | \{<br />"allow\_fallbacks": true<br />}                                                                                                                     |
| `serviceTier`         | *string*                                                                              | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `sessionId`           | *string*                                                                              | :heavy\_minus\_sign: | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). When provided, OpenRouter uses it as the sticky routing key, routing all requests in the session to the same provider to maximize prompt cache hits. Also used for observability grouping. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. |                                                                                                                                                             |
| `speed`               | [models.Speed](../models/speed.mdx)                                                   | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  | fast                                                                                                                                                        |
| `stopSequences`       | *string*\[]                                                                           | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `stopServerToolsWhen` | *models.StopServerToolsWhenCondition*\[]                                              | :heavy\_minus\_sign: | Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides `max_tool_calls`.                                                                                                                                                                                                                                                                           | \[<br />\{<br />"step\_count": 5,<br />"type": "step\_count\_is"<br />},<br />\{<br />"max\_cost\_in\_dollars": 0.5,<br />"type": "max\_cost"<br />}<br />] |
| `stream`              | *boolean*                                                                             | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `system`              | *models.System*                                                                       | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `temperature`         | *number*                                                                              | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `thinking`            | *models.Thinking*                                                                     | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `toolChoice`          | *models.ToolChoice*                                                                   | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `tools`               | *models.MessagesRequestToolUnion*\[]                                                  | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `topK`                | *number*                                                                              | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `topP`                | *number*                                                                              | :heavy\_minus\_sign: | N/A                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                             |
| `trace`               | [models.TraceConfig](../models/traceconfig.mdx)                                       | :heavy\_minus\_sign: | Metadata for observability and tracing. Known keys (trace\_id, trace\_name, span\_name, generation\_name, parent\_span\_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.                                                                                                                                                                       | \{<br />"trace\_id": "trace-abc123",<br />"trace\_name": "my-app-trace"<br />}                                                                              |
| `user`                | *string*                                                                              | :heavy\_minus\_sign: | A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 256 characters.                                                                                                                 |                                                                                                                                                             |
