Volcengine 兼容
兼容火山方舟 OpenAI 兼容接口(v3 协议),可用于豆包 Seed 系列等走火山 v3 协议的模型。
POST
/api/v3/chat/completionsVolcengine 兼容
🔑
Bearer API Key请求头使用 Authorization: Bearer sk_live_...,也支持 x-api-key。
🧩
先确认模型调用名请先在 模型广场 筛选支持当前接口格式的模型,打开模型详情页复制调用名。当前账号的最终可用范围还受组织权限影响。
请求结构
下方内容用于确认方法、地址和鉴权方式,属于 HTTP 结构片段,不是可独立执行示例。
HTTP
POST https://www.silvamux.com/api/v3/chat/completions
Authorization: Bearer $SILVAMUX_API_KEY
Content-Type: application/json请求体
application/json · OpenAIChatRequest · 必填
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
max_tokens | integer | 否 | 生成的最大 token 数;达到限制时输出可能被截断。 |
messages | array<Message> | 是 | 对话消息列表(按时间顺序,至少一条),提供完整上下文。 |
messages.content | string | array<ContentPart> | 是 | 消息内容:纯文本字符串或多模态分段数组(图片 / 音频)。不能只包含 system 或 assistant 消息。 |
messages.name | string | 否 | 参与者名称(可选)。 |
messages.role | string (system | user | assistant | tool) | 是 | 消息角色:system 设定行为与人设,user 用户输入,assistant 模型回复,tool 工具执行结果。 |
messages.tool_call_id | string | 否 | role=tool 时对应的工具调用 ID。 |
messages.tool_calls | array<ToolCall> | 否 | 模型发起的工具调用(出现在 assistant 历史消息中)。 |
messages.tool_calls.function | object | 是 | — |
messages.tool_calls.function.arguments | string | 是 | JSON 编码的函数参数。 |
messages.tool_calls.function.name | string | 是 | 函数名。 |
messages.tool_calls.id | string | 是 | 工具调用 ID。 |
messages.tool_calls.type | string (function) | 是 | — |
model | string | 是 | SilvaMux 模型调用名(id 或 alias)。从模型广场模型详情页复制;账号最终可用范围还受组织权限影响。 |
response_format | object | 否 | 输出格式:text(默认,普通文本)或 json_object(JSON 模式)。 |
response_format.type | string (text | json_object) | 否 | — |
stop | string | array<string> | 否 | 停止词:生成文本出现这些字符串时立即停止,最多 4 个。 |
stream | boolean | 否 | 是否启用流式输出(SSE)。false:完整生成后一次性返回;true:实时返回生成内容,结束时以 data: [DONE] 标记(客户端不应仅依赖该标记判断完成)。;默认值:false |
temperature | number | 否 | 采样温度,控制输出随机性:值越高越发散,越低越稳定。建议只调整 temperature 或 top_p 之一。 |
tool_choice | string (auto | none) | object | 否 | 工具选择策略:auto(默认,模型自行决定)/ none(禁用)/ 指定函数对象。 |
tools | array<Tool> | 否 | 可供模型调用的函数定义列表(Function Calling)。 |
tools.function | object | 是 | — |
tools.function.description | string | 否 | 函数用途描述,帮助模型决定是否调用。 |
tools.function.name | string | 是 | 函数名。 |
tools.function.parameters | object | 否 | 函数参数的 JSON Schema。 |
tools.type | string (function) | 是 | — |
top_p | number | 否 | 核采样参数,temperature 的替代方案。 |
user | string | 否 | 终端用户标识符,用于滥用检测。 |
响应
200OpenAI Chat JSON 或 SSE 响应。
application/json · OpenAIChatResponse
| 字段 | 类型 | 说明 |
|---|---|---|
choices | array<OpenAIChatChoice> | 候选响应列表。 |
choices.finish_reason | string (stop | length | tool_calls | content_filter) | 结束原因:stop 自然结束;length 达到 max_tokens;tool_calls 需执行工具;content_filter 触发内容过滤。 |
choices.index | integer | 候选序号。 |
choices.message | object | 助手消息。 |
choices.message.content | string | 生成的文本内容;仅工具调用时可为空。 |
choices.message.reasoning_content | string | 思考过程内容(支持思考模式的模型返回)。 |
choices.message.role | string (assistant | tool) | — |
choices.message.tool_calls | array<ToolCall> | 模型发起的工具调用。 |
choices.message.tool_calls.function | object | — |
choices.message.tool_calls.id | string | 工具调用 ID。 |
choices.message.tool_calls.type | string (function) | — |
created | integer | 创建时间(Unix 秒)。 |
id | string | 请求 ID。 |
model | string | 实际使用的模型名。 |
object | string | 对象类型(如 chat.completion)。 |
usage | Usage | Token 用量统计;兼容入口可能透传厂商扩展字段。 |
usage.completion_tokens | integer | 输出 token 数。 |
usage.prompt_tokens | integer | 输入 token 数。 |
usage.total_tokens | integer | 总 token 数。 |
defaultVolcengine 兼容错误。
application/json · VolcengineError
| 字段 | 类型 | 说明 |
|---|---|---|
error | FreeFormObject | — |
示例
curl https://www.silvamux.com/api/v3/chat/completions \
-H "Authorization: Bearer $SILVAMUX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seed-2.0-pro",
"messages": [{"role": "user", "content": "你好"}]
}'
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["SILVAMUX_API_KEY"],
base_url="https://www.silvamux.com/api/v3",
)
response = client.chat.completions.create(
model="doubao-seed-2.0-pro",
messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)
// npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.SILVAMUX_API_KEY,
baseURL: "https://www.silvamux.com/api/v3",
});
const response = await client.chat.completions.create({
model: "doubao-seed-2.0-pro",
messages: [{ role: "user", content: "你好" }],
});
console.log(response.choices[0].message.content);
// 仅依赖标准库
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload := []byte(`{
"model": "doubao-seed-2.0-pro",
"messages": [{"role": "user", "content": "你好"}]
}`)
req, err := http.NewRequest("POST", "https://www.silvamux.com/api/v3/chat/completions", bytes.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SILVAMUX_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
https://www.silvamux.com/api/v3即接入域名下的/api/v3,对应路由/api/v3/chat/completions。鉴权使用 SilvaMux API Key,不是火山 AK/SK。