创建图片
/v1/images/generations根据文本生成图片,或根据文本和一张或多张输入图片生成/编辑图片。
图像生成会在本次请求中直接返回结果,不需要像视频生成一样先提交任务再轮询结果。
你可以直接使用返回的 data[].url 下载图片。如需使用专用下载或删除接口,请先通过 GET /v1/images 获取图片记录 ID。
身份验证
Authorization Bearer
在 Authorization header 中使用 API key 作为 Bearer token。
Request Body
modelstringrequiredModel ID.
promptstringrequiredImage generation prompt.
nintegerNumber of images to generate.
sizestringRequested output image dimensions, such as width-by-height, when the model uses explicit image size values.
aspect_ratiostringRequested output image shape as a width-to-height ratio.
resolutionstringRequested output image resolution or resolution tier.
qualitystringRequested generation quality or fidelity tier.
seedintegerOptional numeric seed for repeatable generation when deterministic seeding is supported.
prompt_extendbooleanPrompt extension flag.
negative_promptstringNegative prompt.
watermarkbooleanControls whether generated images include a watermark when supported.
response_formatstringResponse format.
imagesarrayReference images.
sequential_image_generationstringSequential image generation mode.
sequential_image_generation_optionsobjectSequential image generation configuration.
sequential_image_generation_options.max_imagesintegerMaximum number of images to generate in sequential mode.
optimize_prompt_optionsobjectPrompt optimization configuration.
optimize_prompt_options.modestringPrompt optimization mode, such as standard or fast.
strengthnumberInput image influence strength.
enable_interleavebooleanInterleaved generation flag.
enable_web_searchbooleanWeb search flag.
output_formatstringRequested file format for generated image outputs.
streambooleanStreaming response flag.
metadataobjectApplication metadata.
extra_bodyobjectAdditional request body fields.
provider_optionsobjectUpstream configuration.
moderationstringContent moderation strictness for generated images.
partial_imagesintegerNumber of partial images emitted before the final image in streaming mode
maskstringOptional mask image for image edits. Transparent areas indicate where the input image may be edited.
bbox_listarrayPer-input-image bounding boxes for interactive image editing.
enable_sequentialbooleanEnables sequential image-set generation when supported by the model.
thinking_modebooleanEnables publisher thinking mode for image generation.
color_palettearrayCustom output color palette entries with publisher-defined colors and ratios.
backgroundstringBackground handling for generated images, such as auto, transparent, or opaque.
layer_decompositionbooleanWhether the publisher should decompose the generated image into editable layers.
output_compressionintegerOutput image compression percentage for formats that support compression.
input_fidelitystringHow closely an image edit should preserve details from the input images.
userstringStable end-user identifier forwarded to publishers that accept it.
thinking_levelstringPublisher thinking level used while generating an image.
include_thoughtsbooleanWhether the publisher should include thought summaries in the response.
enable_image_searchbooleanWhether Google Search grounding may use image search results.
media_resolutionstringPublisher media-resolution tier used when processing input media.
Response
createdintegerUnix 时间戳。
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错误信息。