Skip to main content

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​

  1. 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 to dall-e-2 and click Add Model.

    model_list:
    - model_name: dall-e-2
    spanway_params:
    model: openai/dall-e-2
    api_key: os.environ/OPENAI_API_KEY
  2. Create a key in Virtual Keys (/ui/api-keys) and pick the model under Models.

  3. 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"
  4. 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​

FieldMeaning
imageThe source image, a square PNG for OpenAI models.
nNumber of variations.
sizeOutput size.
response_formaturl or b64_json.
userEnd 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​

StatusWhat it meansFix
400 BadRequestErrorThe 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.
413The request is larger than general_settings.max_request_size_mb.Shrink the image or raise the limit.
401 AuthenticationErrorThe key is missing, wrong or expired.Use a live key.
403 PermissionDeniedErrorThe key may not use the model.Add the model to the key.
429 RateLimitErrorBudget or rate limit reached.Raise the limit.

Providers​

The gateway's endpoint support matrix marks 2 provider integrations as supporting this endpoint:

OpenAI, Topaz.