API 说明
FoxAPI 完全兼容 OpenAI API 格式,支持任何 OpenAI 兼容客户端。
API 地址
https://foxapi.chat认证
bash
Authorization: Bearer sk-你的KeyChat Completions
POST https://foxapi.chat/v1/chat/completions请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | ✅ | 模型名称 |
| messages | array | ✅ | 消息列表 |
| stream | boolean | ❌ | 流式输出,默认 false |
| temperature | number | ❌ | 温度 0-2,默认 1 |
| max_tokens | integer | ❌ | 最大输出 token |
请求示例
bash
curl https://foxapi.chat/v1/chat/completions \
-H "Authorization: Bearer sk-你的Key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4-mini",
"messages": [
{"role": "user", "content": "你好"}
]
}'Python 示例
python
from openai import OpenAI
client = OpenAI(
api_key="sk-你的Key",
base_url="https://foxapi.chat/v1"
)
response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{"role": "user", "content": "你好"}]
)
print(response.choices[0].message.content)Models
GET https://foxapi.chat/v1/models返回可用模型列表。
Images
文生图
POST https://foxapi.chat/v1/images/generations| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | ❌ | 默认 gpt-image-2 |
| prompt | string | ✅ | 图片描述 |
| n | integer | ❌ | 数量,默认 1 |
| size | string | ❌ | 尺寸,默认 1024x1024 |
bash
curl https://foxapi.chat/v1/images/generations \
-H "Authorization: Bearer sk-你的Key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "一只橘猫在阳光下打盹",
"size": "1024x1024"
}'图片编辑(上传参考图)
POST https://foxapi.chat/v1/images/edits使用参考图 + 文字描述来编辑图片,支持蒙版局部编辑。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | ❌ | 默认 gpt-image-2 |
| image | file | ✅ | 参考图片文件 |
| prompt | string | ✅ | 编辑描述 |
| mask | file | ❌ | 蒙版(白色=编辑区域) |
| n | integer | ❌ | 数量,默认 1 |
| size | string | ❌ | 尺寸,默认 1024x1024 |
bash
curl https://foxapi.chat/v1/images/edits \
-H "Authorization: Bearer sk-你的Key" \
-F "model=gpt-image-2" \
-F "image=@reference.png" \
-F "prompt=把背景改成海边日落"⚠️ 此接口使用
multipart/form-data格式,不是 JSON。 详细文档:图片编辑教程
异步接口
异步接口先提交任务再查询结果,返回真实图片链接(非 base64),不会超时。
POST https://foxapi.chat/async/images/generations
POST https://foxapi.chat/async/images/edits
GET https://foxapi.chat/task/{task_id}bash
# 提交任务
curl https://foxapi.chat/async/images/generations \
-H "Authorization: Bearer sk-你的Key" \
-F "model=gpt-image-2" \
-F "prompt=一只橘猫"
# 查询结果
curl https://foxapi.chat/task/{task_id}⚠️ 使用
multipart/form-data格式。 详细文档:异步图片生成
Billing(余额查询)
GET https://foxapi.chat/v1/dashboard/billing/subscription
GET https://foxapi.chat/v1/dashboard/billing/usage| 接口 | 说明 |
|---|---|
| /subscription | 查询账户状态和限额信息 |
| /usage?start_date=&end_date= | 查询指定时间段的已用额度 |
bash
# 查询账户信息
curl https://foxapi.chat/v1/dashboard/billing/subscription \
-H "Authorization: Bearer sk-你的Key"
# 查询已用额度
curl "https://foxapi.chat/v1/dashboard/billing/usage?start_date=2026-06-01&end_date=2026-06-07" \
-H "Authorization: Bearer sk-你的Key"详细文档:查询余额与用量
错误码
| 状态码 | 说明 | 解决方案 |
|---|---|---|
| 200 | 成功 | — |
| 401 | Key 无效 | 检查 Key 是否正确 |
| 403 | 余额不足 | 充值后再试 |
| 429 | 频率限制 | 稍后重试 |
| 500 | 服务器错误 | 联系客服 |