Skip to content

Image generation

POST /v1/images/generations takes the OpenAI image request shape and returns the OpenAI image response shape, so the openai SDK works against it with the base URL swapped.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.cloakray.com/v1",
  apiKey: process.env.CLOAKRAY_API_KEY,
});

const result = await client.images.generate({
  model: "gemini-3-pro-image-preview",
  prompt: "a quartz crystal on a workbench, studio lighting",
  n: 1,
});

console.log(result.data[0].b64_json);
curl https://api.cloakray.com/v1/images/generations \
  -H "Authorization: Bearer $CLOAKRAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-pro-image-preview",
    "prompt": "a quartz crystal on a workbench, studio lighting",
    "n": 1
  }'

Options

ParameterWhat it does
promptRequired. What the image should show.
nHow many images to generate in one request.
sizeGemini image models take a resolution label (1K, 2K, 4K); GPT Image models take pixel dimensions such as 1024x1536, or auto.
aspect_ratioOn Gemini image models: 1:1, 16:9, 9:16, 4:3 and others.
qualityOn GPT Image models: low, medium, high or auto.

Each model's page lists the values it takes and what each one costs. Images come back as b64_json in data; decode and save them. To change an existing image instead, see image editing.

Image models are their own thing

Use a model whose catalogue entry lists /v1/images/generations. Other models may support image inputs or outputs through different interfaces; do not infer that every image-capable model uses only this endpoint. Unsupported model/endpoint pairs are refused. For editing an existing image, see POST /v1/images/edits.

The models page marks which models generate images, and GET /v1/models lists them alongside the text models.

How image pricing works

Text models are quoted per 1M tokens. Image models are not, and providers do not agree on a single unit:

ModelBilledWhat you see
gemini-3-pro-image-previewPer generated image, by resolution$0.10 / image at 1K and 2K, more at 4K
gpt-image-2Per 1M image-output tokensA per-token price, since no per-image figure is published
gemini-2.5-flash-imagePer token, like a text modelStandard input and output token prices

Each model's page shows the unit that model actually bills in, at the rate you pay. No gateway fee is added on top of it, the same as everywhere else.

What you are charged

Your bill is the cost the request actually incurred, at the rate shown for the model. Nothing is estimated from the prompt, and nothing is rounded up to a per-image figure when the provider billed per token. That is why the resolution you ask for changes the price on models that price by resolution: a 4K image genuinely costs more to produce than a 1K one.

Streaming

There is no streaming form of this endpoint. An image request returns once, with the finished image.