创建聊天对话
POST /v1/chat/completions
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
基本信息
| 项目 | 内容 |
|---|---|
| Base URL | https://www.yunzhuhub.cn |
| 标签 | OpenAI格式(Chat) |
| Operation ID | createChatCompletion |
认证
- BearerAuth:使用 Bearer Token 认证。 格式:
Authorization: Bearer sk-xxxxxx
密钥安全
请只使用你自己的 API Key。示例中的 <YOUR_API_KEY> 必须在本地替换,不要把真实密钥提交到代码仓库或发送给他人。
参数
无额外路径或查询参数。
请求体
Content-Type: application/json
json
{
"title": "ChatCompletionRequest",
"type": "object",
"required": [
"model",
"messages"
],
"properties": {
"model": {
"type": "string",
"description": "模型 ID",
"example": "<MODEL_ID>"
},
"messages": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Message"
},
"description": "对话消息列表"
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2,
"default": 1,
"description": "采样温度"
},
"top_p": {
"type": "number",
"minimum": 0,
"maximum": 1,
"default": 1,
"description": "核采样参数"
},
"n": {
"type": "integer",
"minimum": 1,
"default": 1,
"description": "生成数量"
},
"stream": {
"type": "boolean",
"default": false,
"description": "是否流式响应"
},
"stream_options": {
"type": "object",
"properties": {
"include_usage": {
"type": "boolean"
}
}
},
"stop": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"description": "停止序列"
},
"max_tokens": {
"type": "integer",
"description": "最大生成 Token 数"
},
"max_completion_tokens": {
"type": "integer",
"description": "最大补全 Token 数"
},
"presence_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"frequency_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"logit_bias": {
"type": "object",
"additionalProperties": {
"type": "number"
},
"properties": {}
},
"user": {
"type": "string"
},
"tools": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Tool"
}
},
"tool_choice": {
"oneOf": [
{
"type": "string",
"enum": [
"none",
"auto",
"required"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
]
},
"response_format": {
"$ref": "#/components/schemas/ResponseFormat"
},
"seed": {
"type": "integer"
},
"reasoning_effort": {
"type": "string",
"enum": [
"low",
"medium",
"high"
],
"description": "推理强度 (用于支持推理的模型)"
},
"modalities": {
"type": "array",
"items": {
"type": "string",
"enum": [
"text",
"audio"
]
}
},
"audio": {
"type": "object",
"properties": {
"voice": {
"type": "string"
},
"format": {
"type": "string"
}
}
}
}
}请求示例
以下示例只用于复制到本地终端,不会从文档站发送请求。
bash
curl --request POST 'https://www.yunzhuhub.cn/v1/chat/completions' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data '<REQUEST_JSON>'响应
200 成功创建响应
json
{
"title": "ChatCompletionResponse",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"object": {
"type": "string",
"example": "chat.completion"
},
"created": {
"type": "integer"
},
"model": {
"type": "string"
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {
"type": "integer"
},
"message": {
"$ref": "#/components/schemas/Message"
},
"finish_reason": {
"type": "string",
"enum": [
"stop",
"length",
"tool_calls",
"content_filter"
]
}
}
}
},
"usage": {
"$ref": "#/components/schemas/Usage"
},
"system_fingerprint": {
"type": "string"
}
}
}400 请求参数错误
json
{
"title": "ErrorResponse",
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "错误信息"
},
"type": {
"type": "string",
"description": "错误类型"
},
"param": {
"type": "string",
"description": "相关参数",
"nullable": true
},
"code": {
"type": "string",
"description": "错误代码",
"nullable": true
}
}
}
}
}429 请求频率限制
json
{
"title": "ErrorResponse",
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "错误信息"
},
"type": {
"type": "string",
"description": "错误类型"
},
"param": {
"type": "string",
"description": "相关参数",
"nullable": true
},
"code": {
"type": "string",
"description": "错误代码",
"nullable": true
}
}
}
}
}