创建图片

POST/v1/images/generations

根据文本生成图片,或根据文本和一张或多张输入图片生成/编辑图片。 图像生成会在本次请求中直接返回结果,不需要像视频生成一样先提交任务再轮询结果。 你可以直接使用返回的 data[].url 下载图片。如需使用专用下载或删除接口,请先通过 GET /v1/images 获取图片记录 ID。

身份验证

Authorization Bearer

在 Authorization header 中使用 API key 作为 Bearer token。

Request Body

modelstringrequired

Model ID.

promptstringrequired

Image generation prompt.

ninteger

Number of images to generate.

sizestring

Requested output image dimensions, such as width-by-height, when the model uses explicit image size values.

aspect_ratiostring

Requested output image shape as a width-to-height ratio.

resolutionstring

Requested output image resolution or resolution tier.

qualitystring

Requested generation quality or fidelity tier.

seedinteger

Optional numeric seed for repeatable generation when deterministic seeding is supported.

prompt_extendboolean

Prompt extension flag.

negative_promptstring

Negative prompt.

watermarkboolean

Controls whether generated images include a watermark when supported.

response_formatstring

Response format.

imagesarray

Reference images.

sequential_image_generationstring

Sequential image generation mode.

sequential_image_generation_optionsobject

Sequential image generation configuration.

sequential_image_generation_options.max_imagesinteger

Maximum number of images to generate in sequential mode.

optimize_prompt_optionsobject

Prompt optimization configuration.

optimize_prompt_options.modestring

Prompt optimization mode, such as standard or fast.

strengthnumber

Input image influence strength.

enable_interleaveboolean

Interleaved generation flag.

enable_web_searchboolean

Web search flag.

output_formatstring

Requested file format for generated image outputs.

streamboolean

Streaming response flag.

metadataobject

Application metadata.

extra_bodyobject

Additional request body fields.

provider_optionsobject

Upstream configuration.

moderationstring

Content moderation strictness for generated images.

partial_imagesinteger

Number of partial images emitted before the final image in streaming mode

maskstring

Optional mask image for image edits. Transparent areas indicate where the input image may be edited.

bbox_listarray

Per-input-image bounding boxes for interactive image editing.

enable_sequentialboolean

Enables sequential image-set generation when supported by the model.

thinking_modeboolean

Enables publisher thinking mode for image generation.

color_palettearray

Custom output color palette entries with publisher-defined colors and ratios.

backgroundstring

Background handling for generated images, such as auto, transparent, or opaque.

layer_decompositionboolean

Whether the publisher should decompose the generated image into editable layers.

output_compressioninteger

Output image compression percentage for formats that support compression.

input_fidelitystring

How closely an image edit should preserve details from the input images.

userstring

Stable end-user identifier forwarded to publishers that accept it.

thinking_levelstring

Publisher thinking level used while generating an image.

include_thoughtsboolean

Whether the publisher should include thought summaries in the response.

enable_image_searchboolean

Whether Google Search grounding may use image search results.

media_resolutionstring

Publisher media-resolution tier used when processing input media.

Response

createdinteger

Unix 时间戳。

modelstring

实际服务请求的模型标识。

dataobject[]

生成的图片。

data.urlstring

下载生成图片的 URL。

data.b64_jsonstring

模型返回 Base64 图片时的内容。

data.output_formatstring

模型返回时的输出图片格式,例如 jpeg 或 png。

data.sizestring

模型返回时的输出图片尺寸,格式为 <width>x<height>。

data.errorobject | null

单张图片生成失败时的错误详情。

usageobject

本次请求的用量信息。用量结构因模型而异;以下字段均为可选,仅在所选模型返回时出现。

usage.generated_imagesinteger

模型成功生成的图片数量。

usage.input_imagesinteger

输入参考图片数量。

usage.prompt_tokensinteger

输入 token 数,部分模型使用 OpenAI Chat 风格命名。

usage.completion_tokensinteger

输出 token 数,部分模型使用 OpenAI Chat 风格命名。

usage.input_tokensinteger

本次请求消耗的输入 token。

usage.output_tokensinteger

本次请求消耗的输出 token。

usage.total_tokensinteger

本次请求消耗的总 token。

usage.input_tokens_detailsobject

输入 token 的模态明细。

usage.output_tokens_detailsobject

输出 token 的模态明细。

usage.output_text_tokensinteger

文本输出 token 数的扁平化字段。

usage.output_image_tokensinteger

图片输出 token 数的扁平化字段。

usage.generated_images_countinteger

生成图片数量的兼容字段。

usage.image_countinteger

生成图片数量的兼容字段。

usage.resolutionstring

用于生成或计量的实际输出分辨率档位。

usage.cache_read_tokensinteger

从缓存读取的输入 token 数。

usage.search_queries_countinteger

模型生成过程中使用的搜索查询次数。

errorobject

返回错误 payload 时的请求级错误详情。

error.codestring

错误码。

error.messagestring

错误信息。

请求

1curl -X POST https://api.token360.ai/v1/images/generations \
2  -H "Authorization: Bearer sk-your-api-key" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "model": "nano-banana-pro",
6    "prompt": "A minimalist sunrise over calm water, digital illustration",
7    "size": "1024x1024",
8    "aspect_ratio": "1:1"
9  }'

响应

以下 usage 来自一次真实请求,仅用于展示返回结构;具体字段和数值会随模型、输入内容、图片数量、分辨率及实际模型版本而变化。

JSON
1{
2  "created": 1789126936,
3  "model": "gemini-3-pro-image",
4  "data": [
5    {
6      "url": "your-generated-image-url",
7      "output_format": "png",
8      "size": "1k"
9    }
10  ],
11  "usage": {
12    "completion_tokens": 1304,
13    "generated_images": 1,
14    "generated_images_count": 1,
15    "image_count": 1,
16    "input_tokens": 9,
17    "input_tokens_details": {
18      "text_tokens": 9
19    },
20    "output_image_tokens": 1120,
21    "output_text_tokens": 184,
22    "output_tokens": 1304,
23    "output_tokens_details": {
24      "image_tokens": 1120,
25      "text_tokens": 184
26    },
27    "prompt_tokens": 9,
28    "resolution": "1k",
29    "search_queries_count": 0,
30    "total_tokens": 1313
31  }
32}
此页面对您有帮助吗?