Chat Completions
OpenAI 风格的 Chat Completions 接口用于发送一组消息并获得模型回复。请求地址保持 OpenAI 兼容形态,方便现有 SDK 或网关调用代码迁移。
请求地址
POST
鉴权方式
使用 Bearer Token 认证,在请求头中传入 API Key:
Authorization:Bearer YOUR_API_KEY
请求示例
传入 model 和 messages,并使用 Bearer Token 完成鉴权。
curl https://api.1xtoken.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "deepseek-v4-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'请求体示例
一个启用深度思考(thinking)的完整请求体:
{
"model": "deepseek-v4-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "证明根号 2 是无理数。"}
],
"thinking": {
"type": "enabled",
"budget_tokens": 4096
},
"stream": false
}请求字段
| Field | Type | Description |
|---|---|---|
| model | string | 模型 ID。 |
| messages | array<object> | 对话消息列表。 |
| temperature | number | 可选,默认 1,范围 0~2。采样温度,值越高随机性越强,值越低结果越稳定。 |
| top_p | number | 可选,默认 1,范围 0~1。核采样(Nucleus Sampling)参数,与 temperature 二选一调节即可。 |
| n | integer | 可选,默认 1,范围 >=1。生成的回复数量。 |
| stream | boolean | 可选,默认 false。是否启用流式响应。 |
| stream_options | object | 可选。流式响应相关配置。 |
| stop | string | array<string> | 可选。停止生成的结束标记,遇到指定内容时停止输出。 |
| max_tokens | integer | 可选。最大生成 Token 数(部分新模型已不推荐使用)。 |
| max_completion_tokens | integer | 可选。最大补全(输出)Token 数,推荐优先使用该参数。 |
| presence_penalty | number | 可选,默认 0,范围 -2~2。存在惩罚,值越高越倾向于引入新的话题。 |
| frequency_penalty | number | 可选,默认 0,范围 -2~2。频率惩罚,值越高越减少重复内容。 |
| logit_bias | object | 可选。调整指定 Token 的生成概率。 |
| user | string | 可选。最终用户标识,用于监控和滥用检测。 |
| tools | array<object> | 可选。可供模型调用的工具列表。 |
| tool_choice | string | object | 可选。指定模型如何选择工具调用。 |
| response_format | object | 可选。指定响应格式,例如 JSON 输出。 |
| seed | integer | 可选。随机种子,用于尽可能获得可复现的结果。 |
| thinking | object | 可选。深度思考(Thinking)配置,仅支持推理模型。见下方子字段。 |
| thinking.type | "enabled" | "disabled" | 是否启用深度思考。enabled 启用,disabled 禁用。 |
| thinking.budget_tokens | integer | 可选。深度思考预算 Token 数,仅 thinking.type=enabled 时生效。 |
| reasoning_effort | "low" | "medium" | "high" | 可选。推理强度,与 thinking 同义,建议优先使用 thinking。仅支持推理模型。 |
| modalities | array<string> | 可选。指定响应模态,例如 ["text"]、["text", "audio"]。 |
| audio | object | 可选。音频输出相关配置,当 modalities 包含 "audio" 时使用。 |
thinking 字段说明
thinking 用于控制深度思考(扩展思考链),结构与 Anthropic Messages 接口保持一致:
"thinking": {
"type": "enabled", // enabled 启用深度思考,disabled 禁用
"budget_tokens": 0 // 深度思考预算 Token 数,type=enabled 时生效
}
响应字段
| Field | Type | Description |
|---|---|---|
| id | string | 本次补全的唯一标识。 |
| object | string | 对象类型,固定为 chat.completion。 |
| created | integer | 响应创建的 Unix 时间戳(秒)。 |
| model | string | 生成该响应所用的模型 ID。 |
| choices | array<object> | 补全结果列表,长度由请求 n 决定。 |
| choices[].index | integer | 该结果在 choices 中的下标。 |
| choices[].message | object | 助手消息对象,见下方子字段。 |
| choices[].message.role | string | 消息角色,固定为 assistant。 |
| choices[].message.content | string | 模型生成的正文内容。 |
| choices[].message.reasoning_content | string | 可选。深度思考内容,启用 thinking 时返回。 |
| choices[].message.tool_calls | array<object> | 可选。模型发起的工具调用列表。 |
| choices[].message.refusal | string | 可选。模型拒绝生成时的拒绝原因。 |
| choices[].finish_reason | string | 停止生成的原因,例如 stop、length、tool_calls、refusal。 |
| choices[].logprobs | object | null | 可选。所选 Token 的对数概率信息。 |
| choices[].matched_stop | any | 可选。触发停止的匹配标记。 |
| usage | object | 可选。本次请求的 Token 用量统计,见下方子字段。 |
| usage.prompt_tokens | integer | 输入(提示)Token 数。 |
| usage.completion_tokens | integer | 输出(补全)Token 数。 |
| usage.total_tokens | integer | 输入与输出 Token 总数。 |
| usage.prompt_tokens_details.cached_tokens | integer | 可选。命中缓存的输入 Token 数。 |
| usage.completion_tokens_details.reasoning_tokens | integer | 可选。深度思考消耗的 Token 数。 |
| service_tier | string | 可选。服务层级。 |
| metadata | object | 可选。请求时传入并原样回传的元数据。 |
响应示例
一个启用深度思考后的非流式响应,reasoning_content 为思考内容,reasoning_tokens 为思考消耗:
{
"id": "chatcmpl-1xtoken",
"object": "chat.completion",
"created": 1753305600,
"model": "deepseek-v4-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "要证明根号 2 是无理数,使用反证法……",
"content": "假设根号 2 是有理数,则可表示为最简分数 p/q……矛盾,故根号 2 为无理数。",
"tool_calls": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 180,
"total_tokens": 204,
"prompt_tokens_details": {
"cached_tokens": 8
},
"completion_tokens_details": {
"reasoning_tokens": 120
}
}
}