Skip to main content

Realtime API

This page documents the 6 gateway endpoints tagged realtime 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/realtime/callsStart a WebRTC realtime call
POST/realtime/client_secretsCreate an ephemeral realtime client secret
POST/realtime/transcription_sessionsCreate a realtime transcription session
POST/v1/realtime/callsStart a WebRTC realtime call
POST/v1/realtime/client_secretsCreate an ephemeral realtime client secret
POST/v1/realtime/transcription_sessionsCreate a realtime transcription session

Endpoints​

POST /realtime/calls​

Start a WebRTC realtime call

Exchange the browser's SDP offer for the provider's SDP answer. The Authorization bearer token is the ephemeral client secret from /v1/realtime/client_secrets, not a virtual key.

This is the second step of a browser voice session: the app sends its WebRTC offer (application/sdp) and gets back the answer that opens the audio connection to the model. The call is billed and logged against the virtual key that created the client secret. An expired or unknown client secret answers 401.

Request body (application/sdp, string):

Example request:

curl -X POST "http://localhost:4000/realtime/calls" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The provider's SDP answer.application/sdp 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
401The client secret is missing, unreadable or expired: Missing or invalid Authorization header, Invalid or expired token, Token has expiredapplication/json object
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 /realtime/client_secrets​

Create an ephemeral realtime client secret

Issue a short lived client secret for a browser or mobile client so the long lived virtual key stays on your server. The secret is bound to the model and session settings in the body and expires after the time in expires_after.

Use it when a web page or phone app talks to a voice model directly over WebRTC: your server calls this with its virtual key, then hands the returned value to the app, which sends it to /v1/realtime/calls. Any virtual key allowed to use the model may call it, and the key's budget, rate limits and model access apply. A caller without a virtual key is refused with 400. The gateway encrypts the provider's secret before returning it, so the app never sees the provider key. Each secret writes an audit row on the calling key, without the secret value, and nothing else is stored.

Request body (application/json, object):

FieldTypeRequiredDescription
expires_afterobject or nullNoHow long the secret stays valid
modelstring or nullNoGateway model to route to when session.model is absent, not forwarded
sessionobject or nullNoThe realtime session the secret is bound to, model included

Example request:

curl -X POST "http://localhost:4000/realtime/client_secrets" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"expires_after": {
"anchor": "created_at",
"seconds": 600
},
"session": {
"model": "gpt-realtime",
"type": "realtime"
}
}'

Responses:

StatusDescriptionBody
200The client secret for the browser or mobile app, encrypted by the gatewayapplication/json RealtimeClientSecretResponse
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
expires_atinteger or nullNoWhen the secret expires, in Unix seconds
sessionobject or nullNoThe session as the provider created it
valuestringYesThe client secret to hand to the browser or mobile app

POST /realtime/transcription_sessions​

Create a realtime transcription session

Create an ephemeral Realtime transcription session (POST /v1/realtime/transcription_sessions) for the WebRTC/WebSocket flow.

Use it for live captions or dictation in a browser or phone app: your server calls this with its virtual key and hands the returned client_secret.value to the app, which streams audio and receives text. Any key allowed to use the transcription model may call it, and the key's budget, rate limits and model access apply. The gateway encrypts the provider's ephemeral key under client_secret.value, so the app never sees the provider key.

Request body (application/json, object):

FieldTypeRequiredDescription
input_audio_transcriptionobject or nullNoInput Audio Transcription
modelstring or nullNoModel

Example request:

curl -X POST "http://localhost:4000/realtime/transcription_sessions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_audio_transcription": {
"language": "en",
"model": "gpt-4o-transcribe"
},
"model": "gpt-realtime"
}'

Responses:

StatusDescriptionBody
200The ephemeral client secret for the transcription session.application/json RealtimeTranscriptionSessionResponse
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
client_secretobject or nullNoClient Secret

POST /v1/realtime/calls​

Start a WebRTC realtime call

Exchange the browser's SDP offer for the provider's SDP answer. The Authorization bearer token is the ephemeral client secret from /v1/realtime/client_secrets, not a virtual key.

This is the second step of a browser voice session: the app sends its WebRTC offer (application/sdp) and gets back the answer that opens the audio connection to the model. The call is billed and logged against the virtual key that created the client secret. An expired or unknown client secret answers 401.

Request body (application/sdp, string):

Example request:

curl -X POST "http://localhost:4000/v1/realtime/calls" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The provider's SDP answer.application/sdp 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
401The client secret is missing, unreadable or expired: Missing or invalid Authorization header, Invalid or expired token, Token has expiredapplication/json object
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/realtime/client_secrets​

Create an ephemeral realtime client secret

Issue a short lived client secret for a browser or mobile client so the long lived virtual key stays on your server. The secret is bound to the model and session settings in the body and expires after the time in expires_after.

Use it when a web page or phone app talks to a voice model directly over WebRTC: your server calls this with its virtual key, then hands the returned value to the app, which sends it to /v1/realtime/calls. Any virtual key allowed to use the model may call it, and the key's budget, rate limits and model access apply. A caller without a virtual key is refused with 400. The gateway encrypts the provider's secret before returning it, so the app never sees the provider key. Each secret writes an audit row on the calling key, without the secret value, and nothing else is stored.

Request body (application/json, object):

FieldTypeRequiredDescription
expires_afterobject or nullNoHow long the secret stays valid
modelstring or nullNoGateway model to route to when session.model is absent, not forwarded
sessionobject or nullNoThe realtime session the secret is bound to, model included

Example request:

curl -X POST "http://localhost:4000/v1/realtime/client_secrets" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"expires_after": {
"anchor": "created_at",
"seconds": 600
},
"session": {
"model": "gpt-realtime",
"type": "realtime"
}
}'

Responses:

StatusDescriptionBody
200The client secret for the browser or mobile app, encrypted by the gatewayapplication/json RealtimeClientSecretResponse
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
expires_atinteger or nullNoWhen the secret expires, in Unix seconds
sessionobject or nullNoThe session as the provider created it
valuestringYesThe client secret to hand to the browser or mobile app

POST /v1/realtime/transcription_sessions​

Create a realtime transcription session

Create an ephemeral Realtime transcription session (POST /v1/realtime/transcription_sessions) for the WebRTC/WebSocket flow.

Use it for live captions or dictation in a browser or phone app: your server calls this with its virtual key and hands the returned client_secret.value to the app, which streams audio and receives text. Any key allowed to use the transcription model may call it, and the key's budget, rate limits and model access apply. The gateway encrypts the provider's ephemeral key under client_secret.value, so the app never sees the provider key.

Request body (application/json, object):

FieldTypeRequiredDescription
input_audio_transcriptionobject or nullNoInput Audio Transcription
modelstring or nullNoModel

Example request:

curl -X POST "http://localhost:4000/v1/realtime/transcription_sessions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_audio_transcription": {
"language": "en",
"model": "gpt-4o-transcribe"
},
"model": "gpt-realtime"
}'

Responses:

StatusDescriptionBody
200The ephemeral client secret for the transcription session.application/json RealtimeTranscriptionSessionResponse
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
client_secretobject or nullNoClient Secret