大模型 API 中转平台

📡 API 调用

POST /api/call.php

平台根据请求体自动识别格式,纯透传到对应端点:

请求体和响应体不做任何转换,原封不动转发。

请求头

参数名 必填 说明
X-API-Key 用户的API Key,从管理员处获取
Content-Type application/json

OpenAI 格式请求示例

{
  "model": "MiniMax-M2.7",
  "messages": [
    {"role": "user", "content": "你好"}
  ],
  "stream": false
}

Anthropic 格式请求示例

{
  "model": "MiniMax-M2.7",
  "max_tokens": 4096,
  "system": "你是一个AI助手",
  "messages": [
    {"role": "user", "content": "你好"}
  ]
}

成功响应(非流式 stream=false)

// 直接透传上游 API 原始响应,不做任何包装
// OpenAI 端点返回 OpenAI 格式响应
// Anthropic 端点返回 Anthropic 格式响应

成功响应(流式 stream=true)

Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive

// 实时转发上游 SSE 数据流

队列工作原理:平台始终启用队列,通过 MySQL 锁自动检测上游连接状态。空闲时请求直接透传(零延迟),有并发时自动排队(按用户优先级排序)。队列满时返回 503。

排队响应(上游繁忙时 HTTP 202)

{
  "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 状态检查

GET /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
  }
}

📊 查询排队状态

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

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

Python

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())

JavaScript (Node.js)

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);
提示:如果你还没有API Key,请联系系统管理员获取。