POST /v1/messages
Creates a message using the Anthropic Messages API format. This endpoint lets you call Anthropic models (and compatible providers) with the native request structure — includingsystem as a top-level field, Anthropic-style content blocks, and extended thinking configuration — without translating to the OpenAI format.
This endpoint is intended for Anthropic-native integrations. For cross-provider routing with a unified format, use chat completions instead.
Request headers
string
The provider to route the request to. Typically
anthropic for this endpoint.string
Your provider API key.
string
A JSON config object or config ID that defines routing, fallbacks, retries, and more.
string
A virtual key ID from Portkey Cloud.
Request body
string
required
The model identifier (e.g.
claude-opus-4-5, claude-3-5-sonnet-20241022).object[]
required
The conversation messages. Only
user and assistant roles are accepted; system instructions go in the top-level system field.integer
required
The maximum number of tokens to generate. The request fails if the prompt plus
max_tokens exceeds the model’s context length.string | object[]
The system prompt. Accepts a plain string or an array of
TextBlockParam objects for structured system prompts (including prompt caching with cache_control).number
Sampling temperature between
0 and 1 for most Claude models.number
Nucleus sampling threshold. Only tokens in the top
top_p cumulative probability are considered.integer
Only sample from the top
top_k tokens at each step.boolean
default:"false"
When
true, responses stream as server-sent events.string[]
Custom sequences that cause the model to stop generating.
object[]
Definitions of tools the model may call.
object
Controls tool selection. One of
{"type": "auto"}, {"type": "any"}, {"type": "tool", "name": "..."}, or {"type": "none"}.object
Configuration for extended thinking (reasoning).
object
Optional metadata about the request.
string
Capacity tier to use. One of
auto or standard_only.Response
string
Unique message identifier.
string
Always
message.string
Always
assistant.string
The model that produced the response.
object[]
The generated content as an array of typed content blocks.
string
Why the model stopped. One of
end_turn, max_tokens, stop_sequence, or tool_use.string | null
The stop sequence that triggered a stop, if any.
object
Token usage for the request.
Code examples
POST /v1/messages/count_tokens
Count the number of tokens that a given request would consume without generating a response. Useful for checking whether a prompt fits within a model’s context window before making the full request. The request body has the same structure asPOST /v1/messages.
curl
Response
integer
The number of tokens the request would use, including the system prompt and all messages.