Images
Generate and edit images with OpenAI, Gemini, Together, xAI and OpenRouter models through one API.
Draw an image from a prompt with POST https://gateway.respan.ai/v1/images/generations, or change an image you send with POST https://gateway.respan.ai/v1/images/edits. Both follow OpenAI’s Images API, and each call is logged with its cost. See All API formats.
Quickstart
curl https://gateway.respan.ai/v1/images/generations \
-H "Authorization: Bearer $RESPAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-image-1", "prompt": "A lighthouse at dusk, watercolor"}'Respan parameters work here as on chat: see Respan parameters.
Models and providers
| Provider | Generations | Edits |
|---|---|---|
| OpenAI | Yes | Yes |
| Gemini | Yes | Yes, without masks |
| Together AI | Yes | Yes |
| xAI | Yes | Yes |
| OpenRouter | Yes | Yes, without masks |
To find a model, filter by output type image on the model catalog . A bare model name, such as gpt-image-1, goes to any provider that serves it. To pin one provider, prefix it, such as openai/gpt-image-1. See Models.
Edit an image
Send the image as multipart form data, or as JSON that names each image by URL.
result = client.images.edit(
model="gpt-image-1",
image=open("lighthouse.png", "rb"),
prompt="Add a full moon above the lighthouse",
)Add mask to change only part of the image. Gemini and OpenRouter take no mask. A multipart edit has no JSON body, so send its Respan parameters in the X-Data-Respan-Params header (base64 JSON).
Image variations (/v1/images/variations) are not served.
Sizes
Set size, such as 1024x1024, and n for how many images to make. OpenAI, Together and xAI take size as is. Gemini draws only certain aspect ratios, so a size is mapped to the nearest one within 5%, or refused with 400.
Output
The response follows OpenAI’s Images shape. Each image in data comes back as b64_json or as a url, depending on what the provider returns.
Pricing and logs
- Each call is one trace with one
imagerow. The row keeps each image as a URL: the provider’s, or adata:URL of its bytes. An edit’s input image bytes are not kept. - The row is priced from the provider’s usage: image output at the model’s image output rate, and an edit’s input images at its image input rate where the catalog states one. OpenRouter and xAI report their own charge, which is used as is.
- Before a call on Respan’s credits is sent, the gateway holds the model’s per-image price for each image asked for, or, without one, the prompt plus 8,192 output tokens per image at its image rate.
- On Respan’s credits, a model with no catalog price is refused with
400, even when its provider reports a cost. A model priced at $0 is served free. - An answer on Respan’s credits that reports no billable usage is refused with
502 no_billable_usageand charged nothing. - A non-streamed image call runs to its end even if your client disconnects, so it is charged its reported usage.
- Image calls pass the same checks as chat (limit policies, RPM, key usage cap, customer budgets), with no TPM limit and no customer rate limit. See Limits.
- Image requests are not redacted, so an organization with PII redaction on is refused.