Claude 模型调用
Base URL: https://openai.qiniu.com
Base URL(备): https://api.qnaigc.com
注:本文档是说明如何通过OpenAI API兼容协议调用Claude模型的方法。
而通过Anthropic API兼容协议调用其他大模型的方法请参考Claude Code 配置
Authentication
- HTTP Authentication, scheme: bearer
聊天(Chat)
POST 创建 Chat Completions
POST /v1/chat/completions
根据给定的输入完成推理。
Body 请求参数
{
"model": "claude-3.7-sonnet",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
请求参数
名称 | 位置 | 类型 | 必选 | 说明 |
---|---|---|---|---|
Content-Type | header | string | 是 | none |
Accept | header | string | 是 | none |
Authorization | header | string | 是 | none |
body | body | object | 是 | none |
» model | body | string | 是 | 要使用的模型的 ID |
» messages | body | [object] | 是 | 至今为止对话所包含的消息列表。 |
»» role | body | string | 否 | none |
»» content | body | string | 否 | none |
» temperature | body | integer | 否 | 使用什么采样温度,较高的值将使输出更加随机,而较低的值将使输出更加集中和确定。 |
» top_p | body | integer | 否 | 一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 |
» stream | body | boolean | 否 | 默认为 false 如果设置,则像在 ChatGPT 中一样会发送部分消息增量。标记将以仅数据的服务器发送事件的形式发送, 并在 data: [DONE] 消息时终止流。 |
» max_tokens | body | integer | 否 | 设置模型最大推理输出 token 数量,超出会结束输出 |
» thinking | body | object | 否 | 是否支持思考,部分模型不支持该控制 |
»» type | body | enum | 否 | 可选 enabled/disabled |
»» budget_tokens | body | integer | 否 | 如果设置了type开启,此字段必填,且最小为1024,最大不超过max_tokens(如果设置了的话) |
» tools | body | [string] | 否 | 模型可以调用的一组工具列表。目前,只支持作为工具的函数。使用此功能来提供模型可以为之生成 JSON 输入的函数列表。 |
» tool_choice | body | object | 否 | 控制模型调用哪个函数(如果有的话)。none 表示模型不会调用函数,而是生成消息。auto 表示模型可以在生成消息和调用函数之间进行选择。通过 {“type”: “function”, “function”: {“name”: “my_function”}} 强制模型调用该函数。 如果没有函数存在,默认为 none。如果有函数存在,默认为 auto。 |
详细说明
返回示例
200 Response
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
返回结果
状态码 | 状态码含义 | 说明 | 数据模型 |
---|---|---|---|
200 | OK | none | Inline |
返回数据结构
状态码 200
名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
---|---|---|---|---|---|
» id | string | true | none | none | |
» object | string | true | none | none | |
» created | integer | true | none | none | |
» choices | [object] | true | none | none | |
»» index | integer | false | none | none | |
»» message | object | false | none | none | |
»»» role | string | true | none | none | |
»»» content | string | true | none | none | |
»» finish_reason | string | false | none | none | |
» usage | object | true | none | none | |
»» prompt_tokens | integer | true | none | none | |
»» completion_tokens | integer | true | none | none | |
»» total_tokens | integer | true | none | none |
模型(Models)
GET 列出模型
GET /v1/models
列出当前可用的型号,并提供每个型号的基本信息。
请求参数
名称 | 位置 | 类型 | 必选 | 说明 |
---|---|---|---|---|
Authorization | header | string | 否 | none |
返回示例
200 Response
{
"object": "list",
"data": [
{
"id": "model-id-0",
"object": "model",
"created": 1686935002,
"owned_by": "organization-owner"
},
{
"id": "model-id-1",
"object": "model",
"created": 1686935002,
"owned_by": "organization-owner",
},
{
"id": "model-id-2",
"object": "model",
"created": 1686935002,
"owned_by": "openai"
},
],
"object": "list"
}
返回结果
状态码 | 状态码含义 | 说明 | 数据模型 |
---|---|---|---|
200 | OK | none | Inline |
返回数据结构
状态码 200
名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
---|---|---|---|---|---|
» object | string | true | none | none | |
» data | [object] | true | none | none | |
»» id | string | true | none | none | |
»» object | string | true | none | none | |
»» created | integer | true | none | none | |
»» owned_by | string | true | none | none |
文档反馈
(如有产品使用问题,请 提交工单)