GET /v1/realtime — Real-time bidirectional conversation via WebSocket
Endpoint
GET /v1/realtime
Upgrade to WebSocket via the standard HTTP upgrade mechanism.
Authentication
Pass the API key as a query parameter since WebSocket connections cannot set custom headers in browsers:
wss://api.nbility.dev/v1/realtime?access_token=YOUR_API_KEY
Overview
The Realtime API enables low-latency, bidirectional audio and text streaming conversations. It is compatible with the OpenAI Realtime API protocol.
Example (JavaScript)
Browser
const ws = new WebSocket(
'wss://api.nbility.dev/v1/realtime?access_token=YOUR_API_KEY'
);
ws.onopen = () => {
// Configure session
ws.send(JSON.stringify({
type: 'session.update',
session: {
modalities: ['text'],
model: 'gpt-4o-realtime-preview',
instructions: 'You are a helpful assistant.',
}
}));
// Send a message
ws.send(JSON.stringify({
type: 'conversation.item.create',
item: {
type: 'message',
role: 'user',
content: [{ type: 'input_text', text: 'Hello!' }]
}
}));
ws.send(JSON.stringify({ type: 'response.create' }));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data);
};
Event Types
Client → Server
| Event | Description |
|---|---|
session.update | Update session configuration |
conversation.item.create | Add a message to the conversation |
response.create | Request a new response |
response.cancel | Cancel the current response |
Server → Client
| Event | Description |
|---|---|
session.created | Session created successfully |
response.text.delta | Incremental text response |
response.text.done | Text response complete |
response.done | Full response complete |
error | Error occurred |
Note The Realtime API is currently in beta. Refer to the OpenAI Realtime API documentation for the full event protocol specification.