genmux API 现已全面开放。 查看文档 →
genmux API

图像

POST /v1/generations

创建一个异步生成任务。积分立即预留,任务失败时退回。

请求头

请求头必填说明
Authorization是Bearer <API 密钥>
Idempotency-Key是每个请求唯一(≤ 128 字符)。用同一个 key 重发会返回原来的任务(200),不会再次扣费。同一个 key 配不同请求体 → 422。
Content-Type是application/json

请求体

字段类型说明
modelstring必填。来自 GET /v1/models 的模型 id,例如 "nanobanana"。
promptstring除非提供了 images,否则必填。1–2000 个字符(个别模型上限更低——见 max_prompt)。
negative_promptstring选填。要避开的内容。仅在 schema 中带 negative_prompt: true 的模型上可用。
ninteger生成张数,1–4,默认 1。每张单独计费。
resolutionstring1K(默认)· 2K · 4K。模型出图的档位,也是计价单位。模型在 params_schema.resolutions 中列出它支持的档位。
ratiostring宽高比:auto · 1:1(默认)· 16:9 · 9:16 · 4:3 · 3:4 · 3:2 · 2:3 · 5:4 · 4:5 · 21:9。比例不影响价格。
imagesstring[]选填。用于图生图的参考图,需为公开的 https URL。数量不超过模型的 max_images;模型 schema 中没有该字段表示不接受参考图。
seedinteger选填。模型支持时,相同 seed 加相同提示词可得到可复现的结果。
webhook_urlstring选填。任务完成时回调的 https URL。见「Webhook」。
sizestring (legacy)已废弃。形如 宽x高 的字符串,会映射到最接近的 resolution + ratio。仅为兼容既有接入而保留;与 resolution 或 ratio 同时发送会返回 400。新代码请使用 resolution 和 ratio。

响应 202 Accepted

{"id": "…", "model": "nanobanana", "status": "queued", "params": {…}, "cost": 2, "created_at": "…"}

请求体上限 64 KB。未知字段会被拒绝并返回 400.

GET /v1/generations/{id}

返回该任务。当 status = succeeded 时,响应会包含 images[],其中是预签名下载 URL(有效期 15 分钟;再次调用可获取新 URL)。

status含义
queued等待工作进程接手。
running生成中。
succeeded已完成;带 images[];积分已扣除。
failed失败;带 error{code,message};积分已退回。
cancelled在开始前被你取消;积分已退回。
Failed job
{"id": "…", "status": "failed", "error": {"code": "content_policy", "message": "the prompt was rejected by the content policy"}, "cost": 2, …}

对话补全同样以 generation 记录存储:记录里带 capability: "text.chat" 和一个 usage 块,包含 token 数——从不包含消息本身,只有最后一条用户消息不超过 200 字符的预览和一个哈希。

Chat completion record
{"id": "…", "model": "qwen3.8-max", "capability": "text.chat", "status": "succeeded", "params": {"prompt": "Explain idempotency keys…", "messages": 2, "messages_sha256": "9f2c…", "max_tokens": 200, "stream": true}, "usage": {"prompt_tokens": 31, "completion_tokens": 58, "total_tokens": 89, "finish_reason": "stop", "usage_source": "estimated"}, "cost": 0.004, "created_at": "…", "finished_at": "…"}

GET /v1/generations

最新的在前,每页 50 条。把上一次响应里的 cursor 传回来即可取下一页。

curl -s "https://api.genmux.tech/v1/generations?cursor=2026-08-28T20:01:12.345Z" -H "Authorization: Bearer $API_KEY"
Response
{"data": [ {…job…}, … ], "next_cursor": "2026-08-27T09:12:44.001Z"}

用 ?capability=text.chat 按类型过滤(或 image.generate)。

DELETE /v1/generations/{id}

取消仍处于 queued 的任务并退回其积分。已经在执行的任务无法取消(409).

curl -s -X DELETE https://api.genmux.tech/v1/generations/<id> -H "Authorization: Bearer $API_KEY"
Response · 200 OK
{"id": "…", "status": "cancelled", …}