创建聊天补全 qwen-mt-turbo
POST/v1/chat/completions 创建聊天补全(qwen-mt-turbo)
使用与 OpenAI API 兼容的聊天补全接口调用 qwen-mt-turbo 模型。该接口会根据输入的对话消息生成模型回复,适用于机器翻译、文本改写及多轮对话等场景。
POST https://www.vortapapi.com/v1/chat/completions
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | 请求体格式,通常为 application/json |
Accept | 是 | 响应格式,通常为 application/json |
Authorization | 否 | API 鉴权信息,格式为 Bearer sk-*** |
X-Forwarded-Host | 否 | 可选的转发 Host 信息 |
请求示例
curl https://www.vortapapi.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "qwen-mt-turbo",
"messages": [
{
"role": "user",
"content": "请将下面的内容翻译成英文:你好,请问今天有什么可以帮您?"
}
]
}'
响应示例
{
"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
}
}
响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 本次聊天补全请求的唯一标识 |
object | string | 对象类型,聊天补全响应通常为 chat.completion |
created | integer | 响应创建时间,Unix 时间戳格式 |
choices | array | 模型生成的候选结果列表 |
choices[].index | integer | 当前候选结果在列表中的序号 |
choices[].message | object | 模型返回的消息内容 |
choices[].message.role | string | 消息角色,通常为 assistant |
choices[].message.content | string | 模型生成的文本内容 |
choices[].finish_reason | string | 生成结束原因,例如 stop |
usage | object | Token 使用统计 |
usage.prompt_tokens | integer | 输入消息消耗的 Token 数 |
usage.completion_tokens | integer | 输出内容消耗的 Token 数 |
usage.total_tokens | integer | 本次请求消耗的 Token 总数 |