所有需鉴权的接口在 Header 携带 X-API-Key。在控制台「API KEY」页面创建 KEY。
X-API-Key: ak_xxxxxxxxxxxxxxxx
POST /api/v1/upload
multipart/form-data,字段 file,≤10MB,jpg/png/webp
{
"code": 0,
"data": { "url": "https://.../up_xxx.jpg" }
}
POST /api/v1/avatar/generate
{
"image": "https://.../your-photo.jpg",
"sub_user_id": "user_123",
"style_id": 1,
"color_id": 2,
"shape_id": 1,
"is_public": true
}
返回 record_id,配合查询接口轮询结果
POST /api/v1/avatar/generate-sync
multipart/form-data:file 为图片文件(≤10MB,jpg/png/webp),其余参数以表单字段提交(style_id/color_id/shape_id/is_public/sub_user_id)。无需先上传再轮询,一次请求直接返回头像地址。生成约需数秒~数十秒,客户端超时请设 ≥120s。
curl -X POST https://你的域名/api/v1/avatar/generate-sync \ -H "X-API-Key: ak_xxxx" \ -F "file=@/path/to/photo.jpg" \ -F "style_id=1" \ -F "is_public=1"
{
"code": 0,
"data": {
"record_id": 100,
"status": "success",
"avatar_id": 1001,
"url": "https://.../result.png",
"thumb_url": "https://.../thumb.png",
"audit_status": "approved",
"cost_points": 10,
"remaining_points": 90
}
}
生成失败会自动退还积分并返回 502;审核驳回时 audit_status=rejected 且积分退还。
GET /api/v1/avatar/generate/{record_id}
{
"code": 0,
"data": {
"record_id": 100,
"status": "success",
"avatar_id": 1001,
"url": "https://.../result.png",
"thumb_url": "https://.../thumb.png",
"cost_points": 10
}
}
GET /api/v1/avatar/random | 公共池随机头像,支持 style_id/color_id/shape_id/count |
GET /api/v1/key/info | 当前 KEY 信息(名称、额度) |
GET /api/v1/key/avatars | KEY 下头像列表,可按 sub_user_id 筛选 |
GET /api/v1/key/sub-users/{sid}/avatars | 子用户头像历史 |
GET /api/v1/user/points | 用户积分余额 |
GET /api/v1/configs | 风格/颜色/形状配置(无需鉴权) |
| 0 | 成功 |
| 4001 | 参数错误 |
| 4002 | 鉴权失败 |
| 4003 | 积分不足/禁止访问 |
| 4006 | 图片未通过审核(违规或非人物头像图,HTTP 422) |
| 4029 | 限流(QPS/日限额超限) |
| 4004 | 资源不存在 |
| 5000 | 服务端错误 |
| 5002 | 同步生成失败(积分已自动退还) |