MessagesRequest - TypeScript SDK

MessagesRequest type definition

The TypeScript SDK and docs are currently in beta. Report issues on GitHub.

Request schema for Anthropic Messages API endpoint

Example Usage

1import { MessagesRequest } from "@openrouter/sdk/models";
2
3let 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};

Fields

FieldTypeRequiredDescriptionExample
cacheControlmodels.AnthropicCacheControlDirectiveEnable 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"}
contextManagementmodels.ContextManagementN/A
maxTokensnumberN/A
messagesmodels.MessagesMessageParam[]✔️N/A
metadatamodels.MetadataN/A
modelstring✔️N/A
modelsstring[]N/A
outputConfigmodels.MessagesOutputConfigConfiguration for controlling output behavior. Supports the effort parameter and structured output format.{"effort": "medium"}
pluginsmodels.MessagesRequestPlugin[]Plugins you want to enable for this request, including their settings.
providermodels.ProviderPreferencesWhen multiple model providers are available, optionally indicate your routing preference.{"allow_fallbacks": true}
serviceTierstringN/A
sessionIdstringA 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.
speedmodels.SpeedN/Afast
stopSequencesstring[]N/A
stopServerToolsWhenmodels.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"}
]
streambooleanN/A
systemmodels.SystemN/A
temperaturenumberN/A
thinkingmodels.ThinkingN/A
toolChoicemodels.ToolChoiceN/A
toolsmodels.MessagesRequestToolUnion[]N/A
topKnumberN/A
topPnumberN/A
tracemodels.TraceConfigMetadata 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"}
userstringA 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.