Skip to main content
POST
Generate or Edit Images

生成图像

根据文本提示生成新图像或使用 Google Gemini 2.5 Flash Image 转换现有图像。

端点

说明

从文本描述生成新图像或转换现有图像。该端点支持:
  • 文本到图像:从文本描述生成图像
  • 图像到图像:转换或编辑现有图像(上传图像文件)
所有提示和响应均通过 SMLTP 自动处理,以进行审核记录和合规性。

身份验证

必需:API 密钥

请求正文

此端点接受 multipart/form-data(用于文件上传)和 application/json 格式。

参数

请求示例

文本到图像 (JSON)

图像到图像(多部分表单数据)

JavaScript/Node.js

###Python

回应

成功响应 (200)

响应字段

图像对象

元数据对象

错误响应

400 错误请求

401 未经授权

403 禁止

413 有效负载太大

500 内部服务器错误

503 服务不可用

注释

  • 支持上传的图像格式:JPEG、PNG、WEBP、GIF
  • 最大文件大小:每张图像 10MB
  • 上传图片时,提示说明如何转换图片
  • Gemini 通常为每个请求生成 1-4 张图像
  • 所有请求均通过 SMLTP 处理,以确保安全性和合规性
  • 使用response_format: "b64_json"接收base64编码的图像数据而不是URL

授权

Authorization
string
header
必填

API key authentication using Bearer token format. Example: Authorization: Bearer sk-your-api-key-here

请求体

prompt
string
必填

The text prompt describing the image to generate or how to transform the uploaded image

Required string length: 1 - 4000
示例:

"A beautiful sunset over the ocean with mountains in the background, digital art style"

image
file

Optional image file for image-to-image generation (JPEG, PNG, WEBP, or GIF, max 10MB)

smltp_policy
string
默认值:internal

SMLTP security policy to apply (e.g., 'internal', 'public', 'confidential', 'hipaa', 'gdpr')

示例:

"internal"

response_format
enum<string>
默认值:url

The format of the response images

可用选项:
url,
b64_json
示例:

"url"

size
string
默认值:1024x1024

The size of the generated images (for future use, currently uses default size)

示例:

"1024x1024"

n
integer
默认值:1

Number of images to generate (Gemini typically generates 1-4 images)

必填范围: 1 <= x <= 4
示例:

1

响应

Images generated successfully

success
boolean
示例:

true

id
string

Unique request identifier

示例:

"90d3756f-41c3-4f86-a18d-e257bfbc33a3"

object
string
示例:

"image.generation"

created
integer

Unix timestamp of when the images were created

示例:

1705312200

data
object[]

Array of generated images

metadata
object