POST /api/redeem
使用后台生成的 API Key 鉴权,只需传入 Session。每次成功兑换消耗 Key 的 1 次额度,无需卡密。
请求头
Content-Type: application/json X-Api-Key: <后台生成的 API Key> # 或使用 Authorization: Bearer <API Key>
请求体
{
"session": "{...ChatGPT Session JSON...}"
}session 从 chatgpt.com/api/auth/session 复制完整 JSON 即可。
成功响应
HTTP 200
{ "ok": true, "email": "[email protected]" }失败响应
HTTP 4xx/5xx
{ "ok": false, "error": "card_used" }cURL 示例
curl -X POST https://your-domain.com/api/redeem \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{"session": "<paste session json>"}'GET /api/redeem/quota
查询 API Key 的额度使用情况,可用于前端展示余额或判断是否需要续费。
请求头
X-Api-Key: <后台生成的 API Key> # 或使用 Authorization: Bearer <API Key>
成功响应
HTTP 200
{
"ok": true,
"prefix": "gpt_sk_0rLJZ",
"note": "测试",
"quota": 100,
"used": 23,
"remaining": 77
}cURL 示例
curl https://your-domain.com/api/redeem/quota \ -H "X-Api-Key: YOUR_API_KEY"
额度与并发
API Key 控制可兑换次数,请求时原子扣减额度(FOR UPDATE 防并发超扣)
- 1. 请求到达 → 锁定 Key 并预扣 1 次额度
- 2. 加入工作区成功 → 保留扣减,记录使用邮箱
- 3. 加入失败 → 自动退还额度,可重试
- 4. Key 在控制台 API 对接 中创建与管理
错误码一览
| error | HTTP | 说明 |
|---|---|---|
| invalid_card | 400 | (仅网页接口)卡密不存在 |
| card_used | 409 | (仅网页接口)卡密已被使用 |
| card_processing | 409 | (仅网页接口)卡密正在处理中 |
| card_expired | 410 | (仅网页接口)卡密已过期 |
| email_not_allowed | 400 | 邮箱后缀不在允许范围内 |
| missing_token | 400 | Session 缺少 accessToken |
| invalid_session | 400 | Session 格式无效 |
| no_capacity | 503 | 工作区名额已满 |
| join_failed | 502 | 加入工作区失败(多为 Session 过期) |
| quota_exceeded | 403 | API Key 额度已用完 |
| too_many_requests | 429 | 请求过于频繁 |
| unauthorized | 401 | API Key 无效、已停用或未提供 |
| server_error | 500 | 服务器内部错误 |
网页兑换(参考)
POST /api/invite — 需 Cloudflare 验证码,面向网页用户
API Key 请在管理后台「API 对接」中生成,请勿泄露。