Claude Native Messages
In addition to the OpenAI-compatible format, YouQi AI exposes the Anthropic Claude native Messages API, so you can use the Anthropic SDK or an existing Claude integration directly — no rewrite to the OpenAI format required.
Endpoint & authentication
| Item | Value |
|---|---|
| Endpoint | POST /v1/messages |
| Base URL | https://ai.youqi.tech |
| Auth | x-api-key: <YOUR_API_KEY> |
| Version header | anthropic-version: 2023-06-01 |
Difference from the OpenAI format
The Claude native API uses the x-api-key header (not Authorization: Bearer) and requires the anthropic-version header. The API key is still the sk-... key you create in the console.
Create a message
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, e.g. claude-3-5-sonnet-20241022 |
messages | array | Yes | Conversation messages, each with role (user / assistant) and content |
max_tokens | integer | Yes | Max tokens to generate (required by the Claude native API) |
system | string | No | System prompt (a separate field, not part of messages) |
stream | boolean | No | Whether to stream, default false |
temperature | number | No | Sampling temperature, 0–1 |
top_p | number | No | Nucleus sampling |
stop_sequences | array | No | Stop sequences |
tools | array | No | Tool (function) definitions |
Request example
curl https://ai.youqi.tech/v1/messages \
-H "x-api-key: sk-YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Introduce Hangzhou in one sentence." }
]
}'2
3
4
5
6
7
8
9
10
11
With the official Anthropic Python SDK, just point base_url to YouQi AI:
from anthropic import Anthropic
client = Anthropic(
base_url="https://ai.youqi.tech",
api_key="sk-YOUR_API_KEY",
)
resp = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.content[0].text)2
3
4
5
6
7
8
9
10
11
12
13
Response example
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "claude-3-5-sonnet-20241022",
"content": [
{ "type": "text", "text": "Hangzhou is a city famed for West Lake, blending deep history with a vibrant digital economy." }
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 18,
"output_tokens": 22
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
Streaming (SSE)
Add "stream": true to the request body and the server returns Server-Sent Events. Event types include message_start, content_block_delta, message_delta, and message_stop:
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hang"}}2
Tool use
Declare callable tools in tools. When the model needs to call one, it returns a type: "tool_use" block in the response content; you execute it and send the result back as a tool_result content block with role: "user" to continue the conversation.
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "What's the weather in Beijing today?" }],
"tools": [
{
"name": "get_weather",
"description": "Get the weather for a given city",
"input_schema": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
]
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Note
If you use the OpenAI SDK, you can also call Claude models via the Chat endpoint (/v1/chat/completions) — the gateway handles protocol conversion automatically. The native Messages API suits existing Anthropic integrations or Claude-specific fields.