Skip to main content

GPT Realtime

GET /v1/realtime
The GPT Realtime API enables low-latency real-time voice conversations via WebSocket connections.

Connection

Connect to the Realtime endpoint via WebSocket:
wss://crazyrouter.com/v1/realtime?model=gpt-4o-realtime-preview

Authentication

The currently supported and recommended authentication methods are:

Method 1: pass the API key in request headers

Authorization: Bearer YOUR_API_KEY

Method 2: pass the key in Sec-WebSocket-Protocol

Useful for some OpenAI Realtime-compatible clients:
Sec-WebSocket-Protocol: realtime, openai-insecure-api-key.YOUR_API_KEY
Do not rely on the ?api_key= URL query style.

Supported Models

ModelDescription
gpt-4o-realtime-previewGPT-4o Realtime Preview
gpt-4o-mini-realtime-previewGPT-4o Mini Realtime Preview

Usage Example

Python
import asyncio
import websockets
import json

async def realtime_chat():
    uri = "wss://crazyrouter.com/v1/realtime?model=gpt-4o-realtime-preview"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}

    async with websockets.connect(uri, extra_headers=headers) as ws:
        # Configure session
        await ws.send(json.dumps({
            "type": "session.update",
            "session": {
                "modalities": ["text", "audio"],
                "voice": "nova",
                "input_audio_format": "pcm16",
                "output_audio_format": "pcm16",
                "turn_detection": {
                    "type": "server_vad"
                }
            }
        }))

        # Send text message
        await ws.send(json.dumps({
            "type": "conversation.item.create",
            "item": {
                "type": "message",
                "role": "user",
                "content": [
                    {"type": "input_text", "text": "Hello, please introduce yourself"}
                ]
            }
        }))

        # Trigger response
        await ws.send(json.dumps({"type": "response.create"}))

        # Receive response
        async for message in ws:
            event = json.loads(message)
            if event["type"] == "response.text.delta":
                print(event["delta"], end="")
            elif event["type"] == "response.done":
                break

asyncio.run(realtime_chat())

Event Types

Client Events

EventDescription
session.updateUpdate session configuration
conversation.item.createCreate a conversation item
input_audio_buffer.appendAppend audio data
input_audio_buffer.commitCommit audio buffer
response.createTrigger model response

Server Events

EventDescription
session.createdSession created
response.text.deltaText delta
response.audio.deltaAudio delta
response.doneResponse complete
The Realtime API uses persistent WebSocket connections. Prefer header-based authentication and do not rely on the ?api_key= query parameter.