mixgateway.io 网关 · 快速开始
概述
mixgateway.io 提供与 OpenAI 兼容的 HTTP API,让你通过统一入口访问多家模型供应商(如 DeepSeek、OpenAI 等)。
- Base URL:
https://api.mixgateway.io/v1 - 对话补全:
POST /chat/completions - 鉴权:
Authorization: Bearer {api_key} - 协议:与 OpenAI
chat/completions大体兼容
获取 API Key
- 在 [控制台](/dashboard) 注册并登录。
- 打开 API 密钥管理,创建新密钥。
- 复制生成的
sk-...字符串(或你们网关实际使用的密钥格式)。 - 每次请求在请求头携带:
Authorization: Bearer {api_key}。
安全提示:不要将密钥写进前端打包代码或公开仓库,应放在服务端配置或密钥管理中。
非流式请求示例
curl https://api.mixgateway.io/v1/chat/completions \
-H "Authorization: Bearer sk-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek:deepseek-chat",
"messages": [
{"role": "user", "content": "Hi,只用一句话回复 Hi"}
],
"temperature": 0.7,
"max_tokens": 128,
"stream": false
}'
响应示例
{
"id": "1a9f9f27-ef53-4b0e-8849-465bf8270314",
"object": "chat.completion",
"created": 1772183892,
"model": "deepseek:deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 1,
"total_tokens": 9
}
}
请求里的
model常使用provider:modelId(例如deepseek:deepseek-chat),网据此路由到对应上游。具体可用模型以控制台或供应商文档为准。
流式请求示例
curl https://api.mixgateway.io/v1/chat/completions \
-H "Authorization: Bearer sk-xxxx" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "deepseek:deepseek-chat",
"messages": [
{"role": "user", "content": "用一句话介绍你自己"}
],
"temperature": 0.7,
"max_tokens": 256,
"stream": true
}'
典型的 SSE 数据形如:
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hi"}}], ...}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":",我是网关助手。"}}], ...}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":""},"finish_reason":"stop"}], "usage":{"prompt_tokens":13,"completion_tokens":10,"total_tokens":23}}
最后一条 chunk 可能带有 usage,用于计费与用量统计。
多语言示例
JavaScript(Node.js,fetch)
const resp = await fetch("https://api.mixgateway.io/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer sk-xxxx",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "deepseek:deepseek-chat",
messages: [{ role: "user", content: "Hi" }],
stream: false,
}),
});
const data = await resp.json();
console.log(data.choices[0].message.content);
Python(requests)
import requests
url = "https://api.mixgateway.io/v1/chat/completions"
headers = {
"Authorization": "Bearer sk-xxxx",
"Content-Type": "application/json",
}
json_data = {
"model": "deepseek:deepseek-chat",
"messages": [{"role": "user", "content": "Hi"}],
"stream": False,
}
resp = requests.post(url, headers=headers, json=json_data, timeout=30)
data = resp.json()
print(data["choices"][0]["message"]["content"])
错误格式
接口多采用 OpenAI 风格的错误结构,例如:
{
"error": {
"message": "Incorrect API key provided. For details",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
},
"request_id": "9f6b3bb8-9328-91ad-a5b7-1feed430211b"
}
常见 code:
invalid_api_key— 密钥无效、缺失或已被吊销。model_not_found— 请求的model在本网关未配置或不可用。insufficient_quota或余额相关错误 — 配额或预付费余额不足。