📚 API 开发文档
AutoList Token - 统一 API 代理平台接口说明
1️⃣ 认证说明
1.1 获取 API Key
所有 API 调用都需要认证,有两种方式传递 API Key:
方式一:Authorization Header(推荐)
Authorization: Bearer YOUR_API_KEY
方式二:X-API-Key Header
X-API-Key: YOUR_API_KEY
1.2 获取 API Key
- 登录用户面板:
http://localhost:8000/public/dashboard.html - 在「令牌管理」页面查看当前 API Key
- 如需重新生成,点击「重新生成」按钮
1.3 登录状态
会话认证(用于前端页面)
- 登录后服务器会设置 session cookie
- 前端通过
credentials: 'include'自动携带 cookie - 登录状态有效期取决于服务器配置
API Key 认证(用于程序调用)
- 每个用户拥有独立的 API Key
- API Key 可以随时在用户面板重新生成
- API Key 认证不依赖 session
2️⃣ 用户 API
2.1 用户注册
POST/api/auth.php?action=register
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 邮箱地址 | |
| password | string | 是 | 密码(至少6位) |
请求示例:
{
"email": "user@example.com",
"password": "your_password"
}响应示例:
{
"success": true,
"message": "注册成功",
"data": {
"user": {
"id": "uuid",
"email": "user@example.com",
"balance": 10.00,
"api_key": "tk_xxxxxxxx",
"status": "active"
}
}
}2.2 用户登录
POST/api/auth.php?action=login
2.3 获取用户资料
GET/api/user.php?action=profile
2.4 充值
POST/api/user.php?action=charge
2.5 获取交易记录
GET/api/user.php?action=transactions
3️⃣ 文本生成 API
OpenAI 兼容的 Chat Completions API。
3.1 接口地址
POST/api/v1/chat/completions
3.2 请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID,如 gpt-4o |
| messages | array | 是 | 消息数组 |
| stream | boolean | 否 | 是否开启流式输出 |
| temperature | float | 否 | 温度参数 0-2,默认 0.7 |
| max_tokens | integer | 否 | 最大生成 token 数 |
3.3 请求示例
cURL
curl -X POST http://localhost:8000/api/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好"}
]
}'Python
import requests
response = requests.post(
'http://localhost:8000/api/v1/chat/completions',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json={
'model': 'gpt-4o',
'messages': [{'role': 'user', 'content': '你好'}]
}
)
print(response.json())JavaScript
fetch('http://localhost:8000/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [{role: 'user', content: '你好'}]
})
})
.then(response => response.json())
.then(data => console.log(data));3.4 支持的模型
| 模型 ID | 提供商 | 说明 |
|---|---|---|
| gpt-4o | OpenAI | 最强多模态模型 |
| gpt-4o-mini | OpenAI | 轻量级 GPT-4o |
| claude-3.5-sonnet | Anthropic | 编程能力强 |
| qwen-plus | 阿里云 | 通义千问 Plus |
| deepseek-v3 | DeepSeek | DeepSeek V3 |
4️⃣ 图片生成 API
4.1 接口地址
POST/api/v1/images/generations
4.2 请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 否 | 模型 ID,默认 dall-e-3 |
| prompt | string | 是 | 图片描述 |
| n | integer | 否 | 生成数量 1-10,默认 1 |
| size | string | 否 | 图片尺寸 |
4.3 请求示例
cURL
curl -X POST http://localhost:8000/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "dall-e-3", "prompt": "一只可爱的橘猫", "size": "1024x1024"}'Python
import requests
response = requests.post(
'http://localhost:8000/api/v1/images/generations',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json={'model': 'dall-e-3', 'prompt': '一只可爱的橘猫'}
)
print(response.json()['data'][0]['url'])4.4 支持的模型
| 模型 ID | 提供商 | 价格/张 | 说明 |
|---|---|---|---|
| dall-e-3 | OpenAI | $0.04 | 最强图片生成 |
| stable-diffusion | Stability AI | $0.02 | 开源可定制 |
| qwen-vl | 阿里云 | $0.015 | 中文提示词 |
5️⃣ 视频生成 API
5.1 接口地址
POST/api/v1/videos/generations
5.2 请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 否 | 模型 ID,默认 gen-2 |
| prompt | string | 是 | 视频描述 |
| duration | integer | 否 | 视频时长(秒),默认 10 |
| aspect_ratio | string | 否 | 宽高比,默认 16:9 |
5.3 请求示例
cURL
curl -X POST http://localhost:8000/api/v1/videos/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "gen-2", "prompt": "海浪拍打沙滩", "duration": 10}'5.4 支持的模型
| 模型 ID | 提供商 | 价格/次 | 说明 |
|---|---|---|---|
| gen-2 | Runway | $0.15 | AI 视频生成 |
| pika-1.0 | Pika Labs | $0.10 | 多种风格 |
6️⃣ 错误码说明
6.1 HTTP 状态码
| 状态码 | 说明 |
|---|---|
| 200 | 请求成功 |
| 400 | 请求参数错误 |
| 401 | 未提供 API Key 或 API Key 无效 |
| 402 | 余额不足 |
| 403 | 账户被禁用 |
| 404 | 模型或资源不存在 |
| 429 | 请求过于频繁 |
| 500 | 服务器内部错误 |
| 502 | 上游 API 错误 |
7️⃣ SDK 代码示例
7.1 Python SDK
import requests
class TokenProxy:
def __init__(self, api_key, base_url="http://localhost:8000"):
self.api_key = api_key
self.base_url = base_url
self.headers = {"Authorization": f"Bearer {api_key}"}
def chat(self, model, messages):
return requests.post(
f"{self.base_url}/api/v1/chat/completions",
headers=self.headers,
json={"model": model, "messages": messages}
).json()
def generate_image(self, prompt, model="dall-e-3"):
return requests.post(
f"{self.base_url}/api/v1/images/generations",
headers=self.headers,
json={"model": model, "prompt": prompt}
).json()
def generate_video(self, prompt, model="gen-2"):
return requests.post(
f"{self.base_url}/api/v1/videos/generations",
headers=self.headers,
json={"model": model, "prompt": prompt},
timeout=300
).json()
# 使用
client = TokenProxy("YOUR_API_KEY")
print(client.chat("gpt-4o", [{"role": "user", "content": "你好"}]))7.2 JavaScript SDK
class TokenProxy {
constructor(apiKey, baseUrl = 'http://localhost:8000') {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
this.headers = {'Authorization': `Bearer ${apiKey}`};
}
async chat(model, messages) {
const res = await fetch(`${this.baseUrl}/api/v1/chat/completions`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({model, messages})
});
return res.json();
}
async generateImage(prompt) {
const res = await fetch(`${this.baseUrl}/api/v1/images/generations`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({prompt})
});
return res.json();
}
}
// 使用
const client = new TokenProxy('YOUR_API_KEY');
console.log(await client.chat('gpt-4o', [{role: 'user', content: '你好'}]));