统一接口
简介
文本、图片、视频生成、爆款复刻、配音生成和社交数据查询共用同一个对外入口:type 选择能力,model 选择已发布的模型,input 与 parameters 承载该类型的字段。这是唯一的公开接口:所有能力(包括社交读取)都只切换 type 和各自的输入字段。
1. 请求信封
BASH
curl -X POST https://api.anycap.io/v1/generations \ -H "Authorization: Bearer $ANYCAP_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "type": "video_edit", "model": "<来自 GET /v1/generations/models?type=video_edit 的模型>", "input": { "video_file_id": "<自有源视频文件 id>", "prompt": "把桌上的商品替换成目标商品,保留镜头运动" }, "parameters": { "resolution": "480P", "ratio": "adaptive" } }'| type | input | parameters | 结果 |
|---|---|---|---|
text | messages 及任意 chat 字段 | temperature、max_tokens 等 chat 参数 | 200,同步返回 output |
image | prompt 及发现接口列出的模型字段 | 尺寸、质量、数量等模型字段 | 202,返回 job |
video | prompt、image_url、last_frame_url、自有 reference_*_file_ids | resolution、ratio、duration、audio | 202,返回 job |
video_edit | video_file_id、prompt、自有 reference_*_file_ids | resolution、ratio、duration | 202,返回 job |
audio | prompt,以及 speaker 或自有 reference_audio_file_ids / reference_audio_urls / reference_image_file_id / reference_image_url 之一 | format、sample_rate、speech_rate、loudness_rate、pitch_rate、enable_subtitle、watermark | 202,返回 job |
social | Instagram:资料用 username,帖子列表用 username + operation: posts,帖子用 url + operation: post,评论用 url + operation: comments;TikTok:url | — | 200,同步返回 call,含有效期 2 小时的 Anycap 下载链接 media_downloads;仅上游结果未确认时返回 202 |
2. 发现模型
GET /v1/generations/models?type=text|image|video|video_edit|audio|social 返回当前密钥可调用的模型;items 与各能力发现接口返回的对象一致,价格、限额和可接受字段完全相同。
3. 读取与取消媒体任务
GET /v1/generations/{id}对图片、视频、爆款复刻和配音返回{type, job},对社交查询返回{type, call};加?result=true获取最终媒体地址。DELETE /v1/generations/{id}只能取消尚未提交上游计费调用的视频/爆款复刻任务;图片和配音任务不可取消,返回 400。- 轮询到
completed、failed或pending;202不代表上游成功或已结算。
4. 错误与幂等
- 校验失败返回标准
{error:{code,field,message}},在提交前拦截,不扣费。 - 媒体任务请传
Idempotency-Key(或idempotency_key):重复 key 返回已记录任务,不会重复提交;文本重试也用同一个请求头。 - 图片报价与提交在一次调用内完成;校验失败不会创建预留,也不会扣费。
下一篇文本生成