Claude Messages
Call models in the native Anthropic Messages format.
/v1/messages
Compatible with the Anthropic Messages API, so the official Anthropic SDKs and tools such as Claude Code work with RuToken unchanged. Point the SDK at https://rutoken.ai (without /v1) and use your RuToken key.
Authentication
x-api-key: sk-xxxx together with anthropic-version: 2023-06-01. Authorization: Bearer sk-xxxx is accepted as well.
Optional anthropic-beta headers are forwarded to the upstream to enable beta features.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Model ID, e.g. claude-sonnet-4-5. |
max_tokens |
integer | Yes | Maximum number of tokens to generate. |
messages |
array | Yes | Alternating user / assistant messages. See Messages below. |
system |
string | array | No | System prompt, as a string or an array of text blocks (blocks may carry cache_control). |
temperature |
number | No | 0–1. Default 1. |
top_p |
number | No | Nucleus sampling. Change this or temperature, not both. |
top_k |
integer | No | Sample only from the top K tokens. |
stop_sequences |
array | No | Custom strings that stop generation. |
stream |
boolean | No | Stream the response as SSE. See Streaming. |
tools |
array | No | Tools the model may use: client tools with name, description, input_schema, or server tools such as web_search. |
tool_choice |
object | No | {"type": "auto"}, {"type": "any"}, {"type": "tool", "name": "..."} or {"type": "none"}. |
thinking |
object | No | Extended thinking: {"type": "enabled", "budget_tokens": 4096}. budget_tokens must be lower than max_tokens. |
metadata |
object | No | {"user_id": "..."} — an opaque end-user identifier. |
Messages
content is a string or an array of content blocks:
| Block type | Description |
|---|---|
text |
{"type": "text", "text": "..."} |
image |
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}} or source.type: "url" with url. |
document |
PDF input, source as for images with media_type: "application/pdf". |
tool_use |
A tool call made by the assistant (in previous turns). |
tool_result |
{"type": "tool_result", "tool_use_id": "...", "content": "..."} — result returned by your code in a user message. |
Add "cache_control": {"type": "ephemeral"} to a block to use prompt caching on models that support it.
Request example
curl https://rutoken.ai/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "Explain recursion in one sentence."}
]
}'
import anthropic
client = anthropic.Anthropic(base_url="https://rutoken.ai", api_key="sk-xxxx")
message = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
system="You are a helpful assistant.",
messages=[{"role": "user", "content": "Explain recursion in one sentence."}],
)
print(message.content[0].text)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://rutoken.ai", apiKey: "sk-xxxx" });
const message = await client.messages.create({
model: "claude-sonnet-4-5",
max_tokens: 1024,
system: "You are a helpful assistant.",
messages: [{ role: "user", content: "Explain recursion in one sentence." }],
});
console.log(message.content[0].text);
Extended thinking:
{
"model": "claude-sonnet-4-5",
"max_tokens": 16000,
"thinking": {"type": "enabled", "budget_tokens": 8000},
"messages": [{"role": "user", "content": "Prove that there are infinitely many primes."}]
}
Response
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-5",
"content": [
{
"type": "text",
"text": "Recursion is a technique where a function calls itself to solve smaller instances of the same problem."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 21,
"output_tokens": 24,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}
| Field | Type | Description |
|---|---|---|
content |
array | Output blocks: text, thinking, tool_use. |
stop_reason |
string | end_turn, max_tokens, stop_sequence, tool_use, pause_turn or refusal. |
usage |
object | input_tokens, output_tokens and prompt-cache counters. |
Errors on this endpoint use the Anthropic shape {"type": "error", "error": {"type": ..., "message": ...}}. See Errors.
Streaming
With "stream": true the endpoint emits the Anthropic event sequence message_start → content_block_start → content_block_delta → content_block_stop → message_delta → message_stop. See Streaming.
Notes
- Claude models can also be called through Chat Completions in OpenAI format.
- Many non-Claude models (served through OpenAI-compatible channels) also accept this format; the gateway converts the request. Provider-specific features such as
thinkingorcache_controlmay then be ignored. - To use Claude Code, set
ANTHROPIC_BASE_URL=https://rutoken.aiandANTHROPIC_AUTH_TOKEN=sk-xxxx.