APIMaster.ai

Gemini 3.1 Flash Image Preview API — Text & Image-to-Image Guide

Use gemini-3.1-flash-image-preview on APIMaster.ai for text-to-image and image-to-image generation up to 4K.

Gemini 3.1 Flash Image Preview

  • Model: gemini-3.1-flash-image-preview (fixed)
  • Features: Text-to-image, image-to-image (up to 14 references), up to 4K, extreme aspect ratios, optional Google search grounding

Do not call this model via /v1/chat/completions — you will get 400 with a hint to use the Images API.

Endpoints

Mode Endpoint When to use
Sync (recommended) POST https://apimaster.ai/v1/images/generations One HTTP round-trip; platform polls upstream and returns { "data": [{ "url" }] }
Async POST https://apimaster.ai/v1/images/generations/asyncGET https://apimaster.ai/v1/tasks/{task_id}?model=gemini-3.1-flash-image-preview Long jobs, custom queues

Quick start (sync)

curl -s "https://apimaster.ai/v1/images/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image-preview",
    "prompt": "Cyberpunk city at night, neon lights",
    "size": "16:9",
    "resolution": "2K",
    "n": 1
  }'

Success

{
  "created": 1782633696,
  "data": [{ "url": "https://apimaster.ai/imgs/1782633695067198543.jpg" }]
}

Set HTTP read timeout to ≥ 180s for 2K/4K. Download or mirror URLs promptly — they expire.

Async flow

Submit

curl -s "https://apimaster.ai/v1/images/generations/async" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image-preview",
    "prompt": "a corgi astronaut on the moon",
    "size": "1:1",
    "resolution": "1K",
    "n": 1
  }'

Submit response

{
  "code": 200,
  "data": [{ "status": "submitted", "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K" }]
}

Poll

curl -s "https://apimaster.ai/v1/tasks/TASK_ID?model=gemini-3.1-flash-image-preview" \
  -H "Authorization: Bearer YOUR_API_KEY"

On success read data.result.images[0].url. Typical poll statuses: in_progresssucceeded / completed.

Wait 10–20s before the first poll, then every 3–5s.

Auth

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Body parameters

Field Type Required Notes
model string yes gemini-3.1-flash-image-preview
prompt string yes Scene description
size string no Aspect ratio; see below
resolution string no 0.5K / 1K / 2K / 4K, default 1K; case-insensitive
n integer no Only 1 supported (numeric, not string)
image_urls array no Reference images (URL or data URI)
google_search boolean no Google text search grounding
google_image_search boolean no Requires google_search: true

Resolution & billing tiers

Value ~pixels Price vs 1K base
0.5K ~512 same as 1K
1K ~1024 base
2K ~2048 × 4/3
4K ~4096 × 2

Actual charge = channel price × resolution multiplier × group ratio. See marketplace or console logs.

Errors

HTTP Meaning
400 Bad params, or wrong endpoint (chat)
401 Invalid API key
402 Insufficient balance
408 Sync poll timeout — retry async or lower resolution
500 / 502 Upstream or platform error

Invalid aspect ratios may surface as 500 when only one channel is configured.

Notes

  • Usage logs include result_url for image preview and request_data.effective_resolution.
  • Pricing varies by channel and resolution — see marketplace.