Create a message
Creates a message using the Anthropic Messages API format. Supports text, images, PDFs, tools, and extended thinking.
Authorizations
API key as bearer token in Authorization header
Headers
Opt-in to surface routing metadata on the response under openrouter_metadata. Defaults to disabled. The legacy header X-OpenRouter-Experimental-Metadata is also accepted for backward compatibility.
Opt-in level for surfacing routing metadata on the response under openrouter_metadata.
disabled, enabled "enabled"
Body
Request schema for Anthropic Messages API endpoint
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" }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.
[{ "model": "claude-opus-4-8" }]Configuration for controlling output behavior. Supports the effort parameter and structured output format.
{ "effort": "medium" }Plugins you want to enable for this request, including their settings.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
{
"allowed_models": ["anthropic/*", "openai/gpt-4o"],
"cost_quality_tradeoff": 7,
"enabled": true,
"id": "auto-router"
}When multiple model providers are available, optionally indicate your routing preference.
{ "allow_fallbacks": true }DEPRECATED Use providers.sort.partition instead. Backwards-compatible alias for providers.sort.partition. Accepts legacy values: "fallback" (maps to "model"), "sort" (maps to "none").
fallback, sort, null "fallback"
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.
256Controls output generation speed. When set to fast, uses a higher-speed inference configuration at premium pricing. Defaults to standard when omitted.
fast, standard, null "fast"
Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls.
1A single condition that, when met, halts the server-tool agent loop.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
{ "step_count": 5, "type": "step_count_is" }[
{ "step_count": 5, "type": "step_count_is" },
{
"max_cost_in_dollars": 0.5,
"type": "max_cost"
}
]- Option 1
- Option 2
- Option 3
- Option 1
- Option 2
- Option 3
- Option 4
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
- Option 12
- Option 13
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"
}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.
256Response
Successful response
Non-streaming response from the Anthropic Messages API with OpenRouter extensions
{
"expires_at": "2026-04-08T00:00:00Z",
"id": "ctr_01abc"
}- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
- Option 12
- Option 13
- Option 14
{
"citations": null,
"text": "Hello, world!",
"type": "text"
}assistant Structured information about a refusal
{
"category": "cyber",
"explanation": "The request was refused due to policy.",
"type": "refusal"
}end_turn, max_tokens, stop_sequence, tool_use, pause_turn, refusal, compaction, null "end_turn"
message {
"cache_creation": null,
"cache_creation_input_tokens": null,
"cache_read_input_tokens": null,
"inference_geo": null,
"input_tokens": 100,
"output_tokens": 50,
"output_tokens_details": null,
"server_tool_use": null,
"service_tier": "standard"
}{
"attempt": 1,
"endpoints": {
"available": [
{
"model": "openai/gpt-4o",
"provider": "OpenAI",
"selected": true
}
],
"total": 1
},
"is_byok": false,
"region": "iad",
"requested": "openai/gpt-4o",
"strategy": "direct",
"summary": "available=1, selected=OpenAI"
}AkashML, AI21, AionLabs, Alibaba, Ambient, Baidu, Amazon Bedrock, Amazon Nova, Anthropic, Arcee AI, AtlasCloud, Avian, Azure, BaseTen, BytePlus, Black Forest Labs, Cerebras, Chutes, Cirrascale, Clarifai, Cloudflare, Cohere, Crucible, Crusoe, Darkbloom, Decart, DeepInfra, DeepSeek, DekaLLM, DigitalOcean, Featherless, Fireworks, Friendli, GMICloud, Google, Google AI Studio, Groq, HeyGen, Inception, Inceptron, InferenceNet, Ionstream, Infermatic, Io Net, Inferact vLLM, Inflection, Liquid, Mara, Mancer 2, Minimax, ModelRun, Mistral, Modular, Moonshot AI, Morph, NCompass, Nebius, Nex AGI, NextBit, Novita, Nvidia, OpenAI, OpenInference, Parasail, Poolside, Perceptron, Perplexity, Phala, Recraft, Reka, Relace, Sakana AI, SambaNova, Seed, SiliconFlow, Sourceful, StepFun, Stealth, StreamLake, Switchpoint, Tenstorrent, Together, Upstage, Venice, Wafer, WandB, Quiver, Xiaomi, xAI, Z.AI, FakeProvider "OpenAI"