Skip to main content
MonoRelay accepts native Anthropic API format and exposes it at /v1/messages — you can point the official Anthropic SDK directly at MonoRelay without changing your request format. All request fields, streaming behavior, and beta headers are forwarded transparently to the configured Anthropic-compatible provider.

Endpoints

The Anthropic-compatible endpoints share the same /v1/ base path as OpenAI-compatible ones:
When configuring the Anthropic SDK with base_url, use http://localhost:8787 (without /v1/). The SDK appends /v1/messages automatically.

Authentication

Pass your MonoRelay access token in either of these headers: The token is verified against the MonoRelay server’s configured access_key or a valid user JWT issued after login.

POST /v1/messages

Send a chat message and receive an Anthropic-format response. Supports both single-turn and multi-turn conversations, streaming, vision, tool use, and extended thinking (beta).

GET /v1/anthropic/models

List models available through the configured Anthropic-compatible provider. Returns a model list in Anthropic response format.

POST /v1/messages/beta

Identical to the standard messages endpoint but also accepts the anthropic-beta header for features such as extended thinking, prompt caching, and computer use. Set the header in your request and MonoRelay forwards it upstream unchanged.

Request body

string
required
The model identifier to use, e.g. claude-opus-4-5 or a MonoRelay alias. MonoRelay resolves aliases and provider routing before forwarding.
integer
required
Maximum number of tokens to generate. Required by the Anthropic API; has no default.
array
required
Ordered list of conversation turns. Each element must have:
  • role — "user" or "assistant"
  • content — a string or an array of content blocks (text, image, tool_result, etc.)
The array must alternate roles and must begin with a user turn.
string or array
System prompt text. Accepts either a plain string or an array of content blocks for structured system prompts (useful with prompt caching).
number
Sampling temperature between 0.0 and 1.0. Controls output randomness. Omit to use the model’s default.
number
Nucleus sampling threshold. Only tokens in the top top_p probability mass are considered. Usually set either temperature or top_p, not both.
integer
Only sample from the top top_k tokens at each step. Not available on all models.
array
List of strings that stop generation when encountered. The model will not include the stop sequence in the response.
boolean
Set to true to receive a Server-Sent Events stream instead of a single JSON response. Defaults to false.
array
List of tool definitions the model may call. Each tool requires name, description, and a JSON Schema input_schema.
object
Controls tool selection behavior. Use {"type": "auto"}, {"type": "any"}, or {"type": "tool", "name": "my_tool"} to force a specific tool.

Response fields

string
Unique message identifier, e.g. msg_01XFDUDYJgAACTJgxXiHvVEF.
string
Always "message" for non-streaming responses.
string
Always "assistant".
array
Array of content blocks. A standard text response contains one block of {"type": "text", "text": "..."}. Tool use responses include {"type": "tool_use", ...} blocks. Extended thinking responses include {"type": "thinking", "thinking": "..."} blocks.
string
The model that generated the response as resolved by MonoRelay.
string
Why generation stopped: "end_turn", "max_tokens", "stop_sequence", or "tool_use".
object
Token consumption report:
  • input_tokens — prompt tokens consumed
  • output_tokens — completion tokens generated
  • cache_read_input_tokens — tokens served from prompt cache
  • cache_creation_input_tokens — tokens written to prompt cache

Python SDK example

Point the official Anthropic Python SDK at MonoRelay by setting base_url. No other code changes are needed.

curl example

Streaming example

Streaming responses arrive as Server-Sent Events. The sequence of event types is: message_start → content_block_start → content_block_delta (repeated) → content_block_stop → message_delta → message_stop.