WebSocket endpoint
GET /v1/realtime
Upgrades the connection to a WebSocket. The client sends a standard HTTP Upgrade: websocket request; the gateway establishes a corresponding WebSocket connection to the upstream provider and bridges all messages.
Request headers
Must be
websocket.The provider to connect to (e.g.
openai). The gateway uses this to determine the upstream WebSocket URL and authentication headers.Your Portkey API key or the provider API key.
A Portkey virtual key that resolves provider credentials automatically.
Response
A successful upgrade returns HTTP101 Switching Protocols. Once upgraded, the connection is a standard WebSocket. Messages sent on the client side are forwarded to the provider; messages received from the provider are forwarded back to the client.
Runtime support
- Cloudflare Workers (workerd)
- Node.js
The Realtime handler is registered only when the gateway runs in the Deploy to Cloudflare Workers to use the Realtime endpoint in production.
workerd runtime (Cloudflare Workers). It uses the Cloudflare WebSocketPair API to accept the client connection and then opens an outgoing WebSocket to the provider via fetch() with the Upgrade: websocket header.Connect from a client
You can connect using any standard WebSocket client. Pass the provider and authentication details in the HTTP upgrade request headers.Using the OpenAI Realtime SDK
You can use the official OpenAI Realtime API SDK and point it at the Portkey gateway by overriding the base URL.JavaScript
The OpenAI Realtime SDK connects directly to
wss://api.openai.com/v1/realtime by default. Overriding url with your gateway address routes the connection through Portkey, enabling logging, virtual keys, and other gateway features.