Image Generation API
Separate documentation for the OpenAI image API and the Gemini generateContent image API, with corrected model IDs, parameter names, endpoints, and response shapes.
Understand the two API families first
The most common documentation mistake is mixing OpenAI image parameters with Gemini image parameters. These official APIs are not interchangeable. Their endpoints, field names, model IDs, and response structures differ.
- OpenAI official image API uses
/v1/images/generationsand/v1/images/edits. - Gemini official image API uses
/v1/models/{model}:generateContent. - OpenAI commonly uses
prompt,size,quality, andbackground. - Gemini commonly uses
contents,parts,responseModalities, andresponseFormat.image.
OpenAI official image API
Use the OpenAI image API for direct text-to-image generation. The official API distinguishes clearly between generations and edits.
import OpenAI from "openai";
import fs from "node:fs";
const client = new OpenAI({
apiKey: process.env.GPT88_API_KEY,
baseURL: "https://img.gpt88.cc",
});
const result = await client.images.generate({
model: "gpt-image-2",
prompt: "A children's book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter.",
size: "1024x1024",
quality: "high",
});
const imageBase64 = result.data[0].b64_json;
fs.writeFileSync("otter.png", Buffer.from(imageBase64, "base64"));OpenAI image editing
The official edit endpoint supports editing existing images, generating from references, and localized edits with masks. Do not rewrite this as Gemini-style contents.parts.fileData, because that belongs to a different API family.
import base64
from openai import OpenAI
client = OpenAI(
api_key="YOUR_GPT88_API_KEY",
base_url="https://img.gpt88.cc",
)
prompt = """
Generate a photorealistic image of a gift basket on a white background
labeled 'Relax & Unwind' with a ribbon and handwriting-like font,
containing all the items in the reference pictures.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("body-lotion.png", "rb"),
open("soap.png", "rb"),
open("bath-bomb.png", "rb"),
open("incense-kit.png", "rb"),
],
prompt=prompt,
size="1536x1024",
quality="high",
)
image_base64 = result.data[0].b64_json
with open("gift-basket.png", "wb") as f:
f.write(base64.b64decode(image_base64))Gemini official image API
Gemini image generation uses generateContent. In current Google documentation, Nano Banana 2 maps to gemini-3.1-flash-image, while Nano Banana Pro maps togemini-3-pro-image. Gemini documentation describes output usingresponseFormat.image.aspectRatio and responseFormat.image.imageSize.
export API_KEY="YOUR_GPT88_API_KEY"
export BASE_URL="https://img.gpt88.cc"
export MODEL="gemini-3.1-flash-image"
curl -s -X POST \
"$BASE_URL/v1/models/$MODEL:generateContent" \
-H "x-goog-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{ "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" }
]
}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"responseFormat": {
"image": {
"aspectRatio": "16:9",
"imageSize": "2K"
}
}
}
}' > response.json
jq -r '.. | objects | .inlineData?.data? | select(.)' response.json | head -n 1 | base64 -d > output.pngGemini image-to-image and editing
For Gemini image-to-image flows, the more reliable official pattern is: upload the image first, then call generateContent. Do not document public image URLs as the primary input path here. Upload the file first, then pass the returned fileData.fileUri.
export API_KEY="YOUR_GPT88_API_KEY"
export BASE_URL="https://img.gpt88.cc"
export MODEL="gemini-3.1-flash-image"
# Upload the reference image first
curl -s -X POST "$BASE_URL/upload/v1/files" \
-H "x-goog-api-key: $API_KEY" \
-F "[email protected]" \
-F "mimeType=image/png" > upload.json
FILE_URI=$(jq -r '.file.uri // .uri // .name' upload.json)
curl -s -X POST \
"$BASE_URL/v1/models/$MODEL:generateContent" \
-H "x-goog-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"contents\": [{
\"parts\": [
{ \"text\": \"Keep the main subject, change the background to a moonlit bamboo path\" },
{
\"fileData\": {
\"mimeType\": \"image/png\",
\"fileUri\": \"$FILE_URI\"
}
}
]
}],
\"generationConfig\": {
\"responseModalities\": [\"TEXT\", \"IMAGE\"],
\"responseFormat\": {
\"image\": {
\"aspectRatio\": \"1:1\",
\"imageSize\": \"1K\"
}
}
}
}" > response.jsonField reference
OpenAI image API
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Required | Official GPT Image model, such as gpt-image-2. |
prompt | string | Required | Instruction for image generation or editing. |
size | string | Optional | Pixel dimensions such as 1024x1024, 1536x1024, or 1024x1536. gpt-image-2 also supports more valid resolutions and auto. |
quality | string | Optional | low, medium, high, or auto. |
background | string | Optional | Official docs support opaque or auto. gpt-image-2 currently does not support transparent. |
output_format | string | Optional | PNG by default. JPEG and WebP are also supported. |
output_compression | integer | Optional | Available for JPEG / WebP, range 0-100. |
n | integer | Optional | Generate multiple images in one request. Default is 1. |
image | file | file[] | Optional | Input image(s) for the edit endpoint /v1/images/edits. |
mask | file | Optional | Optional mask for localized editing. Only the masked region is changed. |
modelstringRequiredOfficial GPT Image model, such asgpt-image-2.promptstringRequiredInstruction for image generation or editing.sizestringPixel dimensions such as1024x1024,1536x1024, or1024x1536.gpt-image-2also supports more valid resolutions andauto.qualitystringlow,medium,high, orauto.backgroundstringOfficial docs supportopaqueorauto.gpt-image-2currently does not supporttransparent.output_formatstringPNG by default. JPEG and WebP are also supported.output_compressionintegerAvailable for JPEG / WebP, range 0-100.nintegerGenerate multiple images in one request. Default is 1.imagefile | file[]Input image(s) for the edit endpoint/v1/images/edits.maskfileOptional mask for localized editing. Only the masked region is changed.
Gemini image API
| Field | Type | Required | Description |
|---|---|---|---|
contents | array<Content> | Required | Gemini generateContent input. |
contents[].parts[].text | string | Required | Prompt text. |
contents[].parts[].inlineData | object | Optional | Reference images can be passed inline as base64 with mimeType and data. |
contents[].parts[].fileData | object | Optional | Reference images can also be passed by uploaded fileUri. |
generationConfig.responseModalities | string[] | Optional | Common values are ["IMAGE"] or ["TEXT", "IMAGE"]. |
generationConfig.responseFormat.image.aspectRatio | string | Optional | Official aspect-ratio enums such as 1:1, 16:9, 9:16, 4:3, or 3:4. |
generationConfig.responseFormat.image.imageSize | string | Optional | Some Gemini 3 image models support 1K, 2K, and 4K. |
contentsarray<Content>RequiredGeminigenerateContentinput.contents[].parts[].textstringRequiredPrompt text.contents[].parts[].inlineDataobjectReference images can be passed inline as base64 withmimeTypeanddata.contents[].parts[].fileDataobjectReference images can also be passed by uploadedfileUri.generationConfig.responseModalitiesstring[]Common values are["IMAGE"]or["TEXT", "IMAGE"].generationConfig.responseFormat.image.aspectRatiostringOfficial aspect-ratio enums such as1:1,16:9,9:16,4:3, or3:4.generationConfig.responseFormat.image.imageSizestringSome Gemini 3 image models support1K,2K, and4K.
gpt88.cc compatibility notes
- If you are using an OpenAI-compatible image model such as
gpt-image-2, prefer/v1/images/generationsand/v1/images/edits. - If you are using a Google / Gemini image model, prefer
/v1/models/{model}:generateContent. - If the console shows a platform alias such as
NanoBanana2, use the console model list as the source of truth, then map it to the relevant official API family. - For more entries, see Models and the Codex gpt-image-2 Skill guide.