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

Pass the API Key in the WebSocket connection headers:
Authorization: Bearer YOUR_API_KEY
Or via URL parameter:
wss://crazyrouter.com/v1/realtime?model=gpt-4o-realtime-preview&api_key=YOUR_API_KEY

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. Ensure your client supports the WebSocket protocol. The default connection timeout is 120 seconds.