大模型 API 中转平台
/api/call.php
平台根据请求体自动识别格式,纯透传到对应端点:
system 字段)→ OpenAI 兼容端点system 字段)→ Anthropic 兼容端点请求体和响应体不做任何转换,原封不动转发。
| 参数名 | 必填 | 说明 |
|---|---|---|
| X-API-Key | 是 | 用户的API Key,从管理员处获取 |
| Content-Type | 是 | application/json |
{
"model": "MiniMax-M2.7",
"messages": [
{"role": "user", "content": "你好"}
],
"stream": false
}
{
"model": "MiniMax-M2.7",
"max_tokens": 4096,
"system": "你是一个AI助手",
"messages": [
{"role": "user", "content": "你好"}
]
}
// 直接透传上游 API 原始响应,不做任何包装 // OpenAI 端点返回 OpenAI 格式响应 // Anthropic 端点返回 Anthropic 格式响应
Content-Type: text/event-stream Cache-Control: no-cache Connection: keep-alive // 实时转发上游 SSE 数据流
队列工作原理:平台始终启用队列,通过 MySQL 锁自动检测上游连接状态。空闲时请求直接透传(零延迟),有并发时自动排队(按用户优先级排序)。队列满时返回 503。
{
"success": true,
"queued": true,
"queue_id": 123,
"message": "请求已进入队列,请通过 /api/queue_status.php 查询处理状态"
}
{
"success": false,
"message": "今日请求次数已达上限",
"data": {
"request_limit": 1000,
"request_used": 1000
},
"code": 429
}
/api/status.php
无需API Key,可直接访问查看系统状态。
{
"status": "healthy",
"timestamp": "2026-05-11 12:00:00",
"checks": {
"database": { "status": "connected", "message": "Database connection OK" },
"api_key": { "status": "configured", "message": "API key is configured" },
"api_urls": { "status": "configured", "message": { "openai": "https://api.minimaxi.com/...", "anthropic": "not configured" } },
"disk": { "status": "ok", "usage_percent": 29.0, "free_bytes": 12345678901 }
},
"stats": {
"active_users": 5,
"total_users": 10,
"queue_length": 0,
"processing": 0,
"today_requests": 150,
"today_tokens": 50000,
"today_errors": 2
},
"config": {
"ssl_verify": false,
"request_timeout": 60
}
}
/api/queue_status.php?queue_id=123
队列始终启用,客户端通过此接口查询处理进度和获取响应结果。
{
"success": true,
"queue_id": 123,
"status": "waiting",
"position": 3,
"total_waiting": 10,
"added_at": "2026-05-12 10:00:00"
}
{
"success": true,
"queue_id": 123,
"status": "completed",
"added_at": "2026-05-12 10:00:00",
"completed_at": "2026-05-12 10:00:05",
"response": { /* 上游大模型原始响应 */ }
}
{
"success": true,
"queue_id": 123,
"status": "failed",
"added_at": "2026-05-12 10:00:00",
"completed_at": "2026-05-12 10:00:10",
"error_message": "Connection timeout"
}
| HTTP状态码 | 说明 | 解决方案 |
|---|---|---|
| 200 | 请求成功 | - |
| 400 | 请求参数错误 | 检查请求体格式是否正确 |
| 401 | API Key无效或缺失 | 请提供有效的API Key |
| 429 | 超出每日限额 | 等待次日零点重置或联系管理员调整限额 |
| 500 | 系统配置错误 | 联系管理员检查系统配置 |
| 502 | 大模型API调用失败 | 检查网络连接或稍后重试 |
| 503 | 队列已满 | 稍后重试 |
curl -X POST /api/call.php \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key-here" \
-d '{
"model": "MiniMax-M2.7",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'
import requests
url = "/api/call.php"
headers = {
"Content-Type": "application/json",
"X-API-Key": "your-api-key-here"
}
data = {
"model": "MiniMax-M2.7",
"messages": [
{"role": "user", "content": "Hello!"}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch('/api/call.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key-here'
},
body: JSON.stringify({
model: 'MiniMax-M2.7',
messages: [
{role: 'user', content: 'Hello!'}
]
})
});
const data = await response.json();
console.log(data);