Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix the live tester

Sameer Kankute507bced04f55
diff --git a/docs/my-website/blog/realtime_webrtc_http_endpoints/index.md b/docs/my-website/blog/realtime_webrtc_http_endpoints/index.md
index 8907f3cd404..1316b5c7308 100644
--- a/docs/my-website/blog/realtime_webrtc_http_endpoints/index.md
+++ b/docs/my-website/blog/realtime_webrtc_http_endpoints/index.md
@@ -1,6 +1,6 @@
---
slug: realtime_webrtc_http_endpoints
-title: "Realtime WebRTC HTTP Endpoints on LiteLLM Proxy"
+title: "Realtime WebRTC HTTP Endpoints"
date: 2026-03-12T10:00:00
authors:
- name: Sameer Kankute
@@ -19,59 +19,37 @@ description: "Use the LiteLLM proxy to route OpenAI-style WebRTC realtime via HT
tags: [realtime, webrtc, proxy, openai]
hide_table_of_contents: false
---
----
-id: webrtc
-title: "/realtime - WebRTC Support"
-sidebar_label: "/realtime WebRTC"
----
import WebRTCTester from '@site/src/components/WebRTCTester';
-Use this to connect to the Realtime API via WebRTC from browser/mobile clients, with LiteLLM handling authentication and key management.
+Connect to the Realtime API via WebRTC from browser/mobile clients. LiteLLM handles auth and key management; audio streams directly to OpenAI/Azure.
-**Supported Providers:**
-- OpenAI
-- Azure OpenAI
+**Providers:** OpenAI · Azure OpenAI
-:::info When to use WebRTC vs WebSocket?
-- Use **WebSocket** (`/v1/realtime`) for server-to-server connections
-- Use **WebRTC** (`/v1/realtime/client_secrets` + `/v1/realtime/calls`) for browser/mobile clients where lower latency matters
+:::info **WebRTC vs WebSocket**
+- **WebSocket** (`/v1/realtime`) — server-to-server
+- **WebRTC** (`/v1/realtime/client_secrets` + `/v1/realtime/calls`) — browser/mobile, lower latency
:::
## How it works
-WebRTC keeps your provider API keys secure while allowing the browser to stream audio directly to OpenAI/Azure — without routing audio through LiteLLM.
+LiteLLM issues tokens and relays SDP; audio never passes through the proxy.
```
Browser LiteLLM Proxy OpenAI/Azure
| | |
|-- POST /v1/realtime/ | |
- | client_secrets -------->| |
- | [LiteLLM API key] |-- POST /v1/realtime/ |
- | | sessions [Real key] -->|
+ | client_secrets -------->|-- POST sessions -------->|
| |<-- { ek_... } -----------|
- | | encrypt(ek_...) |
|<-- { encrypted_token } ---| |
- | | |
- |-- POST /v1/realtime/calls | |
- | [SDP + encrypted_token]>| |
- | | decrypt → ek_... |
- | |-- POST /v1/realtime/ |
- | | calls [SDP + ek_...] ->|
- | |<-- SDP answer -----------|
- |<-- SDP answer ------------| |
- | | |
+ |-- POST /v1/realtime/calls |-- POST calls ----------->|
+ | [SDP + token] --------->| |
+ |<-- SDP answer ------------|<-- SDP answer -----------|
|===== audio P2P direct to OpenAI/Azure =============>|
```
-LiteLLM **never touches the audio stream** — it only handles token issuance and the SDP exchange. All audio flows directly browser ↔ provider.
-
----
-
## Proxy Setup
-### Add model to config
-
```yaml
model_list:
- model_name: gpt-4o-realtime
@@ -82,155 +60,75 @@ model_list:
mode: realtime
```
-For Azure:
-
-```yaml
-model_list:
- - model_name: gpt-4o-realtime
- litellm_params:
- model: azure/gpt-4o-realtime-preview
- api_key: os.environ/AZURE_API_KEY
- api_base: os.environ/AZURE_API_BASE
- model_info:
- mode: realtime
-```
-
-### Start the proxy
+**Azure:** use `model: azure/gpt-4o-realtime-preview`, `api_key`, `api_base`.
```bash
litellm --config /path/to/config.yaml
-
-# RUNNING on http://0.0.0.0:4000
```
----
+## Try it live
+
+<WebRTCTester />
## Client Usage
-### Step 1 — Get an encrypted session token
+**1. Get token** — `POST /v1/realtime/client_secrets` with LiteLLM API key and `{ model }`.
+
+**2. WebRTC handshake** — Create `RTCPeerConnection`, add mic track, create data channel `oai-events`, send SDP offer to `POST /v1/realtime/calls` with `Authorization: Bearer <encrypted_token>` and `Content-Type: application/sdp`.
-Call `POST /v1/realtime/client_secrets` from your browser using your LiteLLM API key. LiteLLM fetches a real ephemeral key from OpenAI, encrypts it, and returns the encrypted token — so your provider key never reaches the browser.
+**3. Events** — Use the data channel for `session.update` and other events.
+
+<details>
+<summary>Full code example</summary>
```javascript
-const tokenResponse = await fetch("http://your-litellm-proxy:4000/v1/realtime/client_secrets", {
+// 1. Token
+const r = await fetch("http://proxy:4000/v1/realtime/client_secrets", {
method: "POST",
- headers: {
- "Authorization": "Bearer sk-litellm-your-key",
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- model: "gpt-4o-realtime", // model_name from your config
- }),
+ headers: { "Authorization": "Bearer sk-litellm-key", "Content-Type": "application/json" },
+ body: JSON.stringify({ model: "gpt-4o-realtime" }),
});
+const { client_secret } = await r.json();
+const token = client_secret.value;
-const { client_secret } = await tokenResponse.json();
-const ENCRYPTED_TOKEN = client_secret.value; // encrypted by LiteLLM, not the real ek_...
-```
-
-### Step 2 — Establish WebRTC connection via LiteLLM
-
-Use the standard WebRTC APIs to set up the peer connection, then send your SDP offer to LiteLLM's `/v1/realtime/calls` endpoint. LiteLLM decrypts the token (which encodes the model) and forwards the SDP to OpenAI — no need to pass `model` again.
-
-```javascript
+// 2. WebRTC
const pc = new RTCPeerConnection();
-
-// Set up to play remote audio from the model
-const audioEl = document.createElement("audio");
-audioEl.autoplay = true;
-pc.ontrack = (e) => (audioEl.srcObject = e.streams[0]);
-
-// Add local audio track for microphone input
+const audio = document.createElement("audio");
+audio.autoplay = true;
+pc.ontrack = (e) => (audio.srcObject = e.streams[0]);
const ms = await navigator.mediaDevices.getUserMedia({ audio: true });
pc.addTrack(ms.getTracks()[0]);
-
-// Set up data channel for sending and receiving events
const dc = pc.createDataChannel("oai-events");
-
-// Create SDP offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
-// Send SDP to LiteLLM — model is decoded from the token, no ?model= needed
-const sdpResponse = await fetch("http://your-litellm-proxy:4000/v1/realtime/calls", {
+const sdpRes = await fetch("http://proxy:4000/v1/realtime/calls", {
method: "POST",
- headers: {
- "Authorization": `Bearer ${ENCRYPTED_TOKEN}`,
- "Content-Type": "application/sdp",
- },
+ headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/sdp" },
body: offer.sdp,
});
+await pc.setRemoteDescription({ type: "answer", sdp: await sdpRes.text() });
-const answer = { type: "answer", sdp: await sdpResponse.text() };
-await pc.setRemoteDescription(answer);
-
-// Audio now flows directly browser <-> OpenAI/Azure (P2P)
+// 3. Events
+dc.send(JSON.stringify({ type: "session.update", session: { instructions: "..." } }));
```
-### Step 3 — Send and receive events
-
-Use the WebRTC data channel to send and receive session events:
-
-```javascript
-// Listen for server events
-dc.addEventListener("message", (e) => {
- const event = JSON.parse(e.data);
- console.log(event);
-});
-
-// Send a client event
-dc.send(JSON.stringify({
- type: "session.update",
- session: {
- instructions: "You are a helpful assistant.",
- },
-}));
-```
-
----
-
-## Try it live
-
-Paste your LiteLLM proxy URL and API key to run a real end-to-end WebRTC session right here.
-
-<WebRTCTester />
-
----
+</details>
## FAQ
-### Why do I get `401 Token has expired` on `/v1/realtime/calls`?
+**Q: What do I do if I get a 401 Token expired error?**
+A: Tokens are short-lived. Get a fresh token right before creating the WebRTC offer.
-The encrypted token returned by `/v1/realtime/client_secrets` is short-lived.
-Generate a fresh token right before creating your WebRTC offer, and avoid reusing old tokens across page refreshes or long idle periods.
-
-### Do I send my LiteLLM key or provider key to `/v1/realtime/calls`?
-
-Use the **encrypted token** from `/v1/realtime/client_secrets` as:
-
-```http
-Authorization: Bearer <encrypted_token>
-```
+**Q: Which key should I use for `/v1/realtime/calls`?**
+A: Use the **encrypted token** from `client_secrets`, not your raw API key.
-Do not send your raw OpenAI/Azure key from the client.
+**Q: Should I pass the `model` parameter when making the call?**
+A: No, the encrypted token already encodes all routing information including model.
-### Do I need to pass `model` again on `/v1/realtime/calls`?
+**Q: How do I resolve Azure `api-version` errors?**
+A: Set the correct `api_version` in `litellm_params` (or via the `AZURE_API_VERSION` environment variable), along with the right `api_base` and deployment values.
-Usually no. The encrypted token encodes routing metadata (including model), so LiteLLM can route the SDP exchange without `?model=...`.
+**Q: What if I get no audio?**
+A: Make sure you grant microphone permission, ensure `pc.ontrack` assigns the audio element with `autoplay` enabled, check your network/firewall for WebRTC traffic, and inspect the browser console for ICE or SDP errors.
-### Azure call failing with `api-version` errors - what should I check?
-
-Make sure your Azure deployment config includes a valid `api_version` in `litellm_params` (or set `AZURE_API_VERSION`), plus correct `api_base` and deployment/model mapping.
-
-### Why does the SDP request need `Content-Type: application/sdp` on the client?
-
-Your browser sends raw SDP text to LiteLLM, so `application/sdp` is correct for the client-to-proxy request.
-LiteLLM then transforms and forwards provider-specific payloads upstream.
-
-### The browser asks for microphone permission but I hear no audio. What can I check?
-
-- Confirm microphone permission is granted for your site.
-- Ensure `pc.ontrack` sets an autoplay-enabled audio element.
-- Verify your network allows WebRTC (no restrictive firewall or enterprise policy).
-- Check browser console logs for ICE and SDP negotiation errors.
-
----
diff --git a/docs/my-website/docs/proxy/realtime_webrtc.md b/docs/my-website/docs/proxy/realtime_webrtc.md
index 26770b6685b..694f293652b 100644
--- a/docs/my-website/docs/proxy/realtime_webrtc.md
+++ b/docs/my-website/docs/proxy/realtime_webrtc.md
@@ -1,49 +1,29 @@
# /realtime - WebRTC Support
-Use this to connect to the Realtime API via WebRTC from browser/mobile clients, with LiteLLM handling authentication and key management.
+Connect to the Realtime API via WebRTC from browser/mobile clients. LiteLLM handles auth; audio streams directly to OpenAI/Azure.
-Supported Providers:
-- OpenAI
-- Azure
+**Providers:** OpenAI · Azure
-:::info
-**When to use WebRTC vs WebSocket?**
-
-- Use **WebSocket** (`/v1/realtime`) for server-to-server connections
-- Use **WebRTC** (`/v1/realtime/client_secrets` + `/v1/realtime/calls`) for browser/mobile clients where lower latency matters
+:::info **WebRTC vs WebSocket**
+- **WebSocket** (`/v1/realtime`) — server-to-server
+- **WebRTC** (`/v1/realtime/client_secrets` + `/v1/realtime/calls`) — browser/mobile, lower latency
:::
## How it works
-WebRTC keeps your provider API keys secure while allowing the browser to stream audio directly to OpenAI/Azure — without routing audio through LiteLLM.
+LiteLLM issues tokens and relays SDP; audio never passes through the proxy.
```
Browser LiteLLM Proxy OpenAI/Azure
| | |
- |-- POST /v1/realtime/ | |
- | client_secrets -------->| |
- | [LiteLLM API key] |-- POST /v1/realtime/ |
- | | sessions [Real key] -->|
- | |<-- { ek_... } -----------|
- | | encrypt(ek_...) |
- |<-- { encrypted_token } ---| |
- | | |
- |-- POST /v1/realtime/calls | |
- | [SDP + encrypted_token]>| |
- | | decrypt → ek_... |
- | |-- POST /v1/realtime/ |
- | | calls [SDP + ek_...] ->|
- | |<-- SDP answer -----------|
- |<-- SDP answer ------------| |
- | | |
- |===== audio P2P direct to OpenAI/Azure =============>|
+ |-- POST client_secrets --->|-- POST sessions -------->|
+ |<-- encrypted_token -------|<-- ek_... ---------------|
+ |-- POST calls [SDP+token] ->|-- POST calls ----------->|
+ |<-- SDP answer ------------|<-- SDP answer -----------|
+ |===== audio P2P direct ===============================>|
```
-LiteLLM **never touches the audio stream** — it only handles token issuance and the SDP exchange. All audio flows directly browser ↔ provider.
-
-## Proxy Usage
-
-### Add model to config
+## Proxy Setup
```yaml
model_list:
@@ -55,109 +35,50 @@ model_list:
mode: realtime
```
-For Azure:
-
-```yaml
-model_list:
- - model_name: gpt-4o-realtime
- litellm_params:
- model: azure/gpt-4o-realtime-preview
- api_key: os.environ/AZURE_API_KEY
- api_base: os.environ/AZURE_API_BASE
- model_info:
- mode: realtime
-```
-
-### Start proxy
+**Azure:** `model: azure/gpt-4o-realtime-preview`, `api_key`, `api_base`.
```bash
litellm --config /path/to/config.yaml
-
-# RUNNING on http://0.0.0.0:4000
```
## Client Usage
-### Step 1 — Get an encrypted session token
-
-Call `POST /v1/realtime/client_secrets` from your browser using your LiteLLM API key. LiteLLM will fetch a real ephemeral key from OpenAI, encrypt it, and return the encrypted token — so the real provider key never reaches your browser.
+1. **Token** — `POST /v1/realtime/client_secrets` with LiteLLM key and `{ model }`.
+2. **WebRTC** — Create `RTCPeerConnection`, add mic, data channel `oai-events`, send SDP offer to `POST /v1/realtime/calls` with `Authorization: Bearer <token>`, `Content-Type: application/sdp`.
+3. **Events** — Use data channel for `session.update` and other events.
```javascript
-const tokenResponse = await fetch("http://your-litellm-proxy:4000/v1/realtime/client_secrets", {
+const r = await fetch("http://proxy:4000/v1/realtime/client_secrets", {
method: "POST",
- headers: {
- "Authorization": "Bearer sk-litellm-your-key",
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- model: "gpt-4o-realtime", // your model name from config
- }),
+ headers: { "Authorization": "Bearer sk-litellm-key", "Content-Type": "application/json" },
+ body: JSON.stringify({ model: "gpt-4o-realtime" }),
});
+const token = (await r.json()).client_secret.value;
-const { client_secret } = await tokenResponse.json();
-const ENCRYPTED_TOKEN = client_secret.value; // encrypted by LiteLLM, not the real ek_...
-```
-
-### Step 2 — Establish WebRTC connection via LiteLLM
-
-Use standard WebRTC APIs to set up the peer connection, then send your SDP offer to LiteLLM's `/v1/realtime/calls` endpoint. LiteLLM decrypts the token and forwards the SDP to OpenAI using the real ephemeral key.
-
-```javascript
-// Create a peer connection
const pc = new RTCPeerConnection();
-
-// Set up to play remote audio from the model
-const audioEl = document.createElement("audio");
-audioEl.autoplay = true;
-pc.ontrack = (e) => (audioEl.srcObject = e.streams[0]);
-
-// Add local audio track for microphone input
+const audio = document.createElement("audio");
+audio.autoplay = true;
+pc.ontrack = (e) => (audio.srcObject = e.streams[0]);
const ms = await navigator.mediaDevices.getUserMedia({ audio: true });
pc.addTrack(ms.getTracks()[0]);
-
-// Set up data channel for sending and receiving events
const dc = pc.createDataChannel("oai-events");
-
-// Create SDP offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
-// Send SDP to LiteLLM — it decrypts the token and forwards to OpenAI
-const sdpResponse = await fetch("http://your-litellm-proxy:4000/v1/realtime/calls", {
+const sdpRes = await fetch("http://proxy:4000/v1/realtime/calls", {
method: "POST",
- headers: {
- "Authorization": `Bearer ${ENCRYPTED_TOKEN}`,
- "Content-Type": "application/sdp",
- },
+ headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/sdp" },
body: offer.sdp,
});
+await pc.setRemoteDescription({ type: "answer", sdp: await sdpRes.text() });
-// Set the SDP answer from OpenAI (returned via LiteLLM)
-const answer = {
- type: "answer",
- sdp: await sdpResponse.text(),
-};
-await pc.setRemoteDescription(answer);
-
-// Audio now flows directly browser <-> OpenAI/Azure (P2P)
+dc.send(JSON.stringify({ type: "session.update", session: { instructions: "..." } }));
```
-### Step 3 — Send and receive events
-
-Use the WebRTC data channel to send and receive session events:
-
-```javascript
-// Listen for server events
-dc.addEventListener("message", (e) => {
- const event = JSON.parse(e.data);
- console.log(event);
-});
+## FAQ
-// Send a client event
-dc.send(JSON.stringify({
- type: "session.update",
- session: {
- instructions: "You are a helpful assistant.",
- },
-}));
-```
\ No newline at end of file
+- **401 Token expired** — Get a fresh token right before creating the WebRTC offer.
+- **Which key for `/calls`?** — Encrypted token from `client_secrets`, not raw key.
+- **Pass `model`?** — No. Token encodes routing.
+- **Azure `api-version`** — Set `api_version` in `litellm_params` and correct `api_base`.
+- **No audio** — Grant mic; ensure `pc.ontrack` sets autoplay audio; check firewall/WebRTC; inspect console.
\ No newline at end of file
diff --git a/docs/my-website/src/components/WebRTCTester.jsx b/docs/my-website/src/components/WebRTCTester.jsx
new file mode 100644
index 00000000000..3ade6dd7689
--- /dev/null
+++ b/docs/my-website/src/components/WebRTCTester.jsx
@@ -0,0 +1,83 @@
+import DashboardWebRTCTester from "../../../../ui/litellm-dashboard/src/components/WebRTCTester.jsx";
+
+const LIGHT_MODE_OVERRIDES = `
+.wrt-wrap {
+ background: #1f2937;
+ border: 1px solid #334155;
+}
+.wrt-toggle,
+.wrt-toggle:hover {
+ background: #111827;
+}
+.wrt-toggle-title,
+.we-msg {
+ color: #e2e8f0;
+}
+.wrt-toggle-sub,
+.wrt-label,
+.wrt-field label,
+.wrt-flow-box,
+.wrt-flow-arrow,
+.wrt-meta-row span:first-child,
+.wrt-header-title,
+.wrt-tab,
+.we-time {
+ color: #94a3b8;
+}
+.wrt-body,
+.wrt-sidebar,
+.wrt-main,
+.wrt-header,
+.wrt-tabs,
+.wrt-sdp-box,
+.wrt-sdp-hdr,
+.wrt-divider {
+ border-color: #334155;
+}
+.wrt-header {
+ background: #111827;
+}
+.wrt-field input,
+.wrt-mic-btn,
+.wrt-status-pill {
+ background: #0b1220;
+ border-color: #334155;
+ color: #e2e8f0;
+}
+.wrt-field input:focus,
+.wrt-btn-ghost:hover {
+ border-color: #60a5fa;
+}
+.wrt-btn-ghost {
+ background: #0b1220;
+ border-color: #334155;
+ color: #e2e8f0;
+}
+.wrt-log::-webkit-scrollbar-thumb {
+ background: #475569;
+}
+.wrt-tab.active {
+ color: #93c5fd;
+ border-bottom-color: #93c5fd;
+}
+.wrt-empty,
+.wrt-audio-status,
+.wrt-meta-row span:last-child {
+ color: #cbd5e1;
+}
+.wrt-sdp-dot {
+ background: #475569;
+}
+.wrt-sdp-pane textarea {
+ color: #e2e8f0;
+}
+`;
+
+export default function WebRTCTester() {
+ return (
+ <>
+ <DashboardWebRTCTester />
+ <style>{LIGHT_MODE_OVERRIDES}</style>
+ </>
+ );
+}
diff --git a/ui/litellm-dashboard/src/components/WebRTCTester.jsx b/ui/litellm-dashboard/src/components/WebRTCTester.jsx
index e8b439014fc..b26cf2a2dba 100644
--- a/ui/litellm-dashboard/src/components/WebRTCTester.jsx
+++ b/ui/litellm-dashboard/src/components/WebRTCTester.jsx
@@ -228,7 +228,7 @@ export default function WebRTCTester() {
const [activeTab, setActiveTab] = useState('logs');
const [proxyUrl, setProxyUrl] = useState('http://localhost:4000');
const [apiKey, setApiKey] = useState('sk-1234');
- const [model, setModel] = useState('gpt-4o-realtime');
+ const [model, setModel] = useState('gpt-4o-realtime-preview');
const [status, setStatus] = useState('idle');
const [flowStep, setFlowStep] = useState(0);
const [tokenPreview, setTokenPreview] = useState('—');