给定一个提示,该模型将返回一个或多个预测的完成,并且还可以返回每个位置的替代标记的概率。
为提供的提示和参数创建完成
官方文档:https://docs.anthropic.com/en/api/messages
/v1/messages给定一个提示,该模型将返回一个或多个预测的完成,并且还可以返回每个位置的替代标记的概率。
为提供的提示和参数创建完成
官方文档:https://docs.anthropic.com/en/api/messages
curl -X POST https://top.qingyuntop.ai/v1/messages \
-H "Authorization: Bearer ${QINGYUN_TOP_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-20250514",
"system":"你是一个智能AI助手,叫小王",
"messages": [
{
"role": "user",
"content": "你是谁?!"
}
],
"stream":true
}'| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|---|
Content-Type | Header | string | 是 | - | application/json |
Accept | Header | string | 是 | - | application/json |
x-api-key | Header | string | 否 | - | {{YOUR_API_KEY}} |
model | JSON body | string | 是 | 要使用的模型的 ID。有关哪些模型可与聊天 API 一起使用的详细信息,请参阅模型端点兼容性表。 | - |
messages | JSON body | array<object> | 是 | 至今为止对话所包含的消息列表。Python 代码示例。 | - |
messages[].role | JSON body | string | 否 | - | - |
messages[].content | JSON body | string | 否 | - | - |
temperature | JSON body | integer | 否 | 使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或`top_p`但不是两者。 | - |
top_p | JSON body | integer | 否 | 一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或`temperature`但不是两者。 | - |
n | JSON body | integer | 否 | 默认为 1 为每个输入消息生成多少个聊天补全选择。 | - |
stream | JSON body | boolean | 否 | 默认为 false 如果设置,则像在 ChatGPT 中一样会发送部分消息增量。标记将以仅数据的服务器发送事件的形式发送,这些事件在可用时,并在 data: [DONE] 消息终止流。Python 代码示例。 | - |
stop | JSON body | string | 否 | 默认为 null 最多 4 个序列,API 将停止进一步生成标记。 | - |
max_tokens | JSON body | integer | 否 | 默认为 inf 在聊天补全中生成的最大标记数。 输入标记和生成标记的总长度受模型的上下文长度限制。计算标记的 Python 代码示例。 | - |
presence_penalty | JSON body | number | 否 | -2.0 和 2.0 之间的数字。正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性。 [查看有关频率和存在惩罚的更多信息。](https://platform.openai.com/docs/api-reference/parameter-details) | - |
frequency_penalty | JSON body | number | 否 | 默认为 0 -2.0 到 2.0 之间的数字。正值根据文本目前的存在频率惩罚新标记,降低模型重复相同行的可能性。 有关频率和存在惩罚的更多信息。 | - |
logit_bias | JSON body | null | 否 | 修改指定标记出现在补全中的可能性。 接受一个 JSON 对象,该对象将标记(由标记器指定的标记 ID)映射到相关的偏差值(-100 到 100)。从数学上讲,偏差在对模型进行采样之前添加到模型生成的 logit 中。确切效果因模型而异,但-1 和 1 之间的值应减少或增加相关标记的选择可能性;如-100 或 100 这样的值应导致相关标记的禁用或独占选择。 | - |
user | JSON body | string | 否 | 代表您的最终用户的唯一标识符,可以帮助 OpenAI 监控和检测滥用行为。[了解更多](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids)。 | - |
response_format | JSON body | object | 否 | 指定模型必须输出的格式的对象。 将 { "type": "json_object" } 启用 JSON 模式,这可以确保模型生成的消息是有效的 JSON。 重要提示:使用 JSON 模式时,还必须通过系统或用户消息指示模型生成 JSON。如果不这样做,模型可能会生成无休止的空白流,直到生成达到令牌限制,从而导致延迟增加和请求“卡住”的外观。另请注意,如果 finish_reason="length",则消息内容可能会被部分切断,这表示生成超过了 max_tokens 或对话超过了最大上下文长度。 显示属性 | - |
seen | JSON body | integer | 否 | 此功能处于测试阶段。如果指定,我们的系统将尽最大努力确定性地进行采样,以便使用相同的种子和参数进行重复请求应返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监控后端的更改。 | - |
tools | JSON body | array<string> | 是 | 模型可以调用的一组工具列表。目前,只支持作为工具的函数。使用此功能来提供模型可以为之生成 JSON 输入的函数列表。 | - |
tool_choice | JSON body | object | 是 | 控制模型调用哪个函数(如果有的话)。none 表示模型不会调用函数,而是生成消息。auto 表示模型可以在生成消息和调用函数之间进行选择。通过 {"type": "function", "function": {"name": "my_function"}} 强制模型调用该函数。 如果没有函数存在,默认为 none。如果有函数存在,默认为 auto。 显示可能的类型 | - |
| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|---|
id | 响应 JSON | string | 是 | - | - |
object | 响应 JSON | string | 是 | - | - |
created | 响应 JSON | integer | 是 | - | - |
choices | 响应 JSON | array<object> | 是 | - | - |
choices[].index | 响应 JSON | integer | 否 | - | - |
choices[].message | 响应 JSON | object | 否 | - | - |
choices[].message.role | 响应 JSON | string | 是 | - | - |
choices[].message.content | 响应 JSON | string | 是 | - | - |
choices[].finish_reason | 响应 JSON | string | 否 | - | - |
usage | 响应 JSON | object | 是 | - | - |
usage.prompt_tokens | 响应 JSON | integer | 是 | - | - |
usage.completion_tokens | 响应 JSON | integer | 是 | - | - |
usage.total_tokens | 响应 JSON | integer | 是 | - | - |
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}以下内容来自 Apifox 快照,可能包含兼容层字段或旧示例;公开调用请以本页的协议说明和当前模型列表为准。
{
"id": 497673432,
"name": "创建聊天补全 (流式)",
"type": "http",
"serverId": "",
"preProcessors": [],
"postProcessors": [],
"inheritPreProcessors": {},
"inheritPostProcessors": {},
"description": "给定一个提示,该模型将返回一个或多个预测的完成,并且还可以返回每个位置的替代标记的概率。\n\n为提供的提示和参数创建完成\n\n官方文档:https://docs.anthropic.com/en/api/messages\n",
"operationId": "",
"sourceUrl": "",
"method": "post",
"path": "/v1/messages",
"tags": [],
"status": 1,
"requestBody": {
"type": "application/json",
"parameters": [],
"jsonSchema": {
"type": "object",
"properties": {
"model": {
"type": "string",
"description": "要使用的模型的 ID。有关哪些模型可与聊天 API 一起使用的详细信息,请参阅模型端点兼容性表。\n\n"
},
"messages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
},
"x-apifox-orders": [
"role",
"content"
]
},
"description": "至今为止对话所包含的消息列表。Python 代码示例。"
},
"temperature": {
"type": "integer",
"description": "使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或`top_p`但不是两者。"
},
"top_p": {
"type": "integer",
"description": "一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或`temperature`但不是两者。"
},
"n": {
"type": "integer",
"description": "默认为 1\n为每个输入消息生成多少个聊天补全选择。"
},
"stream": {
"type": "boolean",
"description": "默认为 false 如果设置,则像在 ChatGPT 中一样会发送部分消息增量。标记将以仅数据的服务器发送事件的形式发送,这些事件在可用时,并在 data: [DONE] 消息终止流。Python 代码示例。"
},
"stop": {
"type": "string",
"description": "默认为 null 最多 4 个序列,API 将停止进一步生成标记。"
},
"max_tokens": {
"type": "integer",
"description": "默认为 inf\n在聊天补全中生成的最大标记数。\n\n输入标记和生成标记的总长度受模型的上下文长度限制。计算标记的 Python 代码示例。"
},
"presence_penalty": {
"type": "number",
"description": "-2.0 和 2.0 之间的数字。正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性。 [查看有关频率和存在惩罚的更多信息。](https://platform.openai.com/docs/api-reference/parameter-details)"
},
"frequency_penalty": {
"type": "number",
"description": "默认为 0 -2.0 到 2.0 之间的数字。正值根据文本目前的存在频率惩罚新标记,降低模型重复相同行的可能性。 有关频率和存在惩罚的更多信息。"
},
"logit_bias": {
"type": "null",
"description": "修改指定标记出现在补全中的可能性。\n\n接受一个 JSON 对象,该对象将标记(由标记器指定的标记 ID)映射到相关的偏差值(-100 到 100)。从数学上讲,偏差在对模型进行采样之前添加到模型生成的 logit 中。确切效果因模型而异,但-1 和 1 之间的值应减少或增加相关标记的选择可能性;如-100 或 100 这样的值应导致相关标记的禁用或独占选择。"
},
"user": {
"type": "string",
"description": "代表您的最终用户的唯一标识符,可以帮助 OpenAI 监控和检测滥用行为。[了解更多](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids)。"
},
"response_format": {
"type": "object",
"properties": {},
"x-apifox-orders": [],
"description": "指定模型必须输出的格式的对象。 将 { \"type\": \"json_object\" } 启用 JSON 模式,这可以确保模型生成的消息是有效的 JSON。 重要提示:使用 JSON 模式时,还必须通过系统或用户消息指示模型生成 JSON。如果不这样做,模型可能会生成无休止的空白流,直到生成达到令牌限制,从而导致延迟增加和请求“卡住”的外观。另请注意,如果 finish_reason=\"length\",则消息内容可能会被部分切断,这表示生成超过了 max_tokens 或对话超过了最大上下文长度。 显示属性"
},
"seen": {
"type": "integer",
"description": "此功能处于测试阶段。如果指定,我们的系统将尽最大努力确定性地进行采样,以便使用相同的种子和参数进行重复请求应返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监控后端的更改。"
},
"tools": {
"type": "array",
"items": {
"type": "string"
},
"description": "模型可以调用的一组工具列表。目前,只支持作为工具的函数。使用此功能来提供模型可以为之生成 JSON 输入的函数列表。"
},
"tool_choice": {
"type": "object",
"properties": {},
"description": "控制模型调用哪个函数(如果有的话)。none 表示模型不会调用函数,而是生成消息。auto 表示模型可以在生成消息和调用函数之间进行选择。通过 {\"type\": \"function\", \"function\": {\"name\": \"my_function\"}} 强制模型调用该函数。 如果没有函数存在,默认为 none。如果有函数存在,默认为 auto。 显示可能的类型",
"x-apifox-orders": []
}
},
"required": [
"model",
"messages",
"tools",
"tool_choice"
],
"x-apifox-orders": [
"model",
"messages",
"temperature",
"top_p",
"n",
"stream",
"stop",
"max_tokens",
"presence_penalty",
"frequency_penalty",
"logit_bias",
"user",
"response_format",
"seen",
"tools",
"tool_choice"
]
},
"examples": [
{
"value": "{\n \"model\": \"claude-sonnet-4-20250514\",\n \"system\":\"你是一个智能AI助手,叫小王\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你是谁?!\"\n }\n ],\n \"stream\":true\n }",
"mediaType": "application/json",
"description": ""
}
],
"mediaType": "",
"oasExtensions": "",
"required": false,
"additionalContentTypes": []
},
"parameters": {
"path": [],
"query": [],
"cookie": [],
"header": [
{
"id": "NQs7bxnpZf",
"name": "Content-Type",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "application/json"
},
{
"id": "qb8tEQbCty",
"name": "Accept",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "application/json"
},
{
"id": "gBxcCbXhsa",
"name": "x-api-key",
"required": false,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "{{YOUR_API_KEY}}"
}
]
},
"commonParameters": {
"query": [],
"body": [],
"cookie": [],
"header": []
},
"auth": {},
"responses": [
{
"id": 194333382,
"name": "OK",
"code": 200,
"contentType": "json",
"jsonSchema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"object": {
"type": "string"
},
"created": {
"type": "integer"
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {
"type": "integer"
},
"message": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
},
"required": [
"role",
"content"
],
"x-apifox-orders": [
"role",
"content"
]
},
"finish_reason": {
"type": "string"
}
},
"x-apifox-orders": [
"index",
"message",
"finish_reason"
]
}
},
"usage": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "integer"
},
"completion_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
},
"required": [
"prompt_tokens",
"completion_tokens",
"total_tokens"
],
"x-apifox-orders": [
"prompt_tokens",
"completion_tokens",
"total_tokens"
]
}
},
"required": [
"id",
"object",
"created",
"choices",
"usage"
],
"x-apifox-orders": [
"id",
"object",
"created",
"choices",
"usage"
]
},
"itemSchema": {},
"description": "",
"mediaType": "",
"headers": [],
"oasExtensions": ""
}
],
"responseExamples": [
{
"name": "OK",
"responseId": 194333382,
"data": "{\n \"id\": \"chatcmpl-123\",\n \"object\": \"chat.completion\",\n \"created\": 1677652288,\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"\\n\\nHello there, how may I assist you today?\"\n },\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 9,\n \"completion_tokens\": 12,\n \"total_tokens\": 21\n }\n}",
"description": "",
"oasKey": "",
"oasExtensions": "",
"id": "019fd25e-4bec-7266-8756-b167f6570ef4"
}
],
"codeSamples": [],
"projectId": 8662722,
"moduleId": 8310462,
"folderId": 92749358,
"ordering": 0,
"responsibleId": 0,
"commonResponseStatus": {},
"advancedSettings": {
"disabledSystemHeaders": {},
"isDefaultUrlEncoding": 1
},
"customApiFields": {},
"oasExtensions": "",
"mockScript": {},
"createdAt": "2026-08-05T14:40:23.000Z",
"updatedAt": "2026-08-06T12:15:55.000Z",
"creatorId": 2863449,
"editorId": 2863449,
"creatorUserId": 2863449,
"editorUserId": 2863449,
"responseChildren": [],
"visibility": "INHERITED",
"securityScheme": {},
"callbacks": ""
}