Skip to main content
POST
Create a message

Authorizations

Authorization
string
header
required

A Nemonist key (sk-nm-...) as a bearer token in the Authorization header.

Headers

X-OpenRouter-Metadata
enum<string>

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.

Available options:
disabled,
enabled
Example:

"enabled"

HTTP-Referer
string

The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application.

X-OpenRouter-Title
string

The app display name allows you to customize how your app appears in OpenRouter's dashboard.

X-OpenRouter-Categories
string

Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.

Body

application/json

Request schema for Anthropic Messages API endpoint

messages
object[] | null
required

The conversation so far.

model
string
required

Model id to send the request to, as listed by GET /models (e.g. anthropic/claude-sonnet-4.5).

cache_control
object

Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format.

Example:
context_management
object | null

Context editing: when to clear or compact old context, and how.

deferred_tools
object

Opt-in versioned router-level deferred-tool protocol. Replay assistant reasoning unchanged on continuation; keep the catalog unchanged.

Example:
fallbacks
object[] | null

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.

Example:
max_tokens
integer

Most tokens the model may generate.

metadata
MessagesRequestMetadata · object

Request metadata, such as user_id.

models
string[]

Models to try in order when one is unavailable.

output_config
object

Configuration for controlling output behavior. Supports the effort parameter and structured output format.

Example:
plugins
object[]

Plugins you want to enable for this request, including their settings.

Example:
provider
object | null

When multiple model providers are available, optionally indicate your routing preference.

Example:
route
enum<string> | null
deprecated

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

Available options:
fallback,
sort,
null
Example:

"fallback"

safeguards
object[] | null

Server-side safeguards to run alongside the completion.

service_tier
string

Service tier to run on.

session_id
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.

Maximum string length: 256
speed
enum<string> | null

Inference speed: fast uses a higher-speed configuration at premium pricing; standard when omitted.

Available options:
fast,
standard,
null
Example:

"fast"

stop_sequences
string[]

Text that stops generation when produced.

stop_server_tools_when
object[]

Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls. When a condition fires while the model is still emitting tool calls, the pending tool calls are executed and one final turn is made with tool calls disabled so the response ends with a natural-language answer instead of an unfinished tool call.

Minimum array length: 1

A single condition that, when met, halts the server-tool agent loop.

Example:
Example:
stream
boolean

Stream the response as server-sent events.

system

System prompt: a string, or an array of text blocks (each may set cache_control).

temperature
number<double>

Sampling temperature; higher is more random.

thinking
object

Extended thinking: enabled with a token budget, adaptive, or disabled.

tool_choice
object

How the model chooses tools: auto, any, a named tool, or none.

tools
object[]

The tools the model may call.

top_k
integer

Sample only from this many most likely tokens. Not all providers support it.

top_p
number<double>

Sample only from the most likely tokens whose probabilities add up to this, 0 to 1.

trace
object

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.

Example:
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.

Maximum string length: 256

Response

Successful response

Non-streaming response from the Anthropic Messages API with OpenRouter extensions

container
object | null
required

The code-execution container this response used: its id (send it back to reuse the container), when it expires, and the skills loaded in it. Null when no container was used.

Example:
content
object[]
required

The content blocks the model produced (text, thinking, tool use).

Example:
id
string
required

Id of this message.

model
string
required

Model that produced this message.

role
enum<string>
required

One of "assistant".

Available options:
assistant
stop_details
object | null
required

Structured information about a refusal

Example:
stop_reason
enum<string> | null
required

Why the model stopped: "end_turn" (finished its answer), "max_tokens" (hit max_tokens), "model_context_window_exceeded" (ran out of context), "stop_sequence" (produced a stop sequence), "tool_use" (called a tool and waits for its result), "pause_turn" (paused a long server-tool turn; send the response back to continue), "refusal" (declined for safety), or "compaction" (stopped to compact the context). Null while a stream is still running.

Available options:
end_turn,
max_tokens,
model_context_window_exceeded,
stop_sequence,
tool_use,
pause_turn,
refusal,
compaction,
null
Example:

"end_turn"

stop_sequence
string | null
required

The stop sequence that ended the reply, if any.

type
enum<string>
required

One of "message".

Available options:
message
usage
object
required

Tokens and cost of the request.

Example:
input_transformations
object[] | null

Changes made to the input before it was sent to the model.

context_management
object | null

Context edits applied to this response.

openrouter_metadata
object

How OpenRouter routed this request: the strategy, the endpoints that could serve it, each attempt made, the region, whether your own provider key (BYOK) paid for it, and the generation time.

Example:
provider
string

Provider that served the request.

safeguard_results
object[] | null

Results of the server-side safeguards the request ran, or null.