TokenAgents / API Docs
提交生图任务
提交文生图或图生图任务,返回站内任务记录。
POST
/api/ai/generateImage API提交生图任务
提交文生图或图生图任务,返回站内任务记录。
鉴权方式
需要登录态 Cookie,并校验用户 credits。
调试方式
所有页面都提供 shell curl 模板,方便你直接复制联调。
适配模型
当前页已关联 3 个模型目录,和前端实际可选模型保持同步。
请求体
当前接口支持的请求字段如下。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| provider | string | 是 | 当前支持 replicate。 |
| mediaType | "image" | 是 | 当前文档范围内固定为 image。 |
| scene | "text-to-image" | "image-to-image" | 是 | 生成场景。 |
| model | string | 是 | 模型 ID,需来自当前生图模型列表。 |
| prompt | string | 是 | 生成提示词。 |
| options | object | 否 | 扩展参数;图生图时可传参考图相关字段。 |
成功返回
使用当前接口时,可参考以下返回说明。
Response
{
"code": 0,
"message": "success",
"data": {
"id": "{{taskRecordId}}",
"provider": "replicate",
"model": "google/nano-banana",
"status": "pending",
"taskId": "{{providerTaskId}}",
"scene": "image-to-image",
"costCredits": 4
}
}关联模型
当前接口支持的模型目录。
Shell 调用示例
复制下面的 curl 模板,替换占位变量后即可联调。
curl
curl -X POST "{{baseUrl}}/api/ai/generate" \
-H "Content-Type: application/json" \
-H "Cookie: {{sessionCookie}}" \
-d '{
"provider": "replicate",
"mediaType": "image",
"scene": "text-to-image",
"model": "black-forest-labs/flux-schnell",
"prompt": "A modern SaaS dashboard illustration"
}'调用说明
- • text-to-image 默认扣 2 credits,image-to-image 默认扣 4 credits。