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/completions

SilvaMux 统一入口

可选的跨协议统一入口。按 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/json

Request body

application/json · OpenAIChatRequest · Required

FieldTypeRequiredDescription
max_tokensintegerNo生成的最大 token 数;达到限制时输出可能被截断。
messagesarray<Message>Yes对话消息列表(按时间顺序,至少一条),提供完整上下文。
messages.contentstring | array<ContentPart>Yes消息内容:纯文本字符串或多模态分段数组(图片 / 音频)。不能只包含 system 或 assistant 消息。
messages.namestringNo参与者名称(可选)。
messages.rolestring (system | user | assistant | tool)Yes消息角色:system 设定行为与人设,user 用户输入,assistant 模型回复,tool 工具执行结果。
messages.tool_call_idstringNorole=tool 时对应的工具调用 ID。
messages.tool_callsarray<ToolCall>No模型发起的工具调用(出现在 assistant 历史消息中)。
messages.tool_calls.functionobjectYes—
messages.tool_calls.function.argumentsstringYesJSON 编码的函数参数。
messages.tool_calls.function.namestringYes函数名。
messages.tool_calls.idstringYes工具调用 ID。
messages.tool_calls.typestring (function)Yes—
modelstringYesSilvaMux 模型调用名(id 或 alias)。从模型广场模型详情页复制;账号最终可用范围还受组织权限影响。
response_formatobjectNo输出格式:text(默认,普通文本)或 json_object(JSON 模式)。
response_format.typestring (text | json_object)No—
stopstring | array<string>No停止词:生成文本出现这些字符串时立即停止,最多 4 个。
streambooleanNo是否启用流式输出(SSE)。false:完整生成后一次性返回;true:实时返回生成内容,结束时以 data: [DONE] 标记(客户端不应仅依赖该标记判断完成)。;Default: false
temperaturenumberNo采样温度,控制输出随机性:值越高越发散,越低越稳定。建议只调整 temperature 或 top_p 之一。
tool_choicestring (auto | none) | objectNo工具选择策略:auto(默认,模型自行决定)/ none(禁用)/ 指定函数对象。
toolsarray<Tool>No可供模型调用的函数定义列表(Function Calling)。
tools.functionobjectYes—
tools.function.descriptionstringNo函数用途描述,帮助模型决定是否调用。
tools.function.namestringYes函数名。
tools.function.parametersobjectNo函数参数的 JSON Schema。
tools.typestring (function)Yes—
top_pnumberNo核采样参数,temperature 的替代方案。
userstringNo终端用户标识符,用于滥用检测。

Response

200OpenAI Chat JSON 或 SSE 响应。

application/json · OpenAIChatResponse

FieldTypeDescription
choicesarray<OpenAIChatChoice>候选响应列表。
choices.finish_reasonstring (stop | length | tool_calls | content_filter)结束原因:stop 自然结束;length 达到 max_tokens;tool_calls 需执行工具;content_filter 触发内容过滤。
choices.indexinteger候选序号。
choices.messageobject助手消息。
choices.message.contentstring生成的文本内容;仅工具调用时可为空。
choices.message.reasoning_contentstring思考过程内容(支持思考模式的模型返回)。
choices.message.rolestring (assistant | tool)—
choices.message.tool_callsarray<ToolCall>模型发起的工具调用。
choices.message.tool_calls.functionobject—
choices.message.tool_calls.idstring工具调用 ID。
choices.message.tool_calls.typestring (function)—
createdinteger创建时间(Unix 秒)。
idstring请求 ID。
modelstring实际使用的模型名。
objectstring对象类型(如 chat.completion)。
usageUsageToken 用量统计;兼容入口可能透传厂商扩展字段。
usage.completion_tokensinteger输出 token 数。
usage.prompt_tokensinteger输入 token 数。
usage.total_tokensinteger总 token 数。

defaultOpenAI 兼容错误。

application/json · OpenAIError

FieldTypeDescription
errorobject—
error.codestring | integer—
error.messagestring—
error.typestring—

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"}]
  }'
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.