Skip to main content
POST
Generate or Edit Images

Generate Images

Generate new images from text prompts or transform existing images using Google Gemini 2.5 Flash Image.

Endpoint

Description

Generate new images from text descriptions or transform existing images. This endpoint supports:
  • Text-to-Image: Generate images from text descriptions
  • Image-to-Image: Transform or edit existing images (upload an image file)
All prompts and responses are automatically processed through SMLTP for audit logging and compliance.

Authentication

Required: API Key

Request Body

This endpoint accepts both multipart/form-data (for file uploads) and application/json formats.

Parameters

Request Examples

Text-to-Image (JSON)

Image-to-Image (Multipart Form Data)

JavaScript/Node.js

Python

Response

Success Response (200)

Response Fields

Image Object

Metadata Object

Error Responses

400 Bad Request

401 Unauthorized

403 Forbidden

413 Payload Too Large

500 Internal Server Error

503 Service Unavailable

Notes

  • Supported image formats for upload: JPEG, PNG, WEBP, GIF
  • Maximum file size: 10MB per image
  • When uploading an image, the prompt describes how to transform it
  • Gemini typically generates 1-4 images per request
  • All requests are processed through SMLTP for security and compliance
  • Use response_format: "b64_json" to receive base64-encoded image data instead of URLs

授权

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