Anthropic Messages
The Anthropic-native messaging format for Claude models. You can also call Claude models through the OpenAI-format Chat Completions endpoint.
RequestREQUEST
POST
https://test.kailin.com.cn/v1/messagesResponseRESPONSE
Fill in the request and hit Send — the response shows up here
Request
curl https://test.kailin.com.cn/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: sk-your-token" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Hello, introduce yourself" }
]
}'
note
Both x-api-key: sk-xxx and Authorization: Bearer sk-xxx headers work. The anthropic-version header is optional.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Claude model name |
max_tokens | number | Yes | Max tokens to generate (required in the Anthropic format) |
messages | array | Yes | Message array; role is only user / assistant |
system | string / array | No | System prompt, passed separately from messages |
stream | boolean | No | Stream output (SSE, event types below) |
temperature | number | No | 0–1, default 1 |
top_p / top_k | number | No | Sampling parameters |
stop_sequences | array | No | Stop sequences |
tools | array | No | Tool definitions (name / description / input_schema) |
tool_choice | object | No | {"type": "auto"} / {"type": "any"} / {"type": "tool", "name": "..."} |
Example with a system prompt and an image:
{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"system": "You are a rigorous technical writer.",
"messages": [
{
"role": "user",
"content": [
{ "type": "image", "source": { "type": "base64", "media_type": "image/jpeg", "data": "<base64>" } },
{ "type": "text", "text": "Describe this architecture diagram" }
]
}
]
}
Response (Non-streaming)
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-6",
"content": [
{ "type": "text", "text": "Hello! I'm Claude…" }
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 18,
"output_tokens": 45
}
}
| Field | Description |
|---|---|
content[] | Content blocks — type can be text / tool_use / thinking |
stop_reason | end_turn / max_tokens / stop_sequence / tool_use |
usage.input_tokens / output_tokens | Token usage |
Streaming Events
With "stream": true the response is SSE with distinct event: types:
event: message_start
data: {"type":"message_start","message":{...}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":45}}
event: message_stop
data: {"type":"message_stop"}
| Event | Description |
|---|---|
message_start | Message starts, with initial usage |
content_block_start / _delta / _stop | Content block start / delta / stop — deltas arrive in delta.text |
message_delta | Top-level status update (stop_reason, final usage) |
message_stop | Message ends |
ping | Keep-alive heartbeat |
error | In-stream error |
Using the Anthropic SDK
from anthropic import Anthropic
client = Anthropic(
api_key="sk-your-token",
base_url="https://test.kailin.com.cn",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'sk-your-token',
baseURL: 'https://test.kailin.com.cn',
});
const message = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(message.content[0].text);
tip
For the SDK, set base_url to the root address (without /v1) — the SDK appends /v1/messages automatically.