Images API
This page documents the 8 gateway endpoints tagged images in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| POST | /openai/deployments/{model}/images/generations | Generate images from a prompt |
| POST | /images/generations | Generate images from a prompt |
| POST | /v1/images/generations | Generate images from a prompt |
| POST | /openai/deployments/{model}/images/edits | Edit images with a prompt |
| POST | /images/edits | Edit images with a prompt |
| POST | /v1/images/edits | Edit images with a prompt |
| POST | /images/variations | Create variations of an image |
| POST | /v1/images/variations | Create variations of an image |
Endpoints
POST /openai/deployments/{model}/images/generations
Generate images from a prompt
Create one or more images from a text prompt in the OpenAI images format. The gateway translates the request for the image provider behind the public model name, returns the images as base64 data or URLs, and records the cost per image.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | path | string or null | Yes |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string | Yes | Prompt |
n | integer or null | No | N |
size | string or null | No | Size |
quality | string or null | No | Quality |
style | string or null | No | Style |
response_format | string or null | No | Response Format |
output_format | string or null | No | Output Format |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/openai/deployments/model-123/images/generations" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A lighthouse on a cliff at dawn, watercolor",
"n": 1,
"size": "1024x1024"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /images/generations
Generate images from a prompt
Create one or more images from a text prompt in the OpenAI images format. The gateway translates the request for the image provider behind the public model name, returns the images as base64 data or URLs, and records the cost per image.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string | Yes | Prompt |
n | integer or null | No | N |
size | string or null | No | Size |
quality | string or null | No | Quality |
style | string or null | No | Style |
response_format | string or null | No | Response Format |
output_format | string or null | No | Output Format |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/images/generations" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A lighthouse on a cliff at dawn, watercolor",
"n": 1,
"size": "1024x1024"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /v1/images/generations
Generate images from a prompt
Create one or more images from a text prompt in the OpenAI images format. The gateway translates the request for the image provider behind the public model name, returns the images as base64 data or URLs, and records the cost per image.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string | Yes | Prompt |
n | integer or null | No | N |
size | string or null | No | Size |
quality | string or null | No | Quality |
style | string or null | No | Style |
response_format | string or null | No | Response Format |
output_format | string or null | No | Output Format |
user | string or null | No | User |
Example request:
curl -X POST "http://localhost:4000/v1/images/generations" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A lighthouse on a cliff at dawn, watercolor",
"n": 1,
"size": "1024x1024"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /openai/deployments/{model}/images/edits
Edit images with a prompt
Changes one or more uploaded images as the prompt describes, for example putting a product photo on a new
background, in the OpenAI images format. Send the images as multipart form fields (image or repeated
image[]) with an optional mask whose transparent area marks what to change. Any key allowed to call the image
model may use it; the gateway applies the key's limits and guardrails and records the cost per image.
Follows the OpenAI Images API spec: https://platform.openai.com/docs/api-reference/images/create
curl -s -D >(grep -i x-request-id >&2) -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) -X POST "http://localhost:4000/v1/images/edits" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -F "model=gpt-image-2" -F "image[]=@soap.png" -F 'prompt=Create a studio ghibli image of this'
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | path | string or null | Yes |
Request body (multipart/form-data, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | No | The image model name on the gateway |
prompt | string | No | What to change in the image |
image | array of string | No | The image or images to edit |
image[] | array of string | No | The images to edit, as repeated image[] fields |
mask | array of string | No | A mask whose transparent area marks what to edit |
mask[] | array of string | No | The mask as a repeated mask[] field |
n | integer | No | Number of images |
size | string | No | Output size, for example 1024x1024 |
quality | enum: "high", "medium", "low", "standard", "auto" | No | |
background | enum: "transparent", "opaque", "auto" | No | |
input_fidelity | enum: "high", "low" | No | |
response_format | enum: "url", "b64_json" | No | How images return |
user | string | No | Your end user id, for abuse tracking |
Example request:
curl -X POST "http://localhost:4000/openai/deployments/model-123/images/edits" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /images/edits
Edit images with a prompt
Changes one or more uploaded images as the prompt describes, for example putting a product photo on a new
background, in the OpenAI images format. Send the images as multipart form fields (image or repeated
image[]) with an optional mask whose transparent area marks what to change. Any key allowed to call the image
model may use it; the gateway applies the key's limits and guardrails and records the cost per image.
Follows the OpenAI Images API spec: https://platform.openai.com/docs/api-reference/images/create
curl -s -D >(grep -i x-request-id >&2) -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) -X POST "http://localhost:4000/v1/images/edits" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -F "model=gpt-image-2" -F "image[]=@soap.png" -F 'prompt=Create a studio ghibli image of this'
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No |
Request body (multipart/form-data, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The image model name on the gateway |
prompt | string | No | What to change in the image |
image | array of string | No | The image or images to edit |
image[] | array of string | No | The images to edit, as repeated image[] fields |
mask | array of string | No | A mask whose transparent area marks what to edit |
mask[] | array of string | No | The mask as a repeated mask[] field |
n | integer | No | Number of images |
size | string | No | Output size, for example 1024x1024 |
quality | enum: "high", "medium", "low", "standard", "auto" | No | |
background | enum: "transparent", "opaque", "auto" | No | |
input_fidelity | enum: "high", "low" | No | |
response_format | enum: "url", "b64_json" | No | How images return |
user | string | No | Your end user id, for abuse tracking |
Example request:
curl -X POST "http://localhost:4000/images/edits" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F model="value"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /v1/images/edits
Edit images with a prompt
Changes one or more uploaded images as the prompt describes, for example putting a product photo on a new
background, in the OpenAI images format. Send the images as multipart form fields (image or repeated
image[]) with an optional mask whose transparent area marks what to change. Any key allowed to call the image
model may use it; the gateway applies the key's limits and guardrails and records the cost per image.
Follows the OpenAI Images API spec: https://platform.openai.com/docs/api-reference/images/create
curl -s -D >(grep -i x-request-id >&2) -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) -X POST "http://localhost:4000/v1/images/edits" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -F "model=gpt-image-2" -F "image[]=@soap.png" -F 'prompt=Create a studio ghibli image of this'
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string or null | No |
Request body (multipart/form-data, object):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The image model name on the gateway |
prompt | string | No | What to change in the image |
image | array of string | No | The image or images to edit |
image[] | array of string | No | The images to edit, as repeated image[] fields |
mask | array of string | No | A mask whose transparent area marks what to edit |
mask[] | array of string | No | The mask as a repeated mask[] field |
n | integer | No | Number of images |
size | string | No | Output size, for example 1024x1024 |
quality | enum: "high", "medium", "low", "standard", "auto" | No | |
background | enum: "transparent", "opaque", "auto" | No | |
input_fidelity | enum: "high", "low" | No | |
response_format | enum: "url", "b64_json" | No | How images return |
user | string | No | Your end user id, for abuse tracking |
Example request:
curl -X POST "http://localhost:4000/v1/images/edits" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F model="value"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /images/variations
Create variations of an image
Creates new versions of one uploaded square PNG image, keeping its subject and style, in the OpenAI images format. Send the image and the model as multipart form fields. Any key allowed to call the image model may use it; the gateway applies the key's limits and records the cost per image.
Follows the OpenAI Images API spec: https://platform.openai.com/docs/api-reference/images/createVariation
curl -X POST "http://localhost:4000/v1/images/variations" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -F "model=dall-e-2" -F "image=@otter.png" -F "n=2" -F "size=1024x1024"
Request body (multipart/form-data, object):
| Field | Type | Required | Description |
|---|---|---|---|
image | string | Yes | The square PNG image to vary, under 4 MB |
model | string | Yes | The image model name on the gateway |
n | integer | No | Number of images |
size | string | No | Output size, for example 1024x1024 |
response_format | enum: "url", "b64_json" | No | How images return |
user | string | No | Your end user id, for abuse tracking |
Example request:
curl -X POST "http://localhost:4000/images/variations" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F image="@file.bin" \
-F model="value"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |
POST /v1/images/variations
Create variations of an image
Creates new versions of one uploaded square PNG image, keeping its subject and style, in the OpenAI images format. Send the image and the model as multipart form fields. Any key allowed to call the image model may use it; the gateway applies the key's limits and records the cost per image.
Follows the OpenAI Images API spec: https://platform.openai.com/docs/api-reference/images/createVariation
curl -X POST "http://localhost:4000/v1/images/variations" -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -F "model=dall-e-2" -F "image=@otter.png" -F "n=2" -F "size=1024x1024"
Request body (multipart/form-data, object):
| Field | Type | Required | Description |
|---|---|---|---|
image | string | Yes | The square PNG image to vary, under 4 MB |
model | string | Yes | The image model name on the gateway |
n | integer | No | Number of images |
size | string | No | Output size, for example 1024x1024 |
response_format | enum: "url", "b64_json" | No | How images return |
user | string | No | Your end user id, for abuse tracking |
Example request:
curl -X POST "http://localhost:4000/v1/images/variations" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F image="@file.bin" \
-F model="value"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The images as base64 data or URLs, in the OpenAI images shape. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created | integer | Yes | Created |
background | enum: "transparent", "opaque" or null | No | Background |
data | array of object or null | No | Data |
output_format | enum: "png", "webp", "jpeg" or null | No | Output Format |
quality | enum: "low", "medium", "high" or null | No | Quality |
size | enum: "1024x1024", "1024x1536", "1536x1024" or null | No | Size |
usage | object or null | No |