模型 API / 对话 Completions
对话 Completions
更新时间:2026-02-18
接口说明
生成对话式文本回复,兼容 OpenAI Chat Completions 规范。支持流式输出、工具调用、结构化输出(JSON Mode)。
POST
/chat/completions请求参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 必需 | 模型 ID,如 doubao-seed-2-0-lite-260215、deepseek-v3 |
| messages | array | 必需 | 对话消息列表。每条消息包含 role 与 content 字段 |
| temperature | number | 可选 | 采样温度,取值 [0.0, 2.0],默认 1.0。越高越有创造力 |
| top_p | number | 可选 | 核采样,取值 [0.0, 1.0],默认 1.0 |
| max_tokens | integer | 可选 | 最大生成 Token 数,默认 4096,最大依模型而定 |
| stream | boolean | 可选 | 是否流式输出,默认 false |
| tools | array | 可选 | Function Calling 工具列表,遵循 OpenAI tools schema |
| response_format | object | 可选 | 输出格式,支持 { type: "json_object" } 开启 JSON 模式 |
调用示例
curl -X POST "https://www.tokenwell.com.cn/v1/chat/completions" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"model": "doubao-seed-2-0-lite-260215","messages": [{"role": "user", "content": "用一句话解释量子纠缠"}]}'
流式响应
当 stream 设为 true 时,服务端返回 Server-Sent Events (SSE) 流,每条事件是一个增量 delta。
curl -X POST "https://www.tokenwell.com.cn/v1/chat/completions" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"model": "doubao-seed-2-0-lite-260215","messages": [{"role": "user", "content": "你好"}],"stream": true}'
Function Calling
通过 tools 参数传入函数定义,模型会在需要时返回 tool_calls,由业务侧执行函数并回填结果。
JSON
{"tool_calls": [{"id": "call_abc123","type": "function","function": {"name": "get_weather","arguments": "{\"city\": \"杭州\"}"}}]}
没有找到想看的内容?联系我们 →