OpenAI
API clients for OpenAI chat completions, responses, and real-time voice scenarios.
OpenAI provides VoxEngine clients for chat completions, the Responses API, and the Realtime API. Use this page as the consolidated API surface for creating clients, configuring parameters, sending media, and handling provider events.
For real-time voice scenarios, create an OpenAI.RealtimeAPIClient, bridge call media to it, and listen for OpenAI.Events plus OpenAI.RealtimeAPIEvents.
Related guides
Learn how OpenAI fits into VoxEngine voice AI scenarios.
Start from a complete inbound OpenAI realtime scenario.
Use tool calls and function-call events in an OpenAI scenario.
Combine OpenAI with a separate realtime TTS provider.
Contents
- Usage: required module import and high-level client flow.
- Factory functions: create chat completions, responses, or realtime clients.
- Parameter types: configuration objects used by OpenAI client factories.
- Client methods: methods grouped by client type.
- Events: WebSocket media bridge events.
- RealtimeAPIEvents: OpenAI Realtime server events and provider payload fields.
Usage
Add the module before using the namespace:
Create the client for the API style you need, then call methods on that client instance. Realtime voice scenarios typically use createRealtimeAPIClient, sendMediaTo, and event listeners for Realtime API server messages.
Factory functions
Use the tabs to choose the OpenAI API surface you are creating: Chat Completions for text chat completions, Responses for the newer Responses API, or Realtime for voice scenarios over WebSocket.
Chat Completions
Responses
Realtime
Creates a client for the Chat Completions API.
createChatCompletionsAPIClient
Creates a new OpenAI.ChatCompletionsAPIClient instance.
The required parameters object is typed as OpenAI.Chat.
Parameters
Returns
Parameter types
These parameter objects match the same three API families as the factory functions.
Chat Completions
Responses
Realtime
OpenAI.ChatCompletionsAPIClient parameters. Can be passed as arguments to the OpenAI.createChatCompletionsAPIClient method.
Client methods
Use the tabs to switch between Chat Completions, Responses, and Realtime client methods.
Chat Completions
Responses
Realtime
addEventListener
Adds a handler for the specified OpenAI.ChatCompletionsAPIEvents or OpenAI.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
Returns
close
Closes the OpenAI connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
createChatCompletions
Creates a model response for the given chat conversation. https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create
Parameters
Returns
id
Returns the ChatCompletionsAPIClient id.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Removes a handler for the specified OpenAI.ChatCompletionsAPIEvents or OpenAI.Events event.
Parameters
Returns
webSocketId
Returns the OpenAI WebSocket id.
Parameters
This method does not accept parameters.
Returns
Events
Event tabs mirror the same API families: media bridge events apply to realtime WebSocket media, while the API-specific tabs document provider responses for each client type.
Media bridge
Chat Completions
Responses
Realtime
Media bridge events
These events describe audio received through the OpenAI WebSocket media bridge.
WebSocketMediaStarted
Triggered when the audio stream sent by a third party through an OpenAI WebSocket is started playing.
Event constant: Events.WebSocketMediaStarted
Payload
WebSocketMediaEnded
Triggers after the end of the audio stream sent by a third party through an OpenAI WebSocket (1 second of silence).
Event constant: Events.WebSocketMediaEnded
Payload