Image Generation Guide
How to call gpt-image-2 and the Gemini image models — sizes, quality tiers, parameters and examples.
modelsok offers several AI image models. The base URL is https://modelsok.com, authenticated with Authorization: Bearer <API Key>. This page explains how to call each model and shares practical tips.
Available models
| Model | Notes | Endpoint |
|---|---|---|
gpt-image-2 | OpenAI image model, output size matches the request exactly, up to 3840×2160 | OpenAI-compatible |
gemini-2.5-flash-image-preview | Gemini fast image | OpenAI-compatible / Gemini native |
gemini-2.5-flash-image | Gemini fast image | Gemini native |
gemini-3.1-flash-image-preview | Gemini fast image | Gemini native |
gemini-3-pro-image-preview | Gemini high-quality image | Gemini native |
gpt-image-2
Size rules
The output size exactly matches the requested size. That size must satisfy all three conditions below, otherwise the API returns an explicit error (it never silently falls back to a different size):
| Condition | Error when violated |
|---|---|
| Width and height must both be multiples of 16 | Width and height must both be divisible by 16 |
| Total pixels between 655,360 and 8,294,400 | below / exceeds the current pixel budget |
| Longest edge ≤ 3840 | The longest edge must be less than or equal to 3840 |
Common sizes:
| Aspect ratio | Valid size |
|---|---|
| 1:1 | 1024x1024, 2048x2048 |
| 4:3 / 3:4 | 1024x768, 2048x1536 / 768x1024, 1536x2048 |
| 3:2 / 2:3 | 1536x1024 / 1024x1536 |
| 5:4 / 4:5 | 1280x1024 / 1024x1280 |
| 16:9 / 9:16 | 2048x1152, 3840x2160 / 1152x2048, 2160x3840 |
| 21:9 | 2688x1152 |
4096x4096 is rejected because it exceeds the longest-edge limit. Use 3840x2160 for 4K.
Quality tiers
The optional quality parameter accepts low / medium / high and defaults to low. It affects quality, latency and price at the same time, so specify it explicitly based on your use case.
| quality | Relative price | Latency (1024×1024) | Suggested use |
|---|---|---|---|
low (default) | 1× | ~26s | Drafts, batch previews |
medium | ~9× | ~43s | Everyday production |
high | ~36× | ~109s | Final deliverables |
Text to image
curl https://modelsok.com/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "a red panda eating bamboo, flat vector illustration",
"size": "1024x1024",
"quality": "medium"
}'Image to image / editing
Pass a publicly reachable image URL in the image field — no file upload needed. Pass an array to submit multiple reference images (up to 16).
curl https://modelsok.com/v1/images/edits \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "make the mug matte black, keep the composition unchanged",
"image": "https://your-cdn/reference.png",
"size": "3840x2160",
"quality": "medium"
}'gpt-image-2 does not accept the response_format parameter — sending it returns
400 Unknown parameter: 'response_format'. Results are always returned as b64_json (Base64 image data).
Response example:
{
"created": 1780888000,
"data": [{ "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }]
}Python example
import base64, requests
resp = requests.post(
"https://modelsok.com/v1/images/edits",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model": "gpt-image-2",
"prompt": "a red panda eating bamboo, flat vector illustration",
"image": "https://your-cdn/reference.png",
"size": "2048x2048",
"quality": "medium",
},
timeout=300,
)
data = resp.json()["data"][0]["b64_json"]
open("out.png", "wb").write(base64.b64decode(data))A single image-to-image call typically takes 20–110 seconds (longer at higher
quality). Set your client timeout to at least 300 seconds and add retries.
Gemini models
Option 1: OpenAI-compatible endpoint
Works for gemini-2.5-flash-image-preview.
curl https://modelsok.com/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-flash-image-preview",
"prompt": "a red panda eating bamboo, flat vector illustration",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'Prefer
response_format: "b64_json". The defaulturlreturns a temporary object-storage link that may expire and occasionally times out on download. Usingb64_jsongives you the image data directly and is more robust to integrate. This parameter is available for Gemini models only —gpt-image-2does not support it.
Option 2: Gemini native endpoint
Works for all Gemini image models. Note the trailing slash in the path.
curl "https://modelsok.com/v1beta/models/gemini-2.5-flash-image:generateContent/" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{ "parts": [{ "text": "a blue cartoon cat, white background" }] }]
}'Note: the Gemini native endpoint usually returns the image as a Markdown image link embedded in text (under
candidates[0].content.parts[].text, like) rather than asinlineData. Extract the URL from the text and download it. To get standard image data directly, usegemini-2.5-flash-image-previewvia the OpenAI-compatible endpoint instead.
Response example:
{
"candidates": [{
"content": {
"role": "model",
"parts": [{ "text": "" }]
}
}]
}Billing
gpt-image-2 is billed by token usage — the cost depends on the output size (size), the quality tier (quality) and the reference image size. Larger outputs and higher tiers cost more. The other image models are billed per call (a fixed amount per generation).
See the Model Marketplace for exact prices, which vary by account tier.