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.
| Method | Path | Summary |
|---|---|---|
| POST | /realtime/calls | Start a WebRTC realtime call |
| POST | /realtime/client_secrets | Create an ephemeral realtime client secret |
| POST | /realtime/transcription_sessions | Create a realtime transcription session |
| POST | /v1/realtime/calls | Start a WebRTC realtime call |
| POST | /v1/realtime/client_secrets | Create an ephemeral realtime client secret |
| POST | /v1/realtime/transcription_sessions | Create 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:
| Status | Description | Body |
|---|---|---|
| 200 | The provider's SDP answer. | application/sdp string |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | The client secret is missing, unreadable or expired: Missing or invalid Authorization header, Invalid or expired token, Token has expired | application/json object |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
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):
| Field | Type | Required | Description |
|---|---|---|---|
expires_after | object or null | No | How long the secret stays valid |
model | string or null | No | Gateway model to route to when session.model is absent, not forwarded |
session | object or null | No | The 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:
| Status | Description | Body |
|---|---|---|
| 200 | The client secret for the browser or mobile app, encrypted by the gateway | application/json RealtimeClientSecretResponse |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
expires_at | integer or null | No | When the secret expires, in Unix seconds |
session | object or null | No | The session as the provider created it |
value | string | Yes | The 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):
| Field | Type | Required | Description |
|---|---|---|---|
input_audio_transcription | object or null | No | Input Audio Transcription |
model | string or null | No | Model |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The ephemeral client secret for the transcription session. | application/json RealtimeTranscriptionSessionResponse |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
client_secret | object or null | No | Client 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:
| Status | Description | Body |
|---|---|---|
| 200 | The provider's SDP answer. | application/sdp string |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | The client secret is missing, unreadable or expired: Missing or invalid Authorization header, Invalid or expired token, Token has expired | application/json object |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
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):
| Field | Type | Required | Description |
|---|---|---|---|
expires_after | object or null | No | How long the secret stays valid |
model | string or null | No | Gateway model to route to when session.model is absent, not forwarded |
session | object or null | No | The 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:
| Status | Description | Body |
|---|---|---|
| 200 | The client secret for the browser or mobile app, encrypted by the gateway | application/json RealtimeClientSecretResponse |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
expires_at | integer or null | No | When the secret expires, in Unix seconds |
session | object or null | No | The session as the provider created it |
value | string | Yes | The 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):
| Field | Type | Required | Description |
|---|---|---|---|
input_audio_transcription | object or null | No | Input Audio Transcription |
model | string or null | No | Model |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The ephemeral client secret for the transcription session. | application/json RealtimeTranscriptionSessionResponse |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
client_secret | object or null | No | Client Secret |