发布/v1/消息
用于聊天、流媒体、视觉、工具、缓存和思考的 Anthropic Messages API。
发布/v1/消息
主要的 Anthropic 兼容端点。当所选模型支持时,它支持流、提示缓存、视觉、工具使用和扩展思维。
验证
x-api-key: mg_live_...\nanthropic-version: 2023-06-01\ncontent-type: application/json
最低要求
curl https://api.model-gate.com/v1/messages \
-H "x-api-key: mg_live_..." \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4.8",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'
高级请求
{
"model": "claude-opus-4.8",
"max_tokens": 4096,
"system": "You are a coding assistant.",
"thinking": {"type": "enabled", "budget_tokens": 8000},
"messages": [{"role": "user", "content": "Find the bug in this code."}],
"tools": [{
"name": "search_files",
"description": "Search project files",
"input_schema": {"type": "object", "properties": {"q": {"type": "string"}}}
}]
}
想象
{
"model": "claude-opus-4.8",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is shown in this image?"},
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}}
]
}]
}
提示缓存
{
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Large reusable context...", "cache_control": {"type": "ephemeral"}},
{"type": "text", "text": "New question"}
]
}]
}
流媒体
放 "stream": true。响应作为服务器发送的事件返回。
回复
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-opus-4.8",
"content": [{"type": "text", "text": "Hello!"}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 12, "output_tokens": 8}
}
请求和响应结构遵循 Anthropic Messages API。现有的 Anthropic SDK 通常只需要 base_url 改变。