大模型 API 中转平台
/api/call.php
| 参数名 | 必填 | 说明 |
|---|---|---|
| X-API-Key | 是 | 用户的API Key,从管理员处获取 |
| Content-Type | 是 | application/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/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 -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!"}
]
}'
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())
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);