OhMyGPT

Image generation

Find an image model, work out what an image costs, and generate or edit images with the OpenAI Images API.

Image models answer on the OpenAI Images API: POST /v1/images/generations creates images from a prompt, and POST /v1/images/edits changes images you upload. OpenAI SDKs work as they are with the base URL https://api.ohmygpt.com/v1.

Find an image model

The Models page lists every image model with its price and a try-it panel. From code, ask the catalog for models that output images:

curl "https://api.ohmygpt.com/v1/models?output_modalities=image&include_unavailable=true"

The service field tells you which endpoint a model takes:

serviceEndpoint
image/v1/images/generations and /v1/images/edits
llmChat models that also output images, such as google/gemini-3.1-flash-image. Call them like any chat model: Chat Completions, Responses or the Gemini API.

A model with "available": false is available on request: open its page on the Models page and click Request it now. A call to it returns 503 model_unavailable with a link to that page. Video generation shows the full response and how to request a model that isn't listed.

Generate an image

curl https://api.ohmygpt.com/v1/images/generations \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-image-2", "prompt": "A watercolor map of a fictional island with a lighthouse", "size": "1024x1024", "quality": "low"}' \
  | jq -r '.data[0].b64_json' | base64 --decode > image.png

The image comes back as base64 in data[].b64_json. With the OpenAI SDK:

import base64
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.ohmygpt.com/v1", api_key=os.environ["OHMYGPT_API_KEY"])

result = client.images.generate(
    model="openai/gpt-image-2",
    prompt="A watercolor map of a fictional island with a lighthouse",
    size="1024x1024",
    quality="low",
)
with open("image.png", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))

n asks for several images in one request; each is charged.

Edit an image

POST /v1/images/edits takes the images as multipart form files, which is what the SDK sends:

result = client.images.edit(
    model="openai/gpt-image-2",
    image=open("image.png", "rb"),
    prompt="Add a small sailboat near the lighthouse",
)
with open("edited.png", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))

What an image costs

Most image models are priced per million tokens, like chat models: text input, image input (the images you upload to edit) and image output. The image output is almost all of the cost, and its token count depends on the size and quality you ask for.

For models whose provider publishes those counts, the catalog lists them in limits.image.output_tokens, by quality and size:

{
  "id": "openai/gpt-image-2",
  "limits": {
    "image": {
      "output_tokens": {
        "low": { "1024x1024": 196, "1024x1536": 158, "1536x1024": 158 },
        "medium": { "1024x1024": 1756, "1024x1536": 1372, "1536x1024": 1372 },
        "high": { "1024x1024": 7024, "1024x1536": 5488, "1536x1024": 5488 }
      }
    }
  }
}

An image costs about its output tokens times the image output price. gpt-image-2 charges $27 per million image output tokens, so a low-quality 1024×1024 image is 196 tokens, about $0.0053, and a high-quality one is 7,024 tokens, about $0.19.

Some models also list a price per image for each size and quality. That price applies when the provider doesn't report token usage for the request.

Ask for an estimate

POST /v1/cost-estimates takes the body you would send to /v1/images/generations and prices it at your account's prices, without generating anything:

curl https://api.ohmygpt.com/v1/cost-estimates \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-image-2", "prompt": "A watercolor map of a fictional island with a lighthouse", "size": "1024x1024", "quality": "low"}'
{
  "model": "openai/gpt-image-2",
  "estimated_input_cost": "16 credits",
  "max_output_cost": "1323 credits",
  "max_total_cost": "1339 credits",
  "credits": 1339,
  "confidence": "estimate",
  "estimated_input_tokens": 14,
  "max_output_tokens": 196
}

1,339 Credits is about $0.0054 (1 USD = 250,000 Credits). confidence says how far to trust credits:

confidenceWhen
estimatesize and quality are set and the model publishes output tokens for them. The output part is n images at the published count; the prompt part is estimated from its text.
upper_boundquality is left out or auto: the estimate uses the highest quality published for that size. The same body without quality returns "credits": 47428.
unavailableThe model, size or quality has no published counts, such as "size": "2048x2048" here. credits is 0; the price on the model page still applies.

Images you upload to edit aren't in the estimate.

Read what you paid

Every response carries the charge in the X-Cost-Credits header; see Costs for reading it from an SDK and looking requests up later.

Errors

StatuscodeWhat to do
400invalid_value, invalid_parameterA parameter the model doesn't take, in the model's own words, such as Invalid size '7x7'. Width and height must both be divisible by 16. Fix it and send again. You weren't charged.
400content_policy_violationThe model refused the prompt or image. Revise it and send again.
402insufficient_creditsYour balance can't cover the request. With a Retry-After header, your other unfinished requests have reserved the rest of your balance: wait that many seconds, or top up. Without it, top up on the Billing page.
503model_unavailableThe model is available on request, or can't take requests right now. Follow the message.

Before sending a request to the model, OhMyGPT reserves part of your balance for it, and releases it when the request finishes; a request the model rejects is free. The full list of status codes is on Errors.

Was this page helpful?

Still stuck? Live chat · [email protected] · Telegram group