切换主题
原生Claude格式
Anthropic Claude Messages API 格式的请求。 需要在请求头中包含 anthropic-version。
原生Claude格式
POST /v1/messages
Anthropic Claude Messages API 格式的请求。 需要在请求头中包含 anthropic-version。
认证
BearerAuth
请求参数
| 名称 | 位置 | 必填 | 类型 | 说明 |
|---|---|---|---|---|
| anthropic-version | header | 是 | string | Anthropic API 版本 |
| x-api-key | header | 否 | string | Anthropic API Key (可选,也可使用 Bearer Token) |
请求体
必填:否
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| model | 是 | string | Examples: claude-3-opus-20240229 |
| messages | 是 | array<object> | - |
| messages[].role | 否 | enum: user | assistant | - |
| messages[].content | 否 | oneOf<string | array<object>> | - |
| system | 否 | oneOf<string | array<object>> | - |
| max_tokens | 是 | integer | - |
| temperature | 否 | number | - |
| top_p | 否 | number | - |
| top_k | 否 | integer | - |
| stream | 否 | boolean | - |
| stop_sequences | 否 | array<string> | - |
| tools | 否 | array<object> | - |
| tools[].name | 否 | string | - |
| tools[].description | 否 | string | - |
| tools[].input_schema | 否 | object | - |
| tool_choice | 否 | oneOf<object> | - |
| tool_choice.type | 否 | enum: auto | any | tool | - |
| tool_choice.name | 否 | string | - |
| thinking | 否 | object | - |
| thinking.type | 否 | enum: enabled | disabled | - |
| thinking.budget_tokens | 否 | integer | - |
| metadata | 否 | object | - |
| metadata.user_id | 否 | string | - |
原始 Schema
json
{
"type": "object",
"required": [
"model",
"messages",
"max_tokens"
],
"properties": {
"model": {
"type": "string",
"examples": [
"claude-3-opus-20240229"
]
},
"messages": {
"type": "array",
"items": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"user",
"assistant"
]
},
"content": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"image",
"tool_use",
"tool_result"
]
},
"text": {
"type": "string"
},
"source": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"base64",
"url"
]
},
"media_type": {
"type": "string"
},
"data": {
"type": "string"
},
"url": {
"type": "string"
}
},
"x-apifox-orders": [
"type",
"media_type",
"data",
"url"
]
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"input": {
"type": "object",
"properties": {},
"x-apifox-orders": []
},
"tool_use_id": {
"type": "string"
},
"content": {
"type": "string"
}
},
"x-apifox-orders": [
"type",
"text",
"source",
"id",
"name",
"input",
"tool_use_id",
"content"
]
}
}
]
}
},
"x-apifox-orders": [
"role",
"content"
]
}
},
"system": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {},
"x-apifox-orders": []
}
}
]
},
"max_tokens": {
"type": "integer",
"minimum": 1
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"top_p": {
"type": "number"
},
"top_k": {
"type": "integer"
},
"stream": {
"type": "boolean"
},
"stop_sequences": {
"type": "array",
"items": {
"type": "string"
}
},
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"input_schema": {
"type": "object",
"properties": {},
"x-apifox-orders": []
}
},
"x-apifox-orders": [
"name",
"description",
"input_schema"
]
}
},
"tool_choice": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"auto",
"any",
"tool"
]
},
"name": {
"type": "string"
}
},
"x-apifox-orders": [
"type",
"name"
]
}
]
},
"thinking": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"enabled",
"disabled"
]
},
"budget_tokens": {
"type": "integer"
}
},
"x-apifox-orders": [
"type",
"budget_tokens"
]
},
"metadata": {
"type": "object",
"properties": {
"user_id": {
"type": "string"
}
},
"x-apifox-orders": [
"user_id"
]
}
},
"x-apifox-orders": [
"model",
"messages",
"system",
"max_tokens",
"temperature",
"top_p",
"top_k",
"stream",
"stop_sequences",
"tools",
"tool_choice",
"thinking",
"metadata"
]
}响应
200 成功创建响应
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| id | 否 | string | - |
| type | 否 | string | Examples: message |
| role | 否 | string | Examples: assistant |
| content | 否 | array<object> | - |
| content[].type | 否 | string | - |
| content[].text | 否 | string | - |
| model | 否 | string | - |
| stop_reason | 否 | enum: end_turn | max_tokens | stop_sequence | tool_use | - |
| usage | 否 | object | - |
| usage.input_tokens | 否 | integer | - |
| usage.output_tokens | 否 | integer | - |
| usage.cache_creation_input_tokens | 否 | integer | - |
| usage.cache_read_input_tokens | 否 | integer | - |
原始 Schema
json
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"examples": [
"message"
]
},
"role": {
"type": "string",
"examples": [
"assistant"
]
},
"content": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"text": {
"type": "string"
}
},
"x-apifox-orders": [
"type",
"text"
]
}
},
"model": {
"type": "string"
},
"stop_reason": {
"type": "string",
"enum": [
"end_turn",
"max_tokens",
"stop_sequence",
"tool_use"
]
},
"usage": {
"type": "object",
"properties": {
"input_tokens": {
"type": "integer"
},
"output_tokens": {
"type": "integer"
},
"cache_creation_input_tokens": {
"type": "integer"
},
"cache_read_input_tokens": {
"type": "integer"
}
},
"x-apifox-orders": [
"input_tokens",
"output_tokens",
"cache_creation_input_tokens",
"cache_read_input_tokens"
]
}
},
"x-apifox-orders": [
"id",
"type",
"role",
"content",
"model",
"stop_reason",
"usage"
]
}