SilvaMux Unified Entry
An optional cross-protocol unified entry. It accepts the OpenAI Chat format, picks the upstream automatically based on model, and normalizes responses, SSE, and errors into the OpenAI Chat format. Useful when you want to call models across protocols through a single endpoint.
POST
/api/v0/chat/completionsSilvaMux 统一入口
可选的跨协议统一入口。按 model 选择上游,并将响应、SSE 和错误统一为 OpenAI Chat 格式。
🔑
Bearer API KeyUse the Authorization: Bearer sk_live_... header; x-api-key is also supported.
🧩
Confirm the model call name firstFirst filter models that support this endpoint format on the Models page, then open a model detail page to copy its call name. Your account's final availability also depends on organization permissions.
Request structure
The section below confirms the method, URL and authentication scheme. It is an HTTP structure snippet, not a standalone runnable example.
HTTP
POST https://www.silvamux.com/api/v0/chat/completions
Authorization: Bearer $SILVAMUX_API_KEY
Content-Type: application/jsonRequest body
application/json · OpenAIChatRequest · Required
| Field | Type | Required | Description |
|---|---|---|---|
max_tokens | integer | No | 生成的最大 token 数;达到限制时输出可能被截断。 |
messages | array<Message> | Yes | 对话消息列表(按时间顺序,至少一条),提供完整上下文。 |
messages.content | string | array<ContentPart> | Yes | 消息内容:纯文本字符串或多模态分段数组(图片 / 音频)。不能只包含 system 或 assistant 消息。 |
messages.name | string | No | 参与者名称(可选)。 |
messages.role | string (system | user | assistant | tool) | Yes | 消息角色:system 设定行为与人设,user 用户输入,assistant 模型回复,tool 工具执行结果。 |
messages.tool_call_id | string | No | role=tool 时对应的工具调用 ID。 |
messages.tool_calls | array<ToolCall> | No | 模型发起的工具调用(出现在 assistant 历史消息中)。 |
messages.tool_calls.function | object | Yes | — |
messages.tool_calls.function.arguments | string | Yes | JSON 编码的函数参数。 |
messages.tool_calls.function.name | string | Yes | 函数名。 |
messages.tool_calls.id | string | Yes | 工具调用 ID。 |
messages.tool_calls.type | string (function) | Yes | — |
model | string | Yes | SilvaMux 模型调用名(id 或 alias)。从模型广场模型详情页复制;账号最终可用范围还受组织权限影响。 |
response_format | object | No | 输出格式:text(默认,普通文本)或 json_object(JSON 模式)。 |
response_format.type | string (text | json_object) | No | — |
stop | string | array<string> | No | 停止词:生成文本出现这些字符串时立即停止,最多 4 个。 |
stream | boolean | No | 是否启用流式输出(SSE)。false:完整生成后一次性返回;true:实时返回生成内容,结束时以 data: [DONE] 标记(客户端不应仅依赖该标记判断完成)。;Default: false |
temperature | number | No | 采样温度,控制输出随机性:值越高越发散,越低越稳定。建议只调整 temperature 或 top_p 之一。 |
tool_choice | string (auto | none) | object | No | 工具选择策略:auto(默认,模型自行决定)/ none(禁用)/ 指定函数对象。 |
tools | array<Tool> | No | 可供模型调用的函数定义列表(Function Calling)。 |
tools.function | object | Yes | — |
tools.function.description | string | No | 函数用途描述,帮助模型决定是否调用。 |
tools.function.name | string | Yes | 函数名。 |
tools.function.parameters | object | No | 函数参数的 JSON Schema。 |
tools.type | string (function) | Yes | — |
top_p | number | No | 核采样参数,temperature 的替代方案。 |
user | string | No | 终端用户标识符,用于滥用检测。 |
Response
200OpenAI Chat JSON 或 SSE 响应。
application/json · OpenAIChatResponse
| Field | Type | Description |
|---|---|---|
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 数。 |
defaultOpenAI 兼容错误。
application/json · OpenAIError
| Field | Type | Description |
|---|---|---|
error | object | — |
error.code | string | integer | — |
error.message | string | — |
error.type | string | — |
Examples
curl https://www.silvamux.com/api/v0/chat/completions \
-H "Authorization: Bearer $SILVAMUX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "minimax-m2.5",
"messages": [{"role": "user", "content": "Hello"}]
}'
# 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/v0",
)
response = client.chat.completions.create(
model="minimax-m2.5",
messages=[{"role": "user", "content": "Hello"}],
)
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/v0",
});
const response = await client.chat.completions.create({
model: "minimax-m2.5",
messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content);
// Standard library only
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload := []byte(`{
"model": "minimax-m2.5",
"messages": [{"role": "user", "content": "Hello"}]
}`)
req, err := http.NewRequest("POST", "https://www.silvamux.com/api/v0/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))
}
⚠️
The unified entry normalizes request and response structures. When you need vendor-specific fields, events, or response shapes, prefer the corresponding vendor protocol compatible entry.