API 文档 · 火山 V3 兼容接口
方舟兼容接口
已按火山方舟写好的代码只换地址和密钥接入:视频任务、素材库、真人认证。
已经按火山方舟(Volcano Ark)写好的代码或平台,可以只换地址和密钥接入本平台:请求、响应的结构与方舟相同,计费与 /v1 接口完全一样。新接入建议直接用 /v1。
地址与鉴权
| 用途 | 本平台 | 鉴权 |
|---|---|---|
| 视频任务(推理面) | https://api.aitoken.tools/api/v3 | Authorization: Bearer <API Key> |
| 素材库、真人认证(管控面) | https://api.aitoken.tools/?Action=…&Version=2024-01-01(SDK 里主机名填 api.aitoken.tools,Region ap-southeast-1,Service ark) | AccessKey 按火山 V4 签名:AccessKeyId 在控制台“API Key”页查看(AKAT…),SecretAccessKey 就是这把 API Key 本身;也可以直接用 Bearer API Key |
从官方迁移只改三处:Base URL / 主机名、密钥、已有素材重新导入一次(你自己火山账号下素材库里的素材 ID 在本平台不能用)。
视频任务
| 方舟接口 | 说明 |
|---|---|
POST /api/v3/contents/generations/tasks | 创建,返回 { "id": "task_…" } |
GET /api/v3/contents/generations/tasks/{id} | 查询,返回方舟的任务结构,另附本平台字段 aitoken(扣费金额、实际模型) |
GET /api/v3/contents/generations/tasks | 列表:page_num、page_size(≤ 500,默认 10)、filter.status、filter.task_ids、filter.model |
DELETE /api/v3/contents/generations/tasks/{id} | 暂不支持取消或删除 |
model:本平台的模型名或官方模型 ID(如 dreamina-seedance-2-0-260128)都可以;推理接入点 ep-… 不能用。content:图片、视频、音频的 url 可以是 http(s) 链接(平台当场导入,同一链接复用,放进“方舟接口自动导入”分组)、data:…;base64,…(图片 ≤ 30 MB、音频 ≤ 15 MB、视频 ≤ 10 MB;整个请求体 ≤ 64 MiB)或 asset://asset_…(本平台素材)。图片没写 role 时:一张按首帧,两张按首帧 + 尾帧,更多张请写明 role。- 默认值与方舟一致:resolution 720p、duration 5;有图片输入时 ratio 为 adaptive,否则 16:9。watermark、seed、generate_audio 等模型参数原样传;模型不支持的参数返回 400。
- 方舟没有幂等键:请求头带 Idempotency-Key 就按它去重;网络超时后请先查询,不要直接重发。callback_url 回调的内容是方舟的任务结构。
素材库
支持的 Action(参数与结果字段同方舟素材库;ID 是本平台格式):
CreateAssetGroup GetAssetGroup ListAssetGroups UpdateAssetGroup DeleteAssetGroup CreateAsset GetAsset ListAssets UpdateAsset DeleteAsset
素材组的 GroupType 与方舟一致:普通素材组是 AIGC,真人分组是 LivenessFace(此前返回的是 RealPerson,按这个值判断的代码请改掉)。CreateAssetGroup 的 GroupType 只接受 AIGC(可不填),其他值返回 400;真人分组要通过 CreateVisualValidateSession 创建。ListAssetGroups 支持 Filter.GroupType(AIGC / LivenessFace,其他值返回 400)和 Filter.GroupIds。
素材使用流程
CreateAsset按 URL 创建素材。返回的Result.Id(asset_…)就是素材 ID,后面查询和引用都用它;Name 只是名称,不能当 ID 用。素材是异步导入的,创建成功时就会返回 Id。POST /?Action=CreateAsset&Version=2024-01-01 { "GroupId": "grp_xxx", "URL": "https://example.com/role-a.png", "AssetType": "Image", "Name": "role-a" }{ "ResponseMetadata": { "RequestId": "req_xxx", "Action": "CreateAsset", … }, "Result": { "Id": "asset_xxx" } }- 用
GetAsset查状态:Status为 Active 才能用;Processing 继续等(一般几秒),Failed 看 FailReason。POST /?Action=GetAsset&Version=2024-01-01 { "Id": "asset_xxx" }{ "ResponseMetadata": { … }, "Result": { "Id": "asset_xxx", "Name": "role-a", "Status": "Active", "AssetType": "Image", "GroupId": "grp_xxx", "URL": "https://…" } } - 生成视频时在 content[] 里用
asset://<Result.Id>引用(图片的 role 按用途写 first_frame / last_frame / reference_image):{ "type": "image_url", "image_url": { "url": "asset://asset_xxx" }, "role": "reference_image" }
不想管素材库的话,也可以在 content[] 里直接给图片的 http(s) 链接,平台会当场导入(见上一节)。
真人认证
CreateVisualValidateSession:返回 H5Link、BytedToken(本平台的认证 ID,auth_…)和 GroupId(为这次认证新建的真人分组)。可选参数 Model 指定模型,不填时按你已开通的模型自动选择。可选参数 CallbackURL(http 或 https 的完整地址,不带用户名密码,最长 2048 字符)是认证完成后要回到的页面。- 把 H5Link 交给本人刷脸,30 分钟内有效。完成后浏览器会跳到你传的 CallbackURL,并带上两个查询参数:bytedToken(本平台的认证 ID auth_…,与 CreateVisualValidateSession 返回的 BytedToken 相同)和 resultCode(上游的结果码,10000 表示通过,可能没有)。收到跳转后请用这个 bytedToken 调 GetVisualValidateResult 确认结果,不要只凭 resultCode 判断;跳转到达时结果可能还没出来,返回 Processing 就每隔 5 秒以上再查,直到 Success 或 Failed(个别线路要几分钟)。个别线路刷脸后不会回到 CallbackURL,所以即使传了 CallbackURL,也请保留轮询作为兜底。没传 CallbackURL 时页面停在本站的提示页,请轮询 GetVisualValidateResult。
GetVisualValidateResult:Status 为 Success 时返回 GroupId;Processing 表示还没完成。- 用 CreateAsset 往这个 GroupId 里加本人的照片:自动按真人素材处理,可用后即可在任务里使用。认证通过前往分组加素材会被拒绝。
与方舟官方的差异
- 任务、素材、分组、认证的 ID 都是本平台格式(task_…、asset_…、grp_…、auth_…),代码里不要按火山 ID 的前缀判断。
- 错误码是本平台的(见“错误码”一节),放在方舟的错误结构里;参数错误返回 400。
- 只能用本平台已上架、并为你开通的模型;对话、图片等其他方舟接口不在此列,对话请用 /v1/chat/completions。
- 经济版模型不在方舟兼容接口提供(按模型不存在处理),请用 /v1/videos/generations。
# 创建视频任务:请求体与方舟相同,只换地址和 Key
curl https://api.aitoken.tools/api/v3/contents/generations/tasks \
-H "Authorization: Bearer $AITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dreamina-seedance-2-0-260128",
"content": [
{ "type": "text", "text": "镜头缓缓推进,晨雾中的山间小镇" },
{ "type": "image_url", "image_url": { "url": "https://example.com/first.png" }, "role": "first_frame" }
],
"ratio": "adaptive",
"duration": 5
}'
# 查询任务(方舟的任务结构)
curl https://api.aitoken.tools/api/v3/contents/generations/tasks/task_xxx \
-H "Authorization: Bearer $AITOKEN_API_KEY"
# 素材库:按链接建素材。也可以用 AccessKey 按火山 V4 签名调用
curl "https://api.aitoken.tools/?Action=CreateAsset&Version=2024-01-01" \
-H "Authorization: Bearer $AITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"GroupId":"grp_xxx","URL":"https://example.com/role-a.png","AssetType":"Image","Name":"role-a"}'
# 返回:素材 ID 在 Result.Id(Name 只是名称,不能当 ID 用)
# {"ResponseMetadata":{"RequestId":"req_xxx","Action":"CreateAsset",…},"Result":{"Id":"asset_xxx"}}
# 查状态:Status 变为 Active 才能用(Processing 继续等,Failed 看 FailReason)
curl "https://api.aitoken.tools/?Action=GetAsset&Version=2024-01-01" \
-H "Authorization: Bearer $AITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"Id":"asset_xxx"}'
# {"ResponseMetadata":{…},"Result":{"Id":"asset_xxx","Name":"role-a","Status":"Active","AssetType":"Image","GroupId":"grp_xxx",…}}
# 生成视频时用 asset://<Result.Id> 引用这个素材
curl https://api.aitoken.tools/api/v3/contents/generations/tasks \
-H "Authorization: Bearer $AITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dreamina-seedance-2-0-260128",
"content": [
{ "type": "text", "text": "镜头缓缓推进,晨雾中的山间小镇" },
{ "type": "image_url", "image_url": { "url": "asset://asset_xxx" }, "role": "reference_image" }
]
}'