Gemini 3.1 Flash Image Preview API Usage Guide
Overview
Gemini 3.1 Flash Image Preview is optimized for image understanding and generation, balancing speed and cost. It supports text-to-image, image-guided editing, and multi-turn iterative workflows viacontents.
Reference: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/3-1-flash-image
Authentication
All API requests require authentication using an API key. Include your API key in the Authorization header:Submit Image Generation Request
Base URL
Endpoint
Request Format
Request Parameters
| Parameter | Type | Required | Description | Default | Constraints |
|---|---|---|---|---|---|
prompt | string | Yes (single-turn) | Text description of the target image. | - | Required when contents is not provided |
image | string/array | No | Optional reference image URLs for image-guided generation/editing. | - | Max 14 images; PNG/JPEG/WebP/HEIC/HEIF; 7MB inline upload, 30MB via GCS |
image_size | string | No | Output resolution preset for generated image. | ”1K” | Options: “512”, “1K”, “2K”, “4K” |
aspect_ratio | string | No | Aspect ratio of the generated image. | ”1:1” | Options: “1:1”, “3:2”, “2:3”, “3:4”, “4:3”, “4:5”, “5:4”, “9:16”, “16:9”, “21:9” |
image_output_format | string | No | Output image format. | ”png” | Options: “png”, “jpeg” |
contents | array | No | Multi-turn conversation payload for iterative editing. | - | When provided, prompt and image are ignored |
Response
Check Request Status
Endpoint
Example
Response
Request Status Values
| Status | Description |
|---|---|
queued | Request is waiting to be processed |
processing | Image generation is in progress |
success | Image generation completed successfully |
failed | Image generation failed |
cancelled | Request was cancelled |
List Your Requests
Endpoint
Example
Get Model Information
Endpoint
Example
List Available Models
Endpoint
Example
Multi-turn Conversation (Iterative Image Editing)
This model supports multi-turn conversations for iterative image editing. After generating an image, you can continue refining it by providing additional instructions.How It Works
- First Turn: Send a regular request with
prompt(and optionalimage) - Response: The response includes
next_turn_contentswith prior conversation context - Next Turn: Copy
next_turn_contentsinto payloadcontents, then append your new user instruction - Repeat: Continue until the result is satisfactory
Model Specifications
| Specification | Value |
|---|---|
| Model ID | gemini-3.1-flash-image-preview |
| Max input tokens | 131,072 |
| Max output tokens | 32,768 |
| Max input images | 14 |
| Max file size (inline upload) | 7 MB |
| Max file size (GCS) | 30 MB |
| Max input size | 500 MB |
| Supported image MIME types | image/png, image/jpeg, image/webp, image/heic, image/heif |
| Supported aspect ratios | 1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
| Temperature | 0.0-2.0 (default 1.0) |
| topP | 0.0-1.0 (default 0.95) |
| candidateCount | 1 |
Capabilities
- Supported: System instructions, Count Tokens, Thinking
- Not supported: Code execution, Function calling, Gemini Live API, implicit/explicit context caching, Vertex AI RAG Engine, Chat completions
Tips for Better Results
- Use specific and descriptive prompts for stable outputs.
- For complex edits, use multi-turn mode with
contentsfor iterative refinement.