📚 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

  1. 登录用户面板:http://localhost:8000/public/dashboard.html
  2. 在「令牌管理」页面查看当前 API Key
  3. 如需重新生成,点击「重新生成」按钮

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

请求参数:

参数类型必填说明
emailstring邮箱地址
passwordstring密码(至少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 请求参数

参数类型必填说明
modelstring模型 ID,如 gpt-4o
messagesarray消息数组
streamboolean是否开启流式输出
temperaturefloat温度参数 0-2,默认 0.7
max_tokensinteger最大生成 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-4oOpenAI最强多模态模型
gpt-4o-miniOpenAI轻量级 GPT-4o
claude-3.5-sonnetAnthropic编程能力强
qwen-plus阿里云通义千问 Plus
deepseek-v3DeepSeekDeepSeek V3

4️⃣ 图片生成 API

4.1 接口地址

POST/api/v1/images/generations

4.2 请求参数

参数类型必填说明
modelstring模型 ID,默认 dall-e-3
promptstring图片描述
ninteger生成数量 1-10,默认 1
sizestring图片尺寸

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-3OpenAI$0.04最强图片生成
stable-diffusionStability AI$0.02开源可定制
qwen-vl阿里云$0.015中文提示词

5️⃣ 视频生成 API

5.1 接口地址

POST/api/v1/videos/generations

5.2 请求参数

参数类型必填说明
modelstring模型 ID,默认 gen-2
promptstring视频描述
durationinteger视频时长(秒),默认 10
aspect_ratiostring宽高比,默认 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-2Runway$0.15AI 视频生成
pika-1.0Pika 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: '你好'}]));