Skip to main content

Batch API

This page documents the 12 gateway endpoints tagged batch 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.

MethodPathSummary
GET/batchesList batches
POST/batchesCreate a batch
GET/v1/batchesList batches
POST/v1/batchesCreate a batch
GET/{provider}/v1/batchesList batches
POST/{provider}/v1/batchesCreate a batch
GET/batches/{batch_id}Retrieve a batch
GET/v1/batches/{batch_id}Retrieve a batch
GET/{provider}/v1/batches/{batch_id}Retrieve a batch
POST/batches/{batch_id}/cancelCancel a batch
POST/v1/batches/{batch_id}/cancelCancel a batch
POST/{provider}/v1/batches/{batch_id}/cancelCancel a batch

Endpoints​

GET /batches​

List batches

Lists batch jobs newest first, one page at a time. Use limit for the page size and after with the last id from the previous page to read further. Any key may call it, managed batches are filtered to the ones the caller owns, and nothing changes. The answer follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches?limit=2 -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json"

Parameters:

NameInTypeRequiredDescription
providerquerystring or nullNoThe provider whose batches to list, for example openai, azure or vertex_ai. Used when no model or target_model_names picks the account. Defaults to openai.
limitqueryinteger or nullNoHow many batches to return, from 0 to 100. Outside that range the answer is a 400.
afterquerystring or nullNoReturn the batches after this batch id, taken from last_id of the previous page.
target_model_namesquerystring or nullNoList the batches of this model from model_list instead of the provider's default account.

Example request:

curl -X GET "http://localhost:4000/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200One page of batches, newest first. Pass last_id as after to read the next page.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
object"list"YesObject
dataarray of objectYesData
first_idstring or nullNoFirst Id
last_idstring or nullNoLast Id
has_morebooleanNoHas More

POST /batches​

Create a batch

Starts a batch job: the gateway sends every request in an uploaded JSONL file to the model at the provider's batch price and returns the results in an output file, usually within 24 hours. Any key allowed to use the model may call it, and the batch's cost is tracked against that key, its team and its user. The body follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h"
}'

Parameters:

NameInTypeRequiredDescription
providerquerystring or nullNo
x-spanway-modelheaderstringNoRun the batch on this model from model_list, the same as model in the body.
modelquerystringNoRun the batch on this model from model_list, the same as model in the body.

Request body (application/json, object):

FieldTypeRequiredDescription
input_file_idstringYesInput File Id
endpointenum: "/v1/chat/completions", "/v1/completions", "/v1/embeddings", "/v1/responses"YesEndpoint
completion_window"24h"YesCompletion Window
metadataobject or nullNoMetadata
modelstring or nullNoModel
custom_llm_providerstring or nullNoCustom Llm Provider

Example request:

curl -X POST "http://localhost:4000/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"metadata": {
"job": "nightly-summaries"
}
}'

Responses:

StatusDescriptionBody
200The batch object. Poll it until status is completed.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

GET /v1/batches​

List batches

Lists batch jobs newest first, one page at a time. Use limit for the page size and after with the last id from the previous page to read further. Any key may call it, managed batches are filtered to the ones the caller owns, and nothing changes. The answer follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches?limit=2 -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json"

Parameters:

NameInTypeRequiredDescription
providerquerystring or nullNoThe provider whose batches to list, for example openai, azure or vertex_ai. Used when no model or target_model_names picks the account. Defaults to openai.
limitqueryinteger or nullNoHow many batches to return, from 0 to 100. Outside that range the answer is a 400.
afterquerystring or nullNoReturn the batches after this batch id, taken from last_id of the previous page.
target_model_namesquerystring or nullNoList the batches of this model from model_list instead of the provider's default account.

Example request:

curl -X GET "http://localhost:4000/v1/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200One page of batches, newest first. Pass last_id as after to read the next page.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
object"list"YesObject
dataarray of objectYesData
first_idstring or nullNoFirst Id
last_idstring or nullNoLast Id
has_morebooleanNoHas More

POST /v1/batches​

Create a batch

Starts a batch job: the gateway sends every request in an uploaded JSONL file to the model at the provider's batch price and returns the results in an output file, usually within 24 hours. Any key allowed to use the model may call it, and the batch's cost is tracked against that key, its team and its user. The body follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h"
}'

Parameters:

NameInTypeRequiredDescription
providerquerystring or nullNo
x-spanway-modelheaderstringNoRun the batch on this model from model_list, the same as model in the body.
modelquerystringNoRun the batch on this model from model_list, the same as model in the body.

Request body (application/json, object):

FieldTypeRequiredDescription
input_file_idstringYesInput File Id
endpointenum: "/v1/chat/completions", "/v1/completions", "/v1/embeddings", "/v1/responses"YesEndpoint
completion_window"24h"YesCompletion Window
metadataobject or nullNoMetadata
modelstring or nullNoModel
custom_llm_providerstring or nullNoCustom Llm Provider

Example request:

curl -X POST "http://localhost:4000/v1/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"metadata": {
"job": "nightly-summaries"
}
}'

Responses:

StatusDescriptionBody
200The batch object. Poll it until status is completed.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

GET /{provider}/v1/batches​

List batches

Lists batch jobs newest first for the provider named in the path, one page at a time. It behaves like GET /v1/batches with the provider query parameter set.

Parameters:

NameInTypeRequiredDescription
providerpathstringYesThe provider whose batches to list, for example openai or azure.
limitqueryinteger or nullNoHow many batches to return, from 0 to 100. Outside that range the answer is a 400.
afterquerystring or nullNoReturn the batches after this batch id, taken from last_id of the previous page.
target_model_namesquerystring or nullNoList the batches of this model from model_list instead of the provider's default account.

