Messages (Anthropic-compatible)
POST /v1/messages — Anthropic Messages API
Compatible with the Anthropic Messages API. Under the hood it shares the same routing pipeline as Chat Completions — only the request/response shape is adapted to Anthropic style.
Auth difference (important): the platform's /messages uses Authorization: Bearer $MODELSITE_API_KEY, not official Anthropic x-api-key. With the official anthropic SDK pass auth_token (Bearer); do not pass api_key (sends x-api-key → 401). The anthropic-version header is required.
Example
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.modelsite.ai", # SDK appends /v1/messages
auth_token="ms_live_sk_xxxxxxxx", # Authorization: Bearer (required — not api_key)
)
resp = client.messages.create(
model="claude-sonnet-4.6",
max_tokens=256,
messages=[{"role": "user", "content": "Explain quantum entanglement in one sentence"}],
)
print(resp.content[0].text)The API card below is rendered from the OpenAPI spec (auth, Request-body parameter table, Response schema).
Authorization
BearerAuth Authorization: Bearer $MODELSITE_API_KEY(与 OpenAI 格式共享同一 Key)
In: header
Header Parameters
Anthropic API 版本。
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
curl -X POST "https://example.com/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "string", "messages": [ {} ], "max_tokens": 0 }'{ "id": "string", "type": "string", "role": "string", "model": "string", "content": [ { "type": "string", "text": "string" } ], "stop_reason": "end_turn", "stop_sequence": "string", "usage": { "input_tokens": 0, "output_tokens": 0, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0 }}Streaming
stream: true returns an event sequence: message_start → content_block_start → content_block_delta (many) → content_block_stop → message_delta → message_stop.
Which format?
| Existing code | Recommended entry point |
|---|---|
| OpenAI / LangChain(OpenAI) / most frameworks | /chat/completions |
| Anthropic SDK | /messages (this page) |
Both entry points reach the same set of models.