Anthropic Messages

Create a message

Creates a message using the Anthropic Messages API format. Supports text, images, PDFs, tools, and extended thinking.

post/messages

Headers

X-OpenRouter-Metadata'disabled' | 'enabled'

Opt-in level for surfacing routing metadata on the response under openrouter_metadata.

Example:enabled

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.

Request body

max_tokensinteger
modelstring required
modelsstring[]
route'fallback' | 'sort' | 'null' nullable

DEPRECATED Use providers.sort.partition instead. Backwards-compatible alias for providers.sort.partition. Accepts legacy values: "fallback" (maps to "model"), "sort" (maps to "none").

service_tierstring
session_idstring

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'fast' | 'standard' | 'null' nullable

Controls output generation speed. When set to fast, uses a higher-speed inference configuration at premium pricing. Defaults to standard when omitted.

stop_sequencesstring[]
streamboolean
temperaturenumber double
top_kinteger
top_pnumber double
userstring

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.

Example request

{
  "max_tokens": 1024,
  "messages": [
    {
      "content": "Hello, how are you?",
      "role": "user"
    }
  ],
  "model": "anthropic/claude-4.5-sonnet-20250929",
  "temperature": 0.7
}

Response

Successful response

idstring required
modelstring required
role'assistant' required
stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal' | 'compaction' | 'null' nullable required
stop_sequencestring nullable required
type'message' required
provider'Meta' | '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' | 'Deepgram' | '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'

Example response

{
  "container": null,
  "content": [
    {
      "citations": [],
      "text": "Hello! I'm doing well, thank you for asking.",
      "type": "text"
    }
  ],
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "model": "claude-sonnet-4-5-20250929",
  "role": "assistant",
  "stop_details": null,
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "cache_creation": null,
    "cache_creation_input_tokens": null,
    "cache_read_input_tokens": null,
    "inference_geo": null,
    "input_tokens": 12,
    "output_tokens": 15,
    "server_tool_use": null,
    "service_tier": "standard"
  }
}

Changes