Example request:

curl -X GET "http://localhost:4000/provider-123/v1/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200One page of batches, newest first. Pass last_id as after to read the next page.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
object"list"YesObject
dataarray of objectYesData
first_idstring or nullNoFirst Id
last_idstring or nullNoLast Id
has_morebooleanNoHas More

POST /{provider}/v1/batches​

Create a batch

Starts a batch job: the gateway sends every request in an uploaded JSONL file to the model at the provider's batch price and returns the results in an output file, usually within 24 hours. Any key allowed to use the model may call it, and the batch's cost is tracked against that key, its team and its user. The body follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h"
}'

Parameters:

NameInTypeRequiredDescription
providerpathstring or nullYes
x-spanway-modelheaderstringNoRun the batch on this model from model_list, the same as model in the body.
modelquerystringNoRun the batch on this model from model_list, the same as model in the body.

Request body (application/json, object):

FieldTypeRequiredDescription
input_file_idstringYesInput File Id
endpointenum: "/v1/chat/completions", "/v1/completions", "/v1/embeddings", "/v1/responses"YesEndpoint
completion_window"24h"YesCompletion Window
metadataobject or nullNoMetadata
modelstring or nullNoModel
custom_llm_providerstring or nullNoCustom Llm Provider

Example request:

curl -X POST "http://localhost:4000/provider-123/v1/batches" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"metadata": {
"job": "nightly-summaries"
}
}'

Responses:

StatusDescriptionBody
200The batch object. Poll it until status is completed.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

GET /batches/{batch_id}​

Retrieve a batch

Reads the current state of one batch job: its status, how many requests finished or failed and, once it is completed, the id of the output file to download. Any key that may use the batch's model can call it, a managed batch id only answers for the owner that created it, and nothing changes. The answer follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123 -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json"

Parameters:

NameInTypeRequiredDescription
batch_idpathstringYesThe ID of the batch to retrieve
providerquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/batches/batch_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The batch object with its current status and, once completed, the output file id.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

GET /v1/batches/{batch_id}​

Retrieve a batch

Reads the current state of one batch job: its status, how many requests finished or failed and, once it is completed, the id of the output file to download. Any key that may use the batch's model can call it, a managed batch id only answers for the owner that created it, and nothing changes. The answer follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123 -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json"

Parameters:

NameInTypeRequiredDescription
batch_idpathstringYesThe ID of the batch to retrieve
providerquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/v1/batches/batch_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The batch object with its current status and, once completed, the output file id.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

GET /{provider}/v1/batches/{batch_id}​

Retrieve a batch

Reads the current state of one batch job: its status, how many requests finished or failed and, once it is completed, the id of the output file to download. Any key that may use the batch's model can call it, a managed batch id only answers for the owner that created it, and nothing changes. The answer follows the OpenAI Batch API.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123 -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json"

Parameters:

NameInTypeRequiredDescription
providerpathstring or nullYes
batch_idpathstringYesThe ID of the batch to retrieve

Example request:

curl -X GET "http://localhost:4000/provider-123/v1/batches/batch_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The batch object with its current status and, once completed, the output file id.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

POST /batches/{batch_id}/cancel​

Cancel a batch

Stops a batch job that is still running. Requests already finished stay in the output and are charged, the rest are not sent. Any key that may use the batch's model can call it, and a managed batch id only for the owner that created it. The status moves to cancelling and then cancelled.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123/cancel -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -X POST

Parameters:

NameInTypeRequiredDescription
batch_idpathstringYes
providerquerystring or nullNo

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/batches/batch_id-123/cancel" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The batch while it is being cancelled.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

POST /v1/batches/{batch_id}/cancel​

Cancel a batch

Stops a batch job that is still running. Requests already finished stay in the output and are charged, the rest are not sent. Any key that may use the batch's model can call it, and a managed batch id only for the owner that created it. The status moves to cancelling and then cancelled.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123/cancel -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -X POST

Parameters:

NameInTypeRequiredDescription
batch_idpathstringYes
providerquerystring or nullNo

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/v1/batches/batch_id-123/cancel" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The batch while it is being cancelled.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo

POST /{provider}/v1/batches/{batch_id}/cancel​

Cancel a batch

Stops a batch job that is still running. Requests already finished stay in the output and are charged, the rest are not sent. Any key that may use the batch's model can call it, and a managed batch id only for the owner that created it. The status moves to cancelling and then cancelled.

Example Curl

curl http://localhost:4000/v1/batches/batch_abc123/cancel -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" -X POST

Parameters:

NameInTypeRequiredDescription
batch_idpathstringYes
providerpathstring or nullYes

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/provider-123/v1/batches/batch_id-123/cancel" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The batch while it is being cancelled.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
completion_windowstringYesCompletion Window
created_atintegerYesCreated At
endpointstringYesEndpoint
input_file_idstringYesInput File Id
object"batch"YesObject
statusenum: "validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"YesStatus
cancelled_atinteger or nullNoCancelled At
cancelling_atinteger or nullNoCancelling At
completed_atinteger or nullNoCompleted At
error_file_idstring or nullNoError File Id
errorsobject or nullNo
expired_atinteger or nullNoExpired At
expires_atinteger or nullNoExpires At
failed_atinteger or nullNoFailed At
finalizing_atinteger or nullNoFinalizing At
in_progress_atinteger or nullNoIn Progress At
metadataobject or nullNoMetadata
modelstring or nullNoModel
output_file_idstring or nullNoOutput File Id
request_countsobject or nullNo
usageobject or nullNo