gemini-3.1-flash-image-preview-official Full Guide (Markdown)

Back to model guide

gemini-3.1-flash-image-preview-official API Model Guide

TL;DR

  • Supports prompt-based image generation with multiple aspect ratios.
  • Supports reference_images for stronger style consistency.
  • Official variants expose richer generation controls for production tuning.

Core Capabilities

  • High-quality image generation:Generate high-fidelity images via a unified API.
  • Reference-guided consistency:Use reference_images to stabilize style and composition.
  • Production tuning controls:Tune resolution, aspect ratio, and sampling for quality/cost balance.

When to Use

  • When generating marketing/e-commerce/creative image assets at scale.
  • When using references to stabilize style and iterate prompts quickly.

When Not to Use

  • For long-form video generation or temporal shot control.
  • For complex multi-turn reasoning chat tasks.

Runtime Behavior

  • Uses a unified image generation endpoint with task-style responses.
  • Supports reference image inputs with count/size constraints.
  • Resolution and aspect-ratio support vary by Gemini image variant.

Minimal Request

{
  "model": "gemini-3.1-flash-image-preview-official",
  "prompt": "High-end e-commerce product poster, soft light, realistic texture, minimal background",
  "size": "1:1",
  "resolution": "1K"
}

Minimal Response

{
  "id": "task_img_xxxxxxxx",
  "object": "generation.task",
  "model": "gemini-3.1-flash-image-preview-official",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}

Key Parameters

ParameterTypeRequiredDefaultRangeDescription
modelstringYesgemini-3.1-flash-image-preview-official-Exact image model identifier from ToAPIs.
promptstringYes--Primary image instruction prompt.
sizestringNo1:11:116:9
resolutionstringNo1K1K2K
reference_imagesfile[]No-max 14Reference image array for style/composition control.
temperaturenumberNo0.80-2Sampling temperature for diversity control.
topPnumberNo0.950-1Nucleus sampling threshold.

Common Errors

HTTPCodeTriggerFix ActionRetry Policy
400invalid_request_errorMissing or invalid request payload fields.Validate model/prompt/size/resolution fields.Retry only after fixing payload.
401authentication_errorMissing or invalid API key.Verify Authorization header and API key scope.Retry after auth fix.
429rate_limit_exceededRequest rate, concurrency, or current quota hits upstream rate limiting.Apply exponential backoff first, then review request rate, concurrency, and quota usage.Use 1s/2s/4s backoff with jitter; if it persists, reduce submission pressure.

FAQ

  1. How should I choose Gemini image variants?
    Choose by resolution needs, official vs preview variant, and control parameters; prefer official for production.
  2. Why are reference images not taking effect?
    Check reference count/format/size limits and ensure prompt explicitly uses references.
  3. Image or video model error: invalid apitype: -1
    This usually means the request was sent to the wrong endpoint. Image and video models typically do not use the chat endpoint. Instead, submit the documented HTTP task request and poll the task status endpoint for results. Check the actual request code, URL, and payload first.
  4. An image or video task failed, but the user was still charged
    Ask the user for the task log or screenshot first and check whether input or output token usage appears. If token accounting shows up, the request was likely sent through a chat endpoint instead of the proper media workflow. Image and video models usually run as async HTTP task APIs: submit the task first, then poll by task id according to the relevant docs.

Related APIs