对话补全 (Chat)
豆包 Doubao 系列
豆包对话模型的 OpenAI 兼容调用方式
适用模型
| 模型 | 上下文 | 最大输出 |
|---|---|---|
Doubao1.5-pro-32k | 32,000 | 32,000 |
公开协议
火山方舟提供 OpenAI SDK 兼容调用方式,LoopToken沿用 POST /v1/chat/completions,客户端无需使用方舟的 Endpoint ID 或签名鉴权。
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.vibelab.me/v1',
apiKey: 'sk-lt-...',
});
const response = await client.chat.completions.create({
model: 'Doubao1.5-pro-32k',
messages: [{ role: 'user', content: '为这个产品写一段 100 字介绍' }],
});
console.log(response.choices[0].message.content);请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 固定为 Doubao1.5-pro-32k |
messages | array | 是 | - | 非空对话消息列表 |
messages[].role | string | 是 | - | system、user、assistant 或 tool |
messages[].content | string/array | 是 | - | 文本或模型支持的多模态内容块 |
stream | boolean | 否 | false | 是否启用 SSE 流式输出 |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数,不超过 32,000 |
temperature | number | 否 | 1 | 采样温度,范围 [0, 2) |
top_p | number | 否 | 1 | 核采样阈值,范围 (0, 1] |
stop | string/array | 否 | - | 停止序列 |
tools | array | 否 | - | 函数工具列表 |
tool_choice | string/object | 否 | auto | 工具调用策略 |
response_format | object | 否 | {"type":"text"} | 输出格式 |
响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
id | string | 请求 ID |
object | string | chat.completion 或流式 chunk 类型 |
created | integer | Unix 时间戳 |
model | string | 模型名称 |
choices[].index | integer | 候选结果序号 |
choices[].message | object | 非流式助手消息 |
choices[].delta | object | 流式增量消息 |
choices[].finish_reason | string | 停止原因 |
usage.prompt_tokens | integer | 输入 Token 数 |
usage.completion_tokens | integer | 输出 Token 数 |
usage.total_tokens | integer | 总 Token 数 |
{
"id": "chatcmpl_01H...",
"object": "chat.completion",
"created": 1783819200,
"model": "Doubao1.5-pro-32k",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "LoopToken 提供统一、稳定的大模型 API 调用体验。"},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 20, "completion_tokens": 18, "total_tokens": 38}
}错误响应格式及状态码见错误码。