OpenAI 兼容 API
完全兼容 OpenAI SDK,只需替换 Base URL 和 API Key 即可无缝迁移。支持 Chat Completions、Completions 两种接口。下方端点点击可展开查看参数、7 语言代码示例与响应,并支持在线测试。
https://router.shengsuanyun.com/apiAuthorization: Bearer YOUR_API_KEY端点列表
POST/chat/completionsopenai兼容接口聊天
本接口支持聊天补全、与AI模型进行多轮对话。胜算云为模型路由提供了自动路由、提供商路由两种选择。 工具调用允许模型根据上下文选择一个或多个外部函数。模型不会直接执行函数,而是返回工具调用意图和 JSON 参数;业务代码执行函数后,再把结果作为 `role: tool` 消息发回模型。真实请求地址仍是 `POST /v1/chat/completions`; 胜算云还提供联网搜索功能。您只需在请求体里增加 "online_search": true 即可启用搜索功能。
请求体 · 必填
application/json
| 字段 | 类型 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
model必填 | string | 模型 ID,格式为 provider/model-name。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
messages必填 | array | 多轮对话消息列表。展开结构多轮对话消息列表。
数组元素
| |||||||||||||||||||||||||||||||||||||||||||||||||||
stream | boolean | 是否使用 SSE 流式响应。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
stream_options | object | 流式输出选项,仅在 stream=true 时生效。展开结构流式输出选项,仅在 stream=true 时生效。
| |||||||||||||||||||||||||||||||||||||||||||||||||||
online_search | boolean | 是否启用联网搜索。默认使用博查 AI 搜索。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
online_search_options | object | 联网搜索选项。展开结构联网搜索选项。
| |||||||||||||||||||||||||||||||||||||||||||||||||||
max_tokens | integer | 限制模型生成的最大 token 数。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
max_completion_tokens | integer | 限制 reasoning 模型生成 completion 的最大 token 数。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
temperature | number | 采样温度。值越高输出越随机。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
top_p | number | 核采样阈值。通常不建议和 temperature 同时调整。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
stop | union | 遇到指定字符串时停止生成。展开结构遇到指定字符串时停止生成。
oneOf · 1
oneOf · 2
数组元素
| |||||||||||||||||||||||||||||||||||||||||||||||||||
n | integer | 生成多个候选回复。部分模型支持。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
frequency_penalty | number | 降低重复用词概率。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
presence_penalty | number | 提高模型讨论新主题的倾向。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
response_format | object | 展开结构
| |||||||||||||||||||||||||||||||||||||||||||||||||||
tools | array | 模型可调用的工具列表。展开结构模型可调用的工具列表。
数组元素
| |||||||||||||||||||||||||||||||||||||||||||||||||||
tool_choice | union | 控制模型是否调用工具。展开结构控制模型是否调用工具。
oneOf · 1
oneOf · 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
parallel_tool_calls | boolean | 是否允许模型在一轮响应中并行返回多个工具调用。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
auto_route | boolean | 是否自动路由模型供应商。 | |||||||||||||||||||||||||||||||||||||||||||||||||||
supplier | string | 当 auto_route=false 时指定供应商。 可选值:"DeepSeek" · "Bytedance" · "OpenRouter" · "Ali" | |||||||||||||||||||||||||||||||||||||||||||||||||||
reasoning | object | 控制支持推理模型的思考模式。展开结构控制支持推理模型的思考模式。
|
{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "user",
"content": "上海今天适合夜跑吗?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name, e.g. Shanghai"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
},
"strict": true
}
}
],
"tool_choice": "auto",
"parallel_tool_calls": true
}请求示例
参考地址:https://router.shengsuanyun.com/api/v1。路径参数与凭据需替换;非 JSON 请求体需按对应格式准备。
curl -X POST 'https://router.shengsuanyun.com/api/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "user",
"content": "上海今天适合夜跑吗?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name, e.g. Shanghai"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
},
"strict": true
}
}
],
"tool_choice": "auto",
"parallel_tool_calls": true
}'响应
200 模型返回普通消息或工具调用
application/json
未提供结构定义。
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"tool_calls": [
{
"id": "call_weather_1",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": "{\"location\":\"上海\",\"unit\":\"celsius\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}POST/completionsCompletions
补全兼容入口。胜算云当前该入口使用 messages 数组提交内容;如需标准 OpenAI legacy prompt 续写,请优先使用 Chat Completions 迁移。
请求体 · 必填
application/json
| 字段 | 类型 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
model必填 | string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
messages必填 | array | 消息数组。当前 /v1/completions 兼容入口按 messages 请求体运行。展开结构消息数组。当前 /v1/completions 兼容入口按 messages 请求体运行。
数组元素
| |||||||||||||||||||||||||||||||||||||||||||||||||||
max_tokens | integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||
stream | boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||
temperature | number |
{
"model": "deepseek/deepseek-v4-flash",
"messages": [
{
"role": "user",
"content": "请只回复 OK。"
}
],
"max_tokens": 8
}请求示例
参考地址:https://router.shengsuanyun.com/api/v1。路径参数与凭据需替换;非 JSON 请求体需按对应格式准备。
curl -X POST 'https://router.shengsuanyun.com/api/v1/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
--data '{
"model": "deepseek/deepseek-v4-flash",
"messages": [
{
"role": "user",
"content": "请只回复 OK。"
}
],
"max_tokens": 8
}'响应
200 成功响应
400 请求格式错误
401 认证失败
GET/models获取模型列表
获取当前账号可用的所有模型列表。常用于验证 API Key 是否有效。
请求示例
参考地址:https://router.shengsuanyun.com/api/v1。路径参数与凭据需替换;非 JSON 请求体需按对应格式准备。
curl -X GET 'https://router.shengsuanyun.com/api/v1/models' \
-H 'Authorization: Bearer YOUR_API_KEY'响应
200 模型列表
application/json
未提供结构定义。
{
"object": "list",
"data": [
{
"id": "deepseek/deepseek-v4-flash",
"object": "model",
"owned_by": "deepseek"
},
{
"id": "anthropic/claude-sonnet-4.6",
"object": "model",
"owned_by": "anthropic"
}
]
}401 认证失败
POST/responsesResponses
统一响应接口,适合通用 Agent、Codex / Research 类模型、工具调用、联网搜索和需要跨轮次状态的任务。 与 OpenAI 官方 Responses API 一致:使用 `input` 表达用户输入,使用 `tools` 声明可用工具,返回 `output` 数组和文本输出。 仅支持 `/v1/responses` 的模型也会在实时模型列表中显示。
请求体 · 必填
application/json
| 字段 | 类型 | 说明 | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
model必填 | string | 支持 /v1/responses 的模型 ID。 | |||||||||||||||||||||
input必填 | union | 用户输入。可以是字符串,也可以是包含角色与内容的输入数组。展开结构用户输入。可以是字符串,也可以是包含角色与内容的输入数组。
oneOf · 1
oneOf · 2
数组元素
| |||||||||||||||||||||
instructions | string | 开发者/系统级指令。 | |||||||||||||||||||||
previous_response_id | string | 上一轮 response id,用于延续上下文。 | |||||||||||||||||||||
stream | boolean | 是否使用流式响应。 | |||||||||||||||||||||
tools | array | 可用工具。支持函数工具和官方内置工具,如 web_search_preview。展开结构可用工具。支持函数工具和官方内置工具,如 web_search_preview。
数组元素
oneOf · 1
oneOf · 2
| |||||||||||||||||||||
tool_choice | union | 控制工具选择。展开结构控制工具选择。
oneOf · 1
oneOf · 2
| |||||||||||||||||||||
temperature | number | ||||||||||||||||||||||
top_p | number | ||||||||||||||||||||||
max_output_tokens | integer | 最大输出 token 数。OpenAI Responses 当前最小值通常为 16。 | |||||||||||||||||||||
text | object | 文本输出配置,包括 JSON schema 输出格式。展开结构文本输出配置,包括 JSON schema 输出格式。
|
{
"model": "openai/gpt-5.2",
"input": "请阅读这个仓库的 README,并给出迁移到 Responses API 的改造清单。",
"max_output_tokens": 64,
"stream": false
}请求示例
参考地址:https://router.shengsuanyun.com/api/v1。路径参数与凭据需替换;非 JSON 请求体需按对应格式准备。
curl -X POST 'https://router.shengsuanyun.com/api/v1/responses' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-5.2",
"input": "请阅读这个仓库的 README,并给出迁移到 Responses API 的改造清单。",
"max_output_tokens": 64,
"stream": false
}'响应
200 成功响应
application/json
| 字段 | 类型 | 说明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | string | |||||||||||||
object | string | 可选值:"response" | ||||||||||||
model | string | |||||||||||||
output | array | 展开结构
数组元素
| ||||||||||||
output_text | string | |||||||||||||
usage | object | 展开结构
|
{
"id": "resp_xxx",
"object": "response",
"model": "openai/gpt-5.2",
"output_text": "可以,下面是迁移清单...",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "可以,下面是迁移清单..."
}
]
}
],
"usage": {
"input_tokens": 120,
"output_tokens": 320,
"total_tokens": 440
}
}400 请求格式错误
401 认证失败
404 模型不存在或不支持 /v1/responses
429 频率限制
POST/embeddingsEmbeddings
文本向量化接口。将字符串或字符串数组转换为 embedding 向量,常用于语义检索、RAG、聚类、推荐和相似度计算。
请求体 · 必填
application/json
| 字段 | 类型 | 说明 |
|---|---|---|
model必填 | string | Embedding 模型 ID。已验证可用示例:openai/text-embedding-3-small。 可选值:"openai/text-embedding-3-small" · "openai/text-embedding-3-large" · "text-embedding-3-small" |
input必填 | union | 待向量化文本。展开结构待向量化文本。
oneOf · 1
oneOf · 2
数组元素
|
encoding_format | string | 返回向量编码格式。 |
dimensions | integer | 向量维度,部分模型支持。 |
{
"model": "openai/text-embedding-3-small",
"input": "如何使用 torchserve 部署模型"
}请求示例
参考地址:https://router.shengsuanyun.com/api/v1。路径参数与凭据需替换;非 JSON 请求体需按对应格式准备。
curl -X POST 'https://router.shengsuanyun.com/api/v1/embeddings' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
--data '{
"model": "openai/text-embedding-3-small",
"input": "如何使用 torchserve 部署模型"
}'响应
200 成功响应
application/json
| 字段 | 类型 | 说明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | string | 可选值:"list" | ||||||||||||
data | array | 展开结构
数组元素
| ||||||||||||
model | string | |||||||||||||
usage | object | 展开结构
|
{
"object": "list",
"model": "openai/text-embedding-3-small",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
-0.0142,
-0.0095,
-0.0469
]
}
],
"usage": {
"prompt_tokens": 13,
"total_tokens": 13
}
}