{"library":"openai-realtime-api","title":"OpenAI Realtime Voice API Client","description":"The `openai-realtime-api` package provides a robust and strongly-typed TypeScript client for interacting with OpenAI's realtime voice API. As a direct fork and drop-in replacement for the `openai/openai-realtime-api-beta` project, it addresses numerous bugs and inconsistencies present in the original implementation. Currently at stable version `1.0.8`, the library maintains an active development pace with frequent minor releases focused on bug fixes and dependency updates. Key differentiators include 100% typed events and handlers, comprehensive support across various JavaScript runtimes (Node.js >= 18, browsers, Deno, Bun, Cloudflare Workers), and inclusion of useful tools like Node.js CLI examples, a simple relay server, and an OpenAI Realtime Console demo. It aims to offer a more reliable and developer-friendly experience for building real-time voice applications with OpenAI.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install openai-realtime-api"],"cli":null},"imports":["import { RealtimeClient } from 'openai-realtime-api'","import type { RealtimeClientOptions } from 'openai-realtime-api'","import type { RealtimeCustomEvents } from 'openai-realtime-api'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { RealtimeClient } from 'openai-realtime-api';\n\n// Create a new client; apiKey defaults to process.env.OPENAI_API_KEY in Node.js\n// For browser usage, explicitly pass apiKey or use a relay server.\nconst client = new RealtimeClient({\n  apiKey: process.env.OPENAI_API_KEY ?? '', // Required for browser or if env var not set\n  sessionConfig: {\n    instructions: 'You are a great, upbeat friend.',\n    voice: 'alloy'\n  }\n});\n\n// Update session configuration before connecting, for example.\nclient.updateSession({\n  turn_detection: null,\n  input_audio_transcription: { model: 'whisper-1', language: 'en' }\n});\n\n// Example of custom event handling with type safety\nclient.on('conversation.updated', (event) => {\n  const { item, delta } = event; // 'event' is fully-typed\n  console.log('Conversation updated:', item.text);\n});\n\nclient.on('speech.response', (event) => {\n  console.log('API response:', event.text);\n});\n\nasync function runConversation() {\n  try {\n    await client.connect();\n    console.log('Connected to OpenAI Realtime API.');\n\n    // Send an initial message to start the conversation\n    client.sendUserMessageContent('Hello, how are you today?');\n\n    // Keep the client alive for a few seconds to receive responses\n    await new Promise(resolve => setTimeout(resolve, 10000));\n\n    await client.disconnect();\n    console.log('Disconnected.');\n  } catch (error) {\n    console.error('Realtime API error:', error);\n  }\n}\n\nrunConversation();","lang":"typescript","description":"This quickstart demonstrates initializing the `RealtimeClient`, configuring a session, attaching event listeners for conversation updates and speech responses, connecting to the OpenAI API, sending a user message, and handling disconnections. It highlights TypeScript usage and API key management.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}