Image variations
/v1/images/variations takes an image and returns new images in the same style and composition, without a text prompt. The gateway accepts the OpenAI multipart request, forwards it to the provider behind the public model name, and records cost per image like the other image endpoints.
Scenario
A design team has one approved logo draft and wants a handful of alternatives in the same style to pick from. They upload the draft once and ask for two variations, and the gateway bills the team's key for two images.
Steps
-
Register a model that offers variations. In the Admin UI open Models + Endpoints (
/ui/models-and-endpoints), click Add Model, pick the Provider, choose the model, set the Public Model Name todall-e-2and click Add Model.model_list:- model_name: dall-e-2spanway_params:model: openai/dall-e-2api_key: os.environ/OPENAI_API_KEY -
Create a key in Virtual Keys (
/ui/api-keys) and pick the model under Models. -
Request variations.
curl -X POST http://localhost:4000/v1/images/variations \-H "Authorization: Bearer $SPANWAY_API_KEY" \-F "model=dall-e-2" \-F "image=@logo.png" \-F "n=2" \-F "size=1024x1024" -
Check the cost in Logs (
/ui/logs). The row shows two images times the per-image price.
Expected result
{
"created": 1760441234,
"data": [{"url": "https://..."}, {"url": "https://..."}]
}
Request fields
| Field | Meaning |
|---|---|
image | The source image, a square PNG for OpenAI models. |
n | Number of variations. |
size | Output size. |
response_format | url or b64_json. |
user | End user identifier. |
Variations are supported by a small set of providers, listed below. For models that do not offer variations, use image edits with a prompt describing the desired change, or image generation with the original prompt and a different seed.
Gateway features
Keys, budgets, rate limits, guardrails and cost tracking apply. Requests go through the router, so load balancing, retries and fallbacks between deployments behave as they do for chat completions. Cost is the number of images requested with n (1 when unset) times the per-image price of the deployment, which a deployment can set with output_cost_per_image under model_info. general_settings.max_request_size_mb caps the size of the whole request, upload included.
Errors
| Status | What it means | Fix |
|---|---|---|
400 BadRequestError | The image is not a square PNG, is too large for the provider, or the model does not offer variations. | Convert the image, or use a model listed below. |
| 413 | The request is larger than general_settings.max_request_size_mb. | Shrink the image or raise the limit. |
401 AuthenticationError | The key is missing, wrong or expired. | Use a live key. |
403 PermissionDeniedError | The key may not use the model. | Add the model to the key. |
429 RateLimitError | Budget or rate limit reached. | Raise the limit. |
Related
- Image generation and image edits.
- Custom pricing for
output_cost_per_image.
Providers
The gateway's endpoint support matrix marks 2 provider integrations as supporting this endpoint: