GenCraft.ccPOST /api/v1/generate · GET /api/v1/tasks
面向批量调用与 agent 集成的公开接口。直接用你账户已有的 API Key 鉴权,无需单独申请 token。
在 HTTP header 里附带你的 API Key。这个 key 就是 GenCraft 在你购买套餐后为你账户分配、存在 user_keys 表里的 api_key。校验失败返回 401。
Authorization: Bearer <your_api_key>{ "error": { "type": "invalid_api_key", "message": "Invalid API key" } }/api/v1/generate把任务提交给上游后立即返回 task_ids。拿到 task_ids 后有两种方式拿结果:(A) 自己用 GET /v1/tasks/{id} 轮询;(B) 直接登录网站——同账号的「图像创作」tab 会自动接管这些任务,完成后落到「我的作品」里。
curl -X POST https://www.gencraft.cc/api/v1/generate \
-H "Authorization: Bearer <your_api_key>" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A serene Japanese garden in autumn",
"model": "flash",
"mode": "text",
"aspect": "16:9",
"imageSize": "2K",
"count": 1
}'{
"task_ids": ["task_abc123"],
"email": "you@example.com"
}| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
| prompt | string | ✓ | — | 生成提示词 |
| model | string | gpt-image-2 | 模型 id(见下表) | |
| mode | text | edit | fusion | text | text=文生图;edit=单图编辑;fusion=多图融合 | |
| aspect | string | 1:1 | 比例:1:1、2:3、3:2、3:4、4:3、9:16、16:9、21:9 等 | |
| imageSize | 1K | 2K | 4K | 2K | 输出分辨率 | |
| count | number | 1 | 生成张数(受模型上限约束) | |
| imageUrls | string[] | [] | edit / fusion 模式的参考图 URL |
| model | 名称 | 支持模式 |
|---|---|---|
| gpt-image-2 | GPT Image 2 | text, edit |
| pro | Nano Banana Pro | text, edit |
| flash2 | Nano Banana 2 | text, edit |
| flash | Nano Banana | text, edit |
| HTTP | error.type | 触发条件 |
|---|---|---|
| 400 | invalid_request | body 不是 JSON / prompt 为空 / model 不存在 / model 不支持该 mode |
| 401 | unauthorized | 缺 Authorization header 或不是 Bearer 格式 |
| 401 | invalid_api_key | API key 在 user_keys 表里查不到 |
| 500 | upstream_error | 上游图像服务调用失败(包含上游返回的 message) |
/api/v1/tasks/{task_id}返回上游任务状态。status 取值:queued / in_progress / completed / failed。completed 时多 imageUrl 字段;failed 时多 error 字段。
curl https://www.gencraft.cc/api/v1/tasks/task_abc123 \
-H "Authorization: Bearer <your_api_key>"{
"task_id": "task_abc123",
"status": "completed",
"progress": 100,
"imageUrl": "https://files.example.com/generated/xxx.png"
}/api/v1/tasks?ids=t1,t2一次请求查多个任务,省 N 次 HTTP 往返与鉴权。返回顺序与入参 ids 严格对应。最多一次 20 个 id。
curl "https://www.gencraft.cc/api/v1/tasks?ids=task_abc,task_def,task_ghi" \
-H "Authorization: Bearer <your_api_key>"{
"tasks": [
{ "task_id": "task_abc", "status": "completed", "progress": 100, "imageUrl": "https://..." },
{ "task_id": "task_def", "status": "in_progress", "progress": 60 },
{ "task_id": "task_ghi", "status": "failed", "progress": 0, "error": "model overloaded" }
]
}| HTTP | error.type | 触发条件 |
|---|---|---|
| 400 | invalid_request | 缺 ids 参数,或 ids 超过 20 个 |
| 401 | unauthorized | 缺 Authorization header 或不是 Bearer 格式 |
| 401 | invalid_api_key | API key 在 user_keys 表里查不到 |
/api/v1/upload服务端从 source_url 下载图片后转发到上游 CDN,返回稳定 URL。把返回的 URL 放进 generate_image 的 imageUrls 字段即可。每张最大 25 MB;接受 png / jpeg / webp / gif / bmp。
curl -X POST https://www.gencraft.cc/api/v1/upload \
-H "Authorization: Bearer <your_api_key>" \
-H "Content-Type: application/json" \
-d '{"source_url": "https://example.com/cat.png"}'{
"url": "https://files.example.com/uploads/abc123.png",
"filename": "cat.png",
"content_type": "image/png",
"bytes": 524288
}/api/v1/history?page=1&limit=20返回该 API key 所属账号的过往生成记录,按时间倒序。分页参数:page(1-indexed)、limit(最大 50)。
curl "https://www.gencraft.cc/api/v1/history?page=1&limit=20" \
-H "Authorization: Bearer <your_api_key>"{
"items": [
{
"id": "tsk_img_xxx",
"prompt": "a cat in autumn",
"model": "flash",
"mode": "text",
"aspect": "16:9",
"imageSize": "2K",
"imageCount": 1,
"images": ["https://..."],
"refs": [],
"createdAt": 1777461252000
}
],
"total": 42,
"page": 1,
"limit": 20,
"total_pages": 3
}/api/v1/user/status返回邮箱、套餐档位(trial / starter / standard / pro)、以及上游 key 是否配置。agent 可据此决定是否上高消耗模型。
curl https://www.gencraft.cc/api/v1/user/status \
-H "Authorization: Bearer <your_api_key>"{
"email": "you@example.com",
"tier": "pro",
"has_key": true
}对 LLM agent 来说,接入 GenCraft 最简单的方式是用官方 MCP server——已发布到 npm:@gencraft/mcp-server。它通过 stdio 暴露 6 个 tool(generate_image、get_task、batch_get_tasks、upload_reference_image、list_my_generations、get_account_status),所有 MCP 兼容客户端开箱即用。在你客户端的 MCP 配置里加下面这段就行。
路径:~/Library/Application Support/Claude/claude_desktop_config.json(macOS) · %APPDATA%\Claude\claude_desktop_config.json(Windows)
{
"mcpServers": {
"gencraft": {
"command": "npx",
"args": ["-y", "@gencraft/mcp-server"],
"env": {
"GENCRAFT_API_KEY": "<your_api_key>"
}
}
}
}