Gemini image generation
Generate and edit images with Gemini: parameters, responses, and caveats.
| Item | Value |
|---|---|
| Base URL | https://api.hop-base.com/v1 |
| Generate (incl. reference edits) | POST /v1/images/generations |
| Edit (Gemini (all models, incl. image) only) | POST /v1/images/edits |
| Query async tasks | GET /v1/images/tasks?task_id=… |
| Key group | Gemini (all models, incl. image) or Gemini Official Direct |
Gemini image generation (nicknamed Banana) uses the OpenAI Images API and returns Base64 images synchronously; the two groups differ in edit endpoint and billing.
Available models
| Model | Model ID | Size tiers | Official price |
|---|---|---|---|
| Gemini 3 Pro Image (Banana Pro) | gemini-3-pro-image | 1K / 2K / 4K | $0.1344from/ image |
| Gemini 3.1 Flash Image (Banana 2) | gemini-3.1-flash-image | 1K / 2K | $0.0672/ image |
| Banana 2 preview | gemini-3.1-flash-image-preview | 1K / 2K | $0.0672/ image |
| Gemini 3.1 Flash Lite Image (Banana 2 Lite) | gemini-3.1-flash-lite-image | 1K | $0.0336/ image |
| Gemini 2.5 Flash Image (Banana) | gemini-2.5-flash-image | 1K | $0.0387/ image |
Choosing a model: only gemini-3-pro-image offers 4K; gemini-3.1-flash-image charges the same for 1K and 2K; avoid Lite for multi-reference composition, as it is not optimized for multiple references.
How the two groups differ:
| Group | /v1/images/edits | Billing |
|---|---|---|
| Gemini (all models, incl. image) | Supported | Per image delivered |
| Gemini Official Direct | Returns 404; send references to generations | By token |
Gemini Official Direct can also call image models through /v1/chat/completions, with the image returned as a markdown-embedded data URL.
Request parameters
Generate
POST /v1/images/generations with a JSON body. Use the OpenAI Images structure; do not send a Gemini-native generateContent payload.
| Parameter | Required | Type and limits | Default | Description |
|---|---|---|---|---|
model | Required | string, see the table above | — | Use the ID GET /v1/models returns for your key |
prompt | Required | string, non-empty after trimming | — | Generation or editing instruction |
size | Optional | auto, WIDTHxHEIGHT in any ratio, or 1K / 2K / 4K | — | Converted to a ratio and tier, see below |
n | Optional | integer 1–10 | 1 | Further capped per tier, see below |
google.image_config.aspect_ratio | Optional | 10 official ratios | 1:1 | Overrides size |
google.image_config.image_size | Optional | 1K / 2K / 4K within the model's tiers | 1K | Overrides size |
image / images | Optional | URL / Data URL, string or string array | — | Reference images; images wins if both are sent |
quality, response_format, output_format | Optional | any | — | No effect |
Allowed aspect_ratio values: 1:1 / 2:3 / 3:2 / 3:4 / 4:3 / 4:5 / 5:4 / 9:16 / 16:9 / 21:9.
image_config has three equivalent forms. If more than one is present, the first in this order wins:
google.image_configextra_body.google.image_config(the OpenAI SDK form)- Flat top-level
aspect_ratio/image_size
An explicit image_size above the model's tiers returns 400.
A WIDTHxHEIGHT size is never rejected for its ratio. It maps to the nearest official ratio, and the tier (from the long edge) is silently capped at the model's top tier with no error.
For example, 4096x4096 on gemini-3.1-flash-image returns a 2K image. A tier shorthand above the model's tiers returns 400.
n is also capped by output tier: 4K ≤ 2, 2K ≤ 5, 1K ≤ 10 (response-size limit); going over returns 400.
Reference images
Both groups take references in image / images on generations, JSON only. Each item is an http(s) URL or Data URL string; URLs must be reachable by the server and must not point to an internal address.
| Group | Count | Size per image |
|---|---|---|
| Gemini (all models, incl. image) | At most 14; more returns 400 | Remote URL ≤ 25 MiB |
| Gemini Official Direct | Official limit 14; not checked by the gateway | ≤ 20 MiB decoded |
Gemini (all models, incl. image) compresses references over 4 MiB before generating. Officially, gemini-2.5-flash-image takes at most 3 references. Data URL example: data:image/png;base64,iVBORw0KGgo…, with a MIME type that matches the image.
Edit (Gemini (all models, incl. image) only)
POST /v1/images/edits prefers multipart/form-data and also accepts JSON (references as URL / Data URL). At least one reference image is required.
| Parameter | Required | Type and limits | Default | Description |
|---|---|---|---|---|
image / image[] | Required | file or URL string, repeatable | — | Reference image |
model, prompt | Required | same as Generate | — | — |
size, n | Optional | same as Generate | — | — |
aspect_ratio, image_size | Optional | same as image_config in Generate | — | Multipart field names |
Gemini Official Direct has no such endpoint and returns 404; to edit there, send references to generations. Neither group supports mask, which returns 400.
Async
With the HTTP header Prefer: respond-async, the request immediately returns 202 Accepted and a task_id. Prefer this for 2K / 4K images so long requests are not cut off by CDN timeouts.
Response
Sync requests return OpenAI Images JSON, with the image in data[].b64_json.
| Field | Type | Description |
|---|---|---|
created | integer | Unix seconds |
model | string | The requested model ID |
data[].b64_json | string | Base64 image data |
data[].mime_type | string | Image format; may be image/jpeg |
usage | object | May be returned, with input, output, and total tokens |
usageMetadata | object | May be returned by Gemini Official Direct; official Gemini usage fields |
{
"created": 1760000000,
"model": "gemini-3-pro-image",
"data": [
{
"b64_json": "/9j/4AAQSkZJRgABAQ...",
"mime_type": "image/jpeg"
}
],
"usage": {
"input_tokens": 42,
"output_tokens": 1120,
"total_tokens": 1162
}
}Async tasks
Submitting returns immediately:
{
"task_id": "imgtask_EXAMPLE",
"status": "pending",
"status_url": "/v1/images/tasks?task_id=imgtask_EXAMPLE"
}Query only with the task_id query parameter; putting the task ID in the path is not supported.
| Status | Meaning |
|---|---|
pending / processing / retrying | In progress; keep polling |
completed | Done; read result_content |
failed | Failed; carries only an error string, no code |
The response once the task completes:
{
"task_id": "imgtask_EXAMPLE",
"status": "completed",
"result_content": "",
"usage": {
"cost": 1.36,
"currency": "CNY",
"cost_cny": 1.36,
"cost_usd": 0.2
}
}result_content has one line per image in the form , a relative path you prefix with https://api.hop-base.com. The URL requires no key to open, so do not share it publicly, and download it to your own storage soon.
Examples
Text to image
curl https://api.hop-base.com/v1/images/generations \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image",
"prompt": "A ceramic teapot on a sunlit wooden table, product photo",
"google": {
"image_config": { "aspect_ratio": "16:9", "image_size": "2K" }
}
}' \
| jq -r '.data[0].b64_json' | base64 --decode > result.pngThe curl example needs jq. If data[].mime_type is image/jpeg, rename the file to .jpg.
Edit with reference images
curl https://api.hop-base.com/v1/images/generations \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"prompt": "Recolor the cup in image 1 with the palette of image 2",
"images": [
"https://example.com/cup.png",
"https://example.com/palette.png"
],
"size": "1024x1024"
}'Notes
- Only Gemini (all models, incl. image) offers
/v1/images/edits; with the other group, send references to generations. - Results are Base64 and may be JPEG, so check
data[].mime_typebefore saving. maskis not supported; describe the area to change in the prompt.- Transparent output is not possible, and
background: "transparent"returns 400. stream: trueis not supported; keep the default sync mode or use async tasks.- For 2K / 4K images, add
Prefer: respond-async, or give sync requests a long client read timeout. - Before a paid request, take the full ID from
GET /v1/modelswith your key, and do not append a tier suffix.
- Both groups generate n images in parallel; it is all-or-nothing, so if any image fails, no partial result is returned or billed.
- Gemini Official Direct can also call image models through
/v1/chat/completions, returning the image as a markdown-embedded data URL. - The Chat Completions-to-Images bridge keeps only the first 6 references; call the Images endpoints directly for more.
- Async tasks check
size,n,image_config, andbackgroundat submission and return 400 if they are invalid. - Problems found only while generating, such as a failed reference download or a model refusal, fail the async task.
- Reference counts follow the Google image-generation guide.
- Google supports PNG / JPEG / WebP / HEIC / HEIF; prefer PNG / JPEG / WebP.
- Do not send raw base64, Google Files IDs, or
asset://. - Base64 adds roughly one third to the data size; the whole request body is capped at 60 MB, and larger bodies return 413.
- In Gemini Official Direct, the usage record shows the delivered WxH.
Common errors
Invalid parameters return 400 before generation and are not billed.
| Error | Fix |
|---|---|
prompt must not be empty / missing prompt | Send a non-empty prompt |
n=3 is too large for 4K output on model gemini-3-pro-image; … | Lower n or send separate requests |
model gemini-3.1-flash-image does not support tier 4K; supported: 1K, 2K | Use gemini-3-pro-image or a lower tier |
aspect_ratio "7:3" is not supported for model … | Use an official ratio |
mask is not supported for Gemini image models; … | Remove the mask; describe the area in the prompt |
background=transparent is not supported … | Remove background |
Gemini image generation does not support stream=true; … | Remove stream |
too many reference images: at most 14 are supported … | Send fewer references |
reference image 1: reference image exceeds the 20MB limit | Compress the image and retry |
reference image 1: reference image download returned HTTP 404 | Use a public URL the server can fetch |
| 400 (quoting model text) or 502 | The model declined or replied with text; rephrase |
# Gemini (all models, incl. image)
prompt must not be empty
n must be between 1 and 10 for model gemini-3-pro-image
n=3 is too large for 4K output on model gemini-3-pro-image; at most 2 images per request at this size (response size limit); lower n or send separate requests
model gemini-3.1-flash-image does not support tier 4K; supported: 1K, 2K
model gemini-3-pro-image: size "big" is not valid; expected WIDTHxHEIGHT (any aspect ratio, mapped to the nearest official tier) or 1K/2K/4K
aspect_ratio "7:3" is not supported for model gemini-3-pro-image; allowed values: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
image_size "4K" is not supported for model gemini-3.1-flash-image; supported: 1K, 2K
background=transparent is not supported for model gemini-3-pro-image; Gemini image models cannot output transparent images
mask is not supported for Gemini image models; remove mask and describe the region to edit in the prompt
too many reference images: at most 14 are supported for this model, got 15
# Gemini Official Direct
missing prompt
Gemini image generation does not support stream=true; send a non-streaming request
n must be at most 10
n=6 is too large for 2K output on model gemini-3.1-flash-image; at most 5 images per request at this size (response size limit); lower n or send separate requests
Images generations only accepts a JSON request body: ...
size 4K is not supported for model gemini-3.1-flash-image; supported tiers: 1K, 2K
size "banana" is not valid for model gemini-3-pro-image; use auto, WIDTHxHEIGHT (e.g. 1024x1024, mapped to the nearest supported aspect ratio and capped at the model's largest tier), or one of: 1K, 2K, 4K
image_config.aspect_ratio "7:3" is not supported; allowed values: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
image_config.image_size "4K" is not supported for model gemini-3.1-flash-image; allowed values: 1K, 2K
mask is not supported for model gemini-3-pro-image; remove mask and describe the region to edit in the prompt
background=transparent is not supported for model gemini-3-pro-image; Gemini image models cannot output transparent images
reference image 1: reference image exceeds the 20MB limit
reference image 1: reference image URL must not point to an internal address
reference image 1: reference image download returned HTTP 404
reference image 1: reference file is not a supported image typeBilling
Gemini (all models, incl. image) bills per image delivered; Gemini Official Direct bills by token, at the tier actually generated. Invalid parameters and partial failures are not billed; once an async task ends, usage.cost in the query response is the amount actually charged.
Prices are on each model card and in the signed-in model catalog.
Next steps
- Image generation overview
- GPT Image, Seedream, Grok Imagine images, Kling images
- API reference: Create image, Edit image, Query image task
- When something fails, check Troubleshooting