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

Authorizations

Authorization
string
header
required

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

Body

prompt
string
required

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

Required string length: 1 - 4000
Example:

"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
default:internal

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

Example:

"internal"

response_format
enum<string>
default:url

The format of the response images

Available options:
url,
b64_json
Example:

"url"

size
string
default:1024x1024

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

Example:

"1024x1024"

n
integer
default:1

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

Required range: 1 <= x <= 4
Example:

1

Response

Images generated successfully

success
boolean
Example:

true

id
string

Unique request identifier

Example:

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

object
string
Example:

"image.generation"

created
integer

Unix timestamp of when the images were created

Example:

1705312200

data
object[]

Array of generated images

metadata
object