Models Hub
API ReferenceImages

Image Generation Guide

How to call gpt-image-2 and the Gemini image models — sizes, quality tiers, parameters and examples.

Edit this page

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

ModelNotesEndpoint
gpt-image-2OpenAI image model, output size matches the request exactly, up to 3840×2160OpenAI-compatible
gemini-2.5-flash-image-previewGemini fast imageOpenAI-compatible / Gemini native
gemini-2.5-flash-imageGemini fast imageGemini native
gemini-3.1-flash-image-previewGemini fast imageGemini native
gemini-3-pro-image-previewGemini high-quality imageGemini 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):

ConditionError when violated
Width and height must both be multiples of 16Width and height must both be divisible by 16
Total pixels between 655,360 and 8,294,400below / exceeds the current pixel budget
Longest edge ≤ 3840The longest edge must be less than or equal to 3840

Common sizes:

Aspect ratioValid size
1:11024x1024, 2048x2048
4:3 / 3:41024x768, 2048x1536 / 768x1024, 1536x2048
3:2 / 2:31536x1024 / 1024x1536
5:4 / 4:51280x1024 / 1024x1280
16:9 / 9:162048x1152, 3840x2160 / 1152x2048, 2160x3840
21:92688x1152

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.

qualityRelative priceLatency (1024×1024)Suggested use
low (default)~26sDrafts, batch previews
medium~9×~43sEveryday production
high~36×~109sFinal 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 default url returns a temporary object-storage link that may expire and occasionally times out on download. Using b64_json gives you the image data directly and is more robust to integrate. This parameter is available for Gemini models only — gpt-image-2 does 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 ![image](https://...)) rather than as inlineData. Extract the URL from the text and download it. To get standard image data directly, use gemini-2.5-flash-image-preview via the OpenAI-compatible endpoint instead.

Response example:

{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [{ "text": "![image](https://.../xxxx.png)" }]
    }
  }]
}

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.

On this page