Skip to main content
The Realtime endpoint upgrades an HTTP connection to a WebSocket and proxies bidirectional messages between your client and the upstream provider (e.g. OpenAI Realtime API). The gateway handles authentication, event parsing, and connection lifecycle management.

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

string
required
Must be websocket.
string
required
The provider to connect to (e.g. openai). The gateway uses this to determine the upstream WebSocket URL and authentication headers.
string
required
Your Portkey API key or the provider API key.
string
A Portkey virtual key that resolves provider credentials automatically.

Response

A successful upgrade returns HTTP 101 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

The Realtime handler is registered only when the gateway runs in the 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.
Deploy to Cloudflare Workers to use the Realtime endpoint in production.

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.

Event flow