Skip to content

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

ItemValue
EndpointPOST /v1/messages
Base URLhttps://ai.youqi.tech
Authx-api-key: <YOUR_API_KEY>
Version headeranthropic-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

ParameterTypeRequiredDescription
modelstringYesModel ID, e.g. claude-3-5-sonnet-20241022
messagesarrayYesConversation messages, each with role (user / assistant) and content
max_tokensintegerYesMax tokens to generate (required by the Claude native API)
systemstringNoSystem prompt (a separate field, not part of messages)
streambooleanNoWhether to stream, default false
temperaturenumberNoSampling temperature, 01
top_pnumberNoNucleus sampling
stop_sequencesarrayNoStop sequences
toolsarrayNoTool (function) definitions

Request example

bash
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." }
    ]
  }'

With the official Anthropic Python SDK, just point base_url to YouQi AI:

python
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)

Response example

json
{
  "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
  }
}

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"}}

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.

json
{
  "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"]
      }
    }
  ]
}

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.