接入文档
把任意 OpenAI 协议兼容的客户端指到下面的地址,用访问令牌鉴权。
关键信息
- 接口地址
-
https://image.tokenvalid.com/v1 - 认证方式
Authorization: Bearer sk-...- 协议
-
POST /images/generations·POST /images/edits
模型与规格
每个模型接受什么。档位决定出图多大、以及这一张多少钱;每一档的合法尺寸见下面那张表。
| 模型 | 档位 | 缺省尺寸 | 参考图上限 |
|---|---|---|---|
gemini-3.1-flash-image
亦作 nano-banana-2
|
1k 2k 4k | 1024x1024 | 14 |
gemini-3-pro-image
亦作 nano-banana-pro
|
1k 2k 4k | 1024x1024 | 14 |
gemini-nano-banana-2.1
亦作 nano-banana-2.1
|
1k 2k 4k | 1024x1024 | — |
gpt-image-2
|
1k 2k 4k | 1024x1024 | 16 |
gpt-image-2.5-flare
|
1k 2k 4k | 1024x1024 | 16 |
gpt-image-2.5-sunburst
|
1k 2k 4k | 1024x1024 | 16 |
image-01
|
1k 2k | 1024x1024 | 1 |
image-01-live
|
1k | 1024x1024 | 1 |
image-test
|
不分档 | — | — |
seedream-5.0-open
|
2k 4k | 2048x2048 | — |
seedream-5-0-pro-open
|
1k 2k 4k | 1024x1024 | — |
size 有三种写法:精确像素串(1024x1024)、画幅串(16:9,落最便宜的那一档)、或 auto。
尺寸
size 能写的全部像素串。行是画幅,列是档位。
| 画幅 | 1k | 2k | 4k |
|---|---|---|---|
1:1 |
1024x1024 | 2048x2048 | 2880x2880 |
4:3 |
1152x864 | 2048x1536 | 3200x2400 |
3:4 |
864x1152 | 1536x2048 | 2400x3200 |
3:2 |
1536x1024 | 2304x1536 | 3456x2304 |
2:3 |
1024x1536 | 1536x2304 | 2304x3456 |
16:9 |
1344x768 | 2048x1152 | 3840x2160 |
9:16 |
768x1344 | 1152x2048 | 2160x3840 |
21:9 |
1536x656 | 2304x992 | 3840x1648 |
5:4 |
1120x896 | 1920x1536 | 3200x2560 |
4:5 |
896x1120 | 1536x1920 | 2560x3200 |
不传 size 时用的画幅: 1k = 1:1 · 2k = 1:1 · 4k = 16:9
参数
这个接口认识的全部参数,以及它们各自会被怎么处理。标为「拒绝」的会让请求失败,并返回下面那个错误码。
| 参数 | 处置 | 取值 | 缺省 | 说明 |
|---|---|---|---|---|
model |
生效 | gemini-3.1-flash-image · gemini-3-pro-image · gemini-nano-banana-2.1 · gpt-image-2 · gpt-image-2.5-flare · gpt-image-2.5-sunburst · image-01 · image-01-live · image-test · seedream-5.0-open · seedream-5-0-pro-open | — | — |
prompt |
生效 | <必填,非空字符串> | — | — |
size |
生效 | 41 个取值 —— 见上表 | — | — |
response_format |
生效 | url · b64_json | — | — |
quality |
生效 | low · medium · high · xhigh · max · auto | medium | — |
output_format |
生效 | png · jpeg · webp | jpeg | — |
n |
生效 |
1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10
一次出几张(1–10)。实际张数以返回的 data 条数为准:个别张没出成时只返回成功的几张,也只收这几张的钱。用 b64_json 返回时整批不超过 64MB(按尺寸估算,超了直接拒绝、不扣钱),大图多张请改用 url。
b64_json 返回时整批不超过 64MB(按尺寸估算,超了在扣费前直接拒绝),大图多张请改用 url。
|
1 | the number of images actually returned is the length of data; failed images are refunded |
stream |
收下但不生效 | true · false | — | — |
partial_images |
收下但不生效 | 0 · 1 · 2 · 3 | — | — |
user |
收下但不生效 | <任意字符串> | — | — |
mask |
生效 | <base64 PNG with alpha, same size as the first image> | — |
send to /v1/images/edits with exactly one image; only on the tiers listed under models[].tiers[].features.mask; areas outside the selection may change slightly; per-call groups pay the listed per-quality price, token groups pay by tokens as usual; the instruction below is appended to your prompt
我们会在你的提示词后追加这句话:
Edit only the transparent area of the mask: fill it so it blends seamlessly with the rest of the image, and keep every non-transparent area exactly unchanged. |
background |
生效 | transparent | — | only "transparent" is accepted (opaque / auto are rejected with background_not_supported), only on the tiers listed under models[].tiers[].features.transparent_background; output_format defaults to png, jpeg is rejected; per-call groups pay the listed per-quality price, token groups pay by tokens as usual |
output_compression |
拒绝 |
output_compression_not_supported
|
— | output_compression is not supported; conversion uses a fixed quality |
moderation |
拒绝 |
moderation_not_supported
|
— | moderation cannot be configured per request |
style |
拒绝 |
style_not_supported
|
— | style is not supported |
改图:局部重绘与透明背景
POST /images/edits 带参考图(multipart 或 JSON 都行)。下面两项只在模型列出支持的档位可用;该档暂无线路时请求在扣费前被拒绝。
mask- 带透明通道的 PNG,尺寸必须与第一张参考图完全一致;透明(alpha 0)的区域是要修改的区域。只能带一张参考图;选区之外的内容可能有轻微变化;不能与 background=transparent 同用。background- 只接受 transparent(opaque / auto 会被拒绝)。输出为 PNG:不传 output_format 时默认 png,webp 可用,传 jpeg 会被拒绝。
价格见「模型价格」页;按 token 计费的档照常按用量计费。
交付与限制
- 同步
- 缺省方式:响应里直接带图。客户端超时请设得比下面的整请求时限更长。
- 异步
-
加下面这个请求头:受理后立即返回状态与轮询地址(RFC 7240)。
Prefer: respond-async受理:HTTP 202,字段 id, status, created, model, size, poll_after_seconds 每 5 秒轮询 GET /v1/images/results/{id}(每分钟最多 24000 次)。状态:running · succeeded · failed 结果地址保留 3 天,之后返回 410。 没有回调,请轮询;response_format=b64_json 不能与异步同用。 - 整请求时限
- 一个请求最长可能跑 480 秒,客户端超时要比它长。
- 参考图下限
- 小于 26 字节的参考图会在扣费前被拒绝(invalid_reference)。
- 请求大小
- 请求体最大 32 MB,单张参考图最大 8 MB,最多 32 张参考图,提示词最长 200000 字符。
- b64_json 整批
- n 大于 1 且 response_format=b64_json 时整个响应不超过 64MB(按尺寸估算,超了在扣费前直接拒绝)。
画质与用量
quality: low · medium · high · xhigh · max · auto
- 不传时按 medium
响应里的 usage 由本服务按一套统一算法自算,所有模型、所有渠道相同。发布的规则版本: image-usage/8+q=medium,u=default,p=4412c2e3
- total_tokens
- input_tokens + output_tokens
- input_tokens
- text_tokens + image_tokens
- text_tokens
- o200k_base · if the tokenizer fails: ceil(utf8_bytes / 4)
- image_tokens
- each reference image in the image field (mask is not counted) · 65 + 129 * tiles (at most 581)
- output_tokens
- output_tokens_details.image_tokens + output_tokens_details.reasoning_tokens
- 输出公式
- ceil(grid * (2000000 + width * height) / 4000000)
- 思考
- a model listed in thinking_by_model adds that fixed number of reasoning tokens per image for the billed quality (an unlisted quality uses omitted_quality); they are part of output_tokens and reported in output_tokens_details.reasoning_tokens, charged at the text-and-thinking output rate
- n 大于 1
- text_tokens and image_tokens are counted once for the whole request and split evenly across the n images: floor(total / n) each, the remainder goes to the first image; output_tokens (and its details) are counted per image, in full
机器可读版:GET /v1/spec 的 usage_rules。
错误码
请求失败时返回 HTTP 状态码与 error 对象(code、message、type)。请按 error.code 处理。
| 错误码 | HTTP | 含义 | 可否重试 |
|---|---|---|---|
| 请求参数 | |||
async_b64_unsupported |
400 | 异步提交不支持 response_format=b64_json。 | 否 |
b64_too_large_use_url |
400 | 多张 b64_json 合计响应过大,请改用 response_format=url 或减少张数。 | 否 |
background_not_supported |
400 | 不支持 background 参数。 | 否 |
body_too_large |
413 | 请求体超过大小上限。 | 否 |
duplicate_request |
409 | 该 Idempotency-Key 已有对应请求。 | 否 |
edits_not_supported |
400 | 该模型不支持图生图。 | 否 |
feature_combination_not_supported |
400 | mask 与 background=transparent 不能在同一请求中同时使用。 | 否 |
invalid_json |
400 | 请求体不是合法的 JSON。 | 否 |
invalid_mask |
400 | 蒙版无效:须为带透明通道的 PNG、与第一张图同尺寸,并通过 /v1/images/edits 随恰好一张参考图提交。 | 否 |
invalid_multipart |
400 | multipart 请求体无法解析。 | 否 |
invalid_n |
400 | n 必须是 1 到 10 的整数。 | 否 |
invalid_output_format |
400 | output_format 仅支持 png、jpeg、webp。 | 否 |
invalid_reference |
400 | 参考图不是有效的图片文件。 | 否 |
invalid_response_format |
400 | response_format 仅支持 url、b64_json。 | 否 |
mask_not_supported |
400 | 不支持 mask(局部重绘)参数。 | 否 |
model_not_priced |
400 | 该模型(或该档位)尚未定价,暂不可下单。 | 否 |
model_required |
400 | 缺少 model 参数。 | 否 |
model_spec_missing |
400 | 模型不存在,请对照 GET /v1/models 核对名称。 | 否 |
moderation_not_supported |
400 | 不支持按请求设置审核级别。 | 否 |
n_exceeds_concurrency |
400 | n 超过该账号的并发上限,请减少单次张数。 | 否 |
n_not_supported |
400 | 不支持 n>1,每次请求生成一张。 | 否 |
output_compression_not_supported |
400 | 不支持 output_compression。 | 否 |
prompt_required |
400 | 缺少 prompt 参数。 | 否 |
prompt_too_long |
400 | 提示词超过长度上限(limits.max_prompt_chars)。 | 否 |
prompt_too_long_for_route |
400 | 提示词超过当前可用线路接受的最长长度,错误信息中给出该长度。 | 否 |
reference_image_required |
400 | 提示词要求参考图片,但请求未附带图片;请通过 /v1/images/edits 提交。 | 否 |
reference_too_large |
400 | 参考图超过大小上限。 | 否 |
request_not_supported |
400 | 该模型不支持此请求,错误信息中指出具体部分。 | 否 |
size_not_allowed |
400 | size 取值不合法,错误信息中给出最接近的合法值。 | 否 |
style_not_supported |
400 | 不支持 style 参数。 | 否 |
tier_not_available |
400 | 该模型不提供所请求的档位,错误信息中列出可用档位。 | 否 |
token_billing_unavailable |
400 | 该模型在你所在分组的按 token 计费下不可用(没有官方 token 价或该档位未定价)。 | 否 |
too_many_reference_images |
400 | 参考图数量超过上限。 | 否 |
| 鉴权与额度 | |||
insufficient_quota |
402 | 余额不足。 | 否 |
invalid_api_key |
401 | API 密钥无效或已停用。 | 否 |
missing_api_key |
401 | 缺少 Authorization: Bearer <key>。 | 否 |
model_not_allowed |
403 | 该 API 密钥无权使用此模型。 | 否 |
poll_rate_limit_exceeded |
429 | 查询结果过于频繁。 | 是 |
rate_limit_exceeded |
429 | 请求过于频繁,请降低频率。 | 是 |
too_many_concurrent_requests |
429 | 并发请求过多。 | 是 |
| 内容审核 | |||
content_policy_violation |
400 | 提示词或参考图未通过内容审核,请修改后提交。 | 否 |
output_content_policy_violation |
400 | 生成的图片未通过内容审核,可重新提交。 | 是 |
| 上游与线路 | |||
all_channels_failed |
502 | 所有可用线路均处理失败。 | 是 |
channel_saturated |
503 | 线路已满载,请稍后重试。 | 是 |
image_conversion_failed |
502 | 图片格式或尺寸转换失败。 | 否 |
image_empty_response |
502 | 上游返回的图片为空。 | 是 |
image_fetch_failed |
502 | 从上游下载图片失败。 | 是 |
image_fetch_timeout |
504 | 从上游下载图片超时。 | 是 |
image_pixels_too_large |
502 | 上游返回的图片超出处理上限。 | 否 |
image_redirect_not_followed |
502 | 上游图片链接发生重定向,未予跟随。 | 是 |
image_too_large |
502 | 上游返回的图片超出存储上限。 | 否 |
image_unreachable |
502 | 无法访问上游返回的图片链接。 | 是 |
image_url_invalid |
502 | 上游返回的图片链接无效。 | 是 |
image_url_not_public |
502 | 上游返回的图片链接不可公开访问。 | 是 |
no_channel_available |
503 | 该模型当前无可用线路。 | 否 |
no_image_returned |
502 | 上游未返回图片。 | 是 |
ratio_not_supported |
400 | 当前线路不支持该画幅。 | 否 |
size_not_supported |
400 | 当前线路不支持该尺寸。 | 否 |
transparent_background_missing |
502 | 上游返回的图片没有透明背景。 | 是 |
upstream_account_problem |
502 | 上游无法处理本次请求。 | 是 |
upstream_busy |
502 | 上游未能在时限内完成。 | 是 |
upstream_error |
502 | 上游处理失败。 | 是 |
upstream_rate_limited |
429 | 当前线路限流,请稍后重试。 | 是 |
upstream_redirected |
502 | 上游重定向了请求。 | 是 |
upstream_rejected |
502 | 上游拒绝本次请求。 | 是 |
upstream_response_too_large |
502 | 上游响应超过大小上限。 | 否 |
upstream_send_failed |
502 | 与上游的连接失败。 | 是 |
upstream_timeout |
504 | 上游未在时限内响应。 | 是 |
upstream_undersized |
502 | 上游返回的图片远小于请求尺寸。 | 是 |
upstream_unreachable |
502 | 无法连接上游。 | 是 |
| 服务与任务 | |||
abandoned |
— | 请求中断,已全额退款。 | 是 |
async_storage_unavailable |
— | 存储暂不可用,已全额退款。 | 是 |
async_unavailable |
503 | 当前节点不受理异步提交。 | 是 |
database_unavailable |
503 | 服务暂不可用,请稍后重试。 | 是 |
draining |
503 | 节点重启中,请稍后重试。 | 是 |
generation_failed |
— | 生成失败,已全额退款。 | 是 |
internal_error |
500 | 服务内部错误。 | 是 |
not_found |
404 | 未找到该请求编号。 | 否 |
server_busy |
503 | 节点繁忙,请稍后重试。 | 是 |
unknown_upstream |
500 | 线路配置错误。 | 是 |
HTTP 为「—」的错误码只出现在异步结果查询的 failure.code 中。机器可读版本:GET /v1/spec 的 errors。
审核拒绝时,若上游给出原因,message 中会包含原因,写法为 (reason: <reason>[, <reason>])
| 原因 | 含义 |
|---|---|
nudity or sexual content |
裸露或色情内容 |
sexually suggestive content |
性暗示或挑逗内容 |
depiction of minors |
涉及未成年人形象 |
real person |
涉及真实人物 |
violence |
暴力内容 |
self-harm or suicide |
自残或自杀相关内容 |
hateful content |
仇恨或歧视内容 |
illegal activity |
违法活动 |
fraud or scams |
欺诈或诈骗 |
defamation |
诽谤(将真实人物与犯罪或不当行为相关联) |
copyright |
涉及版权内容 |
similarity to third-party content |
与第三方内容(作品、角色、商标等)相似 |
similarity to existing content |
与已有内容相似 |
sensitive personal information |
涉及个人敏感信息 |
prohibited content |
违禁内容 |
blocked terms |
包含禁用词 |
image safety |
生成的图片触发安全策略 |
出图主机
生成的图从这些主机上取。把它们加进你的出网白名单或 CSP。
https://image*.tokenvalid.com
请求示例
curl https://image.tokenvalid.com/v1/images/generations \
-H "Authorization: Bearer $XTOKEN_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "a paper crane on a desk",
"size": "1024x1024"
}'