Claude Sonnet 5.5
本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。
接口
POST /claude/v1/messages
完整 URL: https://ai.modelfold.online/claude/v1/messages
鉴权:所有请求都需要
Authorization: Bearer <API_KEY>请求头。
Streaming Support
当请求中设置 stream: true 时,接口会以 SSE 的形式返回结果。Claude 的函数调用会通过 tool_use 内容块和 input_json_delta 增量片段进行流式输出。
Streaming Response Format:
- Content-Type:
text/event-stream - 常见事件包括
message_start、content_block_start、content_block_delta、message_delta和message_stop - 函数调用会以
tool_use内容块的形式返回 - 函数调用场景下最终的
stop_reason通常为tool_use
Features
- 使用
messages进行标准对话。 - 使用
tools和input_schema进行函数调用。 - 支持 Claude 原生事件流返回。
- 支持项目中的 thinking 开关。
Request Notes
- 在
model字段中传入当前模型名称。 - 使用
messages传递对话上下文。 - 使用
tools声明可调用函数。 - 设置
stream: true可获得 SSE 流式返回。
Authentication
鉴权:请求头携带 Authorization: Bearer YOUR_API_KEY。使用 x-api-key 的客户端(如 Anthropic SDK)需将其值设为 Bearer YOUR_API_KEY。anthropic-version 可不传。
请求参数
请求体 (application/json)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 本页模型 id,如 claude-sonnet-5-5。可用 id 见 GET https://ai.modelfold.online/v1/anthropic/v1/models%60%E3%80%82 可选值:claude-sonnet-5-5。 示例:claude-sonnet-5-5`。 |
messages | array<object> | 是 | 按时间顺序传递的对话消息数组。 |
messages[].role | string | 是 | 消息角色。 可选值:user / assistant。 示例:user。 |
messages[].content | `string | array<object>` | 是 |
tools | array<object> | 否 | 可选的函数工具列表。每个工具都包含名称、描述和 input_schema。 |
tools[].name | string | 是 | 函数名称。 示例:get_current_weather。 |
tools[].description | string | 是 | 函数的自然语言描述。 示例:Get the current weather in a given location。 |
tools[].input_schema | object | 是 | 函数参数的 JSON Schema。 |
tools[].input_schema.type | string | 否 | Schema 类型。 示例:object。 |
tools[].input_schema.properties | object | 否 | 函数参数定义。 |
tools[].input_schema.required | array<string> | 否 | 必填参数列表。 |
thinkingFlag | boolean | 否 | 是否开启思考。 示例:true。 |
stream | boolean | 否 | 如果设为 true,接口会返回 SSE 流。 默认值:true。 示例:false。 |
max_tokens | number | 否 | 可选的Claude输出令牌限制。留空以使用默认值4096。 默认值:4096。 示例:4096。 |
请求示例
bash
curl -X POST "https://ai.modelfold.online/claude/v1/messages" \
-H "Authorization: Bearer $MODELFOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston today?"
}
],
"tools": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. Boston, MA"
}
},
"required": [
"location"
]
}
}
],
"thinkingFlag": true,
"stream": false,
"max_tokens": 4096
}'json
{
"model": "claude-sonnet-5-5",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston today?"
}
],
"tools": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. Boston, MA"
}
},
"required": [
"location"
]
}
}
],
"thinkingFlag": true,
"stream": false,
"max_tokens": 4096
}响应
200 — 请求成功。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
role | string | 否 | 返回消息角色 示例:assistant。 |
usage | object | 否 | 返回的用量信息 |
usage.input_tokens | integer | 否 | 输入 token 数量 示例:600。 |
usage.output_tokens | integer | 否 | 输出 token 数量 示例:57。 |
usage.cache_creation_input_tokens | integer | 否 | 缓存创建输入 token 数量 示例:0。 |
usage.cache_read_input_tokens | integer | 否 | 缓存读取输入 token 数量 示例:0。 |
usage.service_tier | string | 否 | 服务等级 示例:standard。 |
stop_reason | string | 否 | 生成停止原因 示例:tool_use。 |
model | string | 否 | 实际返回的模型版本 示例:claude-opus-4-5-20251101。 |
id | string | 否 | 消息唯一标识 示例:msg_01VSoxV4a8YWB3DBh9TdM63W。 |
credits_consumed | number | 否 | 本次请求消耗的 credits 示例:0.25。 |
type | string | 否 | 顶层响应对象类型 示例:message。 |
content | array<object> | 否 | 响应内容块 |
content[].input | object | 否 | 工具输入参数 |
content[].caller | object | 否 | 工具调用来源信息 |
content[].caller.type | string | 否 | 示例:direct。 |
content[].name | string | 否 | 工具名称 示例:get_current_weather。 |
content[].id | string | 否 | 工具调用标识 示例:toolu_018gdqs2FHxrRjQHLZv1qvbF。 |
content[].type | string | 否 | 内容块类型 示例:tool_use。 |
json
{
"role": "assistant",
"usage": {
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 0
},
"output_tokens": 57,
"service_tier": "standard",
"cache_creation_input_tokens": 0,
"input_tokens": 600,
"cache_read_input_tokens": 0,
"inference_geo": "not_available"
},
"stop_reason": "tool_use",
"model": "claude-sonnet-5-5",
"id": "msg_01VSoxV4a8YWB3DBh9TdM63W",
"credits_consumed": 0.14,
"type": "message",
"content": [
{
"input": {
"location": "Beijing, China"
},
"caller": {
"type": "direct"
},
"name": "get_current_weather",
"id": "toolu_018gdqs2FHxrRjQHLZv1qvbF",
"type": "tool_use"
}
]
}400 — 错误请求 - 请求参数无效
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | 否 | — |
error.message | string | 否 | 示例:Invalid request parameters。 |
error.type | string | 否 | 示例:invalid_request_error。 |
json
{
"error": {
"message": "Invalid request parameters",
"type": "invalid_request_error"
}
}401 — 未授权 - API Key 无效或缺失
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | 否 | — |
error.message | string | 否 | 示例:Invalid or missing API key。 |
error.type | string | 否 | 示例:authentication_error。 |
json
{
"error": {
"message": "Invalid or missing API key",
"type": "authentication_error"
}
}