Skip to main content

WebSocket API

This page documents the 6 gateway endpoints tagged WebSocket 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/responsesOpen a Responses API WebSocket session
GET/v1/responsesOpen a Responses API WebSocket session
GET/vertex_ai/liveVertex AI Live API WebSocket Pass-through Endpoint
GET/realtimeOpen a realtime voice or transcription WebSocket session
GET/v1/realtimeOpen a realtime voice or transcription WebSocket session
GET/openai/v1/realtimeOpen a realtime voice or transcription WebSocket session

Endpoints​

GET /responses​

Open a Responses API WebSocket session

Keeps one connection open for many response.create events, which cuts latency for agents that make many tool call round trips. The virtual key in the Authorization header is checked before the connection is accepted. The model comes from the ?model= query parameter or from the first response.create frame. A session lasts at most general_settings.responses_websocket_session_limit_seconds (60 to 7200, default 3600) from accept.

Close codes: 1000 "Session duration limit reached" when the session lifetime ends; 1008 "Invalid JSON in first message", "Invalid first message", "No model provided" or "Pre-call error" when the first frame or a gateway check refuses the session; 1011 "Internal server error" on an unexpected failure.

Parameters:

NameInTypeRequiredDescription
modelquerystringNoThe model to use for the responses WebSocket session.

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched

GET /v1/responses​

Open a Responses API WebSocket session

Keeps one connection open for many response.create events, which cuts latency for agents that make many tool call round trips. The virtual key in the Authorization header is checked before the connection is accepted. The model comes from the ?model= query parameter or from the first response.create frame. A session lasts at most general_settings.responses_websocket_session_limit_seconds (60 to 7200, default 3600) from accept.

Close codes: 1000 "Session duration limit reached" when the session lifetime ends; 1008 "Invalid JSON in first message", "Invalid first message", "No model provided" or "Pre-call error" when the first frame or a gateway check refuses the session; 1011 "Internal server error" on an unexpected failure.

Parameters:

NameInTypeRequiredDescription
modelquerystringNoThe model to use for the responses WebSocket session.

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched

GET /vertex_ai/live​

Vertex AI Live API WebSocket Pass-through Endpoint

This endpoint delegates to the WebSocket function defined in llm_passthrough_endpoints.py

Parameters:

NameInTypeRequiredDescription
modelquerystringNoOptional model name, used to determine Vertex region for global models.
vertex_projectquerystringNoOverride the Vertex AI project id used for the upstream connection.
vertex_locationquerystringNoOverride the Vertex AI region (for example, 'us-central1').

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched

GET /realtime​

Open a realtime voice or transcription WebSocket session

Streams audio and events between your server and a realtime model. The virtual key in the Authorization header is checked before the connection is accepted, and the key's model access, budget and limits apply. Pass the model as ?model=; with ?intent=transcription and no model the gateway uses gpt-realtime-whisper. ?guardrails= names extra guardrails for this session, comma separated.

Close codes: 1008 "model query parameter is required" when neither model nor intent=transcription is sent, or the key's model access error when the key cannot use the model; 1011 "Pre-call error" when a gateway hook refuses the session.

Parameters:

NameInTypeRequiredDescription
modelquerystringNoThe model to use for the websocket connection.
intentquerystringNoThe intent of the websocket connection.
guardrailsquerystringNoComma-separated list of guardrail names to apply to this request.

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched

GET /v1/realtime​

Open a realtime voice or transcription WebSocket session

Streams audio and events between your server and a realtime model. The virtual key in the Authorization header is checked before the connection is accepted, and the key's model access, budget and limits apply. Pass the model as ?model=; with ?intent=transcription and no model the gateway uses gpt-realtime-whisper. ?guardrails= names extra guardrails for this session, comma separated.

Close codes: 1008 "model query parameter is required" when neither model nor intent=transcription is sent, or the key's model access error when the key cannot use the model; 1011 "Pre-call error" when a gateway hook refuses the session.

Parameters:

NameInTypeRequiredDescription
modelquerystringNoThe model to use for the websocket connection.
intentquerystringNoThe intent of the websocket connection.
guardrailsquerystringNoComma-separated list of guardrail names to apply to this request.

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched

GET /openai/v1/realtime​

Open a realtime voice or transcription WebSocket session

Streams audio and events between your server and a realtime model. The virtual key in the Authorization header is checked before the connection is accepted, and the key's model access, budget and limits apply. Pass the model as ?model=; with ?intent=transcription and no model the gateway uses gpt-realtime-whisper. ?guardrails= names extra guardrails for this session, comma separated.

Close codes: 1008 "model query parameter is required" when neither model nor intent=transcription is sent, or the key's model access error when the key cannot use the model; 1011 "Pre-call error" when a gateway hook refuses the session.

Parameters:

NameInTypeRequiredDescription
modelquerystringNoThe model to use for the websocket connection.
intentquerystringNoThe intent of the websocket connection.
guardrailsquerystringNoComma-separated list of guardrail names to apply to this request.

Example request:

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

Responses:

StatusDescriptionBody
101WebSocket Protocol Switched