Nbility logoNbility Docs

Search documentation

Search guides and API reference content

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

EventDescription
session.updateUpdate session configuration
conversation.item.createAdd a message to the conversation
response.createRequest a new response
response.cancelCancel the current response

Server → Client

EventDescription
session.createdSession created successfully
response.text.deltaIncremental text response
response.text.doneText response complete
response.doneFull response complete
errorError occurred

Note The Realtime API is currently in beta. Refer to the OpenAI Realtime API documentation for the full event protocol specification.