/t1/imagegen 异步提交:预备链(认证/能力位/解出/受理/配额/预扣)与同步端点同一函数——校验失败在本响应即时可见恒不产失败任务行;通过即落 media_tasks 行并后台执行,202 携 taskId/status=queued/pollIntervalMs;计费语义同同步径(成功即扣,断连照常产出照常扣费,有找回径不亏);params 快照恒不含用户内容
const url = 'https://api.tansr.com/t1/imagegen/tasks';const options = { method: 'POST', headers: { 'x-tansr-key-id': '<x-tansr-key-id>', 'x-tansr-key': '<x-tansr-key>', 'Content-Type': 'application/json' }, body: '{"model":"example","prompt":"example","negativePrompt":"example","size":"example","n":1,"seed":1,"imageUrls":["example"],"action":{"taskId":"example","actionId":"example"}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.tansr.com/t1/imagegen/tasks \ --header 'Content-Type: application/json' \ --header 'x-tansr-key: <x-tansr-key>' \ --header 'x-tansr-key-id: <x-tansr-key-id>' \ --data '{ "model": "example", "prompt": "example", "negativePrompt": "example", "size": "example", "n": 1, "seed": 1, "imageUrls": [ "example" ], "action": { "taskId": "example", "actionId": "example" } }'Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”签名时间戳(unix 秒,十进制串;T-A34):与服务器时钟偏差 >300s → 401 signature_invalid
签名随机数(≥16 字符;T-A34):同 keyId 600s 窗内重现 → 401 nonce_replayed
请求签名(hex 小写;T-A34):HMAC-SHA256(K=sha256(SK 明文) 原始摘要, TWP1-HMAC-SHA256\n{METHOD}\n{path+query}\n{ts}\n{nonce}\n{sha256hex(rawBody)});三头须同现,在场恒校验;app signRequired 或 TANSR_API_TWP_REQUIRE_SIGNATURE=1 时未签名恒 401 signature_invalid
Request Bodyrequired
Section titled “Request Bodyrequired”object
图像模型引用名(候选池三级收敛产物;池外/越权恒 403 model_not_authorized,不泄露池存在性)。缺席 = 授权集顺位第一(与 bundle platformModels.imageGen 首行恒同);空授权集恒 imagegen_not_configured
正向提示词(平台恒不落日志不落库;wire 帽 2100 = dashscope 系最宽档,上游按模型限长再截)。除 midjourney 动词行(action 径)外必填
反向提示词(dashscope 系上限 500 字符,超限上游自截)
输出分辨率 ‘宽高’(如 10241024;缺省随模型;合法域随模型,越域由上游 400 如实回)
生成张数(缺省 1 保守——费用 = 单价 × 张数;wire 帽 4 = 经典万相档,超模型帽静默钳,放宽属加法)
随机种子(内容相对稳定;缺省上游随机)
输入图像(编辑/参考;公网 URL 或 data:image/*;base64 URI)。受理与张数域随模型(如 qwen-image-edit 必 1 张、seedream 至 14 张、flux 系只收 data URI);不受理的模型在场即 400
Midjourney 动词行引用位(reroll/upscale/variation 恒必携;imagine 与其他模型在场即 400)
object
被引用任务 id(上一次 imagine/动词响应的 taskId)
动作引用 id(上一次响应 actions[].actionId)
Examplegenerated
{ "model": "example", "prompt": "example", "negativePrompt": "example", "size": "example", "n": 1, "seed": 1, "imageUrls": [ "example" ], "action": { "taskId": "example", "actionId": "example" }}Responses
Section titled “Responses”已受理({taskId, status:“queued”, model, pollIntervalMs})
object
任务 id(ULID;GET /t1/{videogen,imagegen}/tasks/:id 找回锚)
生效模型引用名(同步端点 model 回显同语义;缺省径 = 顺位第一 canonical handle)
建议轮询间隔毫秒(服务端上游轮询同拍;更密只耗限额不提速)
找回窗截止(ISO;窗外查询恒 404。产出直链另受上游 ~24h 失效约束,及时转存)
Example
{ "status": "queued"}Imagegen_not_configured(平台面未开通 / 解出三闸 wire·价格·凭据任一不过 fail-closed)/ bad_request(受理面拒:size/seed/negativePrompt 位不受理、imageUrls 域外、n 超帽、动词行缺 action 等,detail 可解释)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}App_key_invalid / 令牌无效或过期 / signature_invalid / nonce_replayed(T-A34)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}Insufficient_balance(预扣 fail-closed 零上游)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}Model_not_authorized(点名池外/越权,不泄露池存在性)/ forbidden(令牌径能力位 platform.* 未开,detail.capability)/ app_disabled / app_ip_denied
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}Rate_limited(key 级 60s 窗)/ imagegen_quota_exceeded(平台日顶或终端用户日配额档,UTC+8 日界,detail.limit/used)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}Upstream_error(上游拒绝/形状非法;方言正文不透传,仅 detail.upstreamCode 机器码 + upstreamStatus)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}本文是否有帮助?
感谢反馈,我们会持续改进这篇文章。