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.
npm install openai-realtime-apiVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json` or `.mjs` file extensions) and that your Node.js runtime is version 18 or newer. Replace all CommonJS `require()` calls with ES Module `import` statements.
In Node.js, the `OPENAI_API_KEY` environment variable is automatically detected. For browser environments, or if the environment variable is not set, you must explicitly pass the `apiKey` string in the `RealtimeClientOptions` during client initialization.
For production browser deployments, it is highly recommended to deploy and utilize the included relay server (as detailed in the package's README). Configure the `RealtimeClient` with the `relayServerUrl` option to proxy requests and secure your OpenAI API key.
If your application requires a precise audio transcription frequency, ensure it is explicitly set within the `sessionConfig.input_audio_transcription.frequency` property when initializing or updating the client's session configuration.
Update your project to use ES Module `import` statements. If in Node.js, ensure your `package.json` contains `"type": "module"` or use `.mjs` file extensions for your source files.
For Node.js, ensure `process.env.OPENAI_API_KEY` is set. For browser clients or explicit control, pass the `apiKey` directly as an option: `new RealtimeClient({ apiKey: 'YOUR_API_KEY' })`.Verify network connectivity and firewall settings. For browser environments, check browser developer console for CORS errors; if present, implement and configure the `relayServerUrl` option with your proxy server.
No dependency data recorded yet.