大模型 API 中转平台

📡 API 调用

POST /api/call.php

请求头

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

请求体 (JSON)

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {"role": "user", "content": "你好,请介绍一下自己"}
  ]
}

响应示例

{
  "success": true,
  "message": "请求成功",
  "data": {
    "response": {
      "id": "chatcmpl-xxx",
      "choices": [{
        "message": {
          "role": "assistant",
          "content": "你好!我是..."
        }
      }]
    },
    "usage": {
      "prompt_tokens": 20,
      "completion_tokens": 150,
      "total_tokens": 170
    },
    "daily_limits": {
      "requests": {"used": 5, "limit": 1000, "remaining": 995},
      "tokens": {"used": 5000, "limit": 100000, "remaining": 95000}
    }
  }
}

错误响应

{
  "success": false,
  "message": "每日请求次数已达上限",
  "data": {
    "daily_request_count": 1000,
    "daily_request_limit": 1000,
    "daily_token_count": 50000,
    "daily_token_limit": 100000
  }
}

🔍 API 状态检查

GET /api/status.php

无需API Key,可直接访问查看系统状态。

响应示例

{
  "success": true,
  "message": "OK",
  "data": {
    "status": "running",
    "api_key_configured": true,
    "queue_enabled": true,
    "stats": {
      "total_users": 10,
      "queue_length": 0,
      "processing": 0,
      "today_requests": 150,
      "today_tokens": 50000
    }
  }
}

📋 错误码说明

HTTP状态码 说明 解决方案
200 请求成功 -
400 请求参数错误 检查请求体格式是否正确
401 API Key无效或缺失 请提供有效的API Key
429 超出每日限额 等待次日零点重置或联系管理员调整限额
500 系统配置错误 联系管理员检查系统配置
502 大模型API调用失败 检查网络连接或稍后重试
503 队列已满 稍后重试

💡 使用示例

cURL

curl -X POST https://your-domain/api/call.php \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key-here" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Python

import requests

url = "https://your-domain/api/call.php"
headers = {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key-here"
}
data = {
    "model": "gpt-3.5-turbo",
    "messages": [
        {"role": "user", "content": "Hello!"}
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

JavaScript (Node.js)

const response = await fetch('https://your-domain/api/call.php', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key-here'
  },
  body: JSON.stringify({
    model: 'gpt-3.5-turbo',
    messages: [
      {role: 'user', content: 'Hello!'}
    ]
  })
});

const data = await response.json();
console.log(data);
提示:如果你还没有API Key,请联系系统管理员获取。