MessagesRequest - TypeScript SDK
MessagesRequest - TypeScript SDK
MessagesRequest type definition
MessagesRequest - TypeScript SDK
The TypeScript SDK and docs are currently in beta. Report issues on GitHub.
Request schema for Anthropic Messages API endpoint
1 import { MessagesRequest } from "@openrouter/sdk/models"; 2 3 let value: MessagesRequest = { 4 messages: [ 5 { 6 content: "Hello, how are you?", 7 role: "user", 8 }, 9 ], 10 model: "anthropic/claude-4.5-sonnet-20250929", 11 };
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
cacheControl | models.AnthropicCacheControlDirective | ➖ | 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. | {"type": "ephemeral"} |
contextManagement | models.ContextManagement | ➖ | N/A | |
maxTokens | number | ➖ | N/A | |
messages | models.MessagesMessageParam[] | ✔️ | N/A | |
metadata | models.Metadata | ➖ | N/A | |
model | string | ✔️ | N/A | |
models | string[] | ➖ | N/A | |
outputConfig | models.MessagesOutputConfig | ➖ | Configuration for controlling output behavior. Supports the effort parameter and structured output format. | {"effort": "medium"} |
plugins | models.MessagesRequestPlugin[] | ➖ | Plugins you want to enable for this request, including their settings. | |
provider | models.ProviderPreferences | ➖ | When multiple model providers are available, optionally indicate your routing preference. | {"allow_fallbacks": true} |
serviceTier | string | ➖ | N/A | |
sessionId | string | ➖ | 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 | ➖ | N/A | fast |
stopSequences | string[] | ➖ | N/A | |
stopServerToolsWhen | models.StopServerToolsWhenCondition[] | ➖ | Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls. | [{"step_count": 5,"type": "step_count_is"},{"max_cost_in_dollars": 0.5,"type": "max_cost"}] |
stream | boolean | ➖ | N/A | |
system | models.System | ➖ | N/A | |
temperature | number | ➖ | N/A | |
thinking | models.Thinking | ➖ | N/A | |
toolChoice | models.ToolChoice | ➖ | N/A | |
tools | models.MessagesRequestToolUnion[] | ➖ | N/A | |
topK | number | ➖ | N/A | |
topP | number | ➖ | N/A | |
trace | models.TraceConfig | ➖ | 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. | {"trace_id": "trace-abc123","trace_name": "my-app-trace"} |
user | string | ➖ | 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. |