Skip to main content

Audio API

This page documents the 4 gateway endpoints tagged audio 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
POST/audio/speechGenerate speech audio from text
POST/v1/audio/speechGenerate speech audio from text
POST/audio/transcriptionsTranscribe an audio file
POST/v1/audio/transcriptionsTranscribe an audio file

Endpoints​

POST /audio/speech​

Generate speech audio from text

Turn text into spoken audio, in the OpenAI speech format. The body of the answer is the audio file itself in the requested response_format. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.

Request body (application/json, object):

FieldTypeRequiredDescription
modelstringYesModel
inputstringYesInput
voicestringYesVoice
response_formatenum: "mp3", "opus", "aac", "flac", "wav", "pcm" or nullNoResponse Format
speednumber or nullNoSpeed
instructionsstring or nullNoInstructions

Example request:

curl -X POST "http://localhost:4000/audio/speech" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Your order has shipped and will arrive on Thursday.",
"voice": "alloy",
"response_format": "mp3"
}'

Responses:

StatusDescriptionBody
200The audio bytes in the requested format, with a matching Content-Type header.audio/mpeg string
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

POST /v1/audio/speech​

Generate speech audio from text

Turn text into spoken audio, in the OpenAI speech format. The body of the answer is the audio file itself in the requested response_format. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.

Request body (application/json, object):

FieldTypeRequiredDescription
modelstringYesModel
inputstringYesInput
voicestringYesVoice
response_formatenum: "mp3", "opus", "aac", "flac", "wav", "pcm" or nullNoResponse Format
speednumber or nullNoSpeed
instructionsstring or nullNoInstructions

Example request:

curl -X POST "http://localhost:4000/v1/audio/speech" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Your order has shipped and will arrive on Thursday.",
"voice": "alloy",
"response_format": "mp3"
}'

Responses:

StatusDescriptionBody
200The audio bytes in the requested format, with a matching Content-Type header.audio/mpeg string
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

POST /audio/transcriptions​

Transcribe an audio file

Turn an audio file into text, in the OpenAI transcription format. Upload the file as multipart form data with the model name. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.

Request body (multipart/form-data, object):

FieldTypeRequiredDescription
filestringYesThe audio file, up to 25 MB
modelstringYesThe transcription model name on the gateway
languagestringNoISO-639-1 language of the audio, for example en
promptstringNoText that guides the style or spells out names
response_formatenum: "json", "text", "srt", "verbose_json", "vtt"NoShape of the transcript
temperaturenumberNoSampling temperature
timestamp_granularities[]array of enum: "word", "segment"NoTimestamp detail for verbose_json

Example request:

curl -X POST "http://localhost:4000/audio/transcriptions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F file="@file.bin" \
-F model="value"

Responses:

StatusDescriptionBody
200The transcript. With response_format=text the body is the plain transcript instead of JSON.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
textstring or nullNoText
usageobject or nullNoUsage

POST /v1/audio/transcriptions​

Transcribe an audio file

Turn an audio file into text, in the OpenAI transcription format. Upload the file as multipart form data with the model name. Any virtual key that may use the named model can call it. The gateway checks the key's budget, rate limits and guardrails first, sends the request to one of the model group's deployments with retries and fallbacks, and records the cost and usage in the spend logs. Nothing else changes.

Request body (multipart/form-data, object):

FieldTypeRequiredDescription
filestringYesThe audio file, up to 25 MB
modelstringYesThe transcription model name on the gateway
languagestringNoISO-639-1 language of the audio, for example en
promptstringNoText that guides the style or spells out names
response_formatenum: "json", "text", "srt", "verbose_json", "vtt"NoShape of the transcript
temperaturenumberNoSampling temperature
timestamp_granularities[]array of enum: "word", "segment"NoTimestamp detail for verbose_json

Example request:

curl -X POST "http://localhost:4000/v1/audio/transcriptions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F file="@file.bin" \
-F model="value"

Responses:

StatusDescriptionBody
200The transcript. With response_format=text the body is the plain transcript instead of JSON.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
textstring or nullNoText
usageobject or nullNoUsage