Deepgram
Deepgram provides a VoxEngine client for connecting a call or media unit to the Deepgram Voice Agent API over WebSocket.
Use Deepgram.createVoiceAgentClient(...) to create a VoiceAgentClient for the current scenario.
Related guides
Contents
- Usage: required module import and basic flow.
- Factory functions: create the Deepgram Voice Agent client.
- Methods: media and conversation control methods.
- Events: WebSocket media bridge events.
- VoiceAgentEvents: Deepgram Voice Agent event names and payload fields.
Usage
Add the module before using the namespace:
Create the client, bridge media, and listen for Voice Agent events.
Factory functions
createVoiceAgentClient
Creates a Deepgram.VoiceAgentClient instance.
Parameters
Returns
VoiceAgentClient
Methods
addEventListener
Adds a handler for the specified Deepgram.VoiceAgentEvents or Deepgram.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
clearMediaBuffer
Clears the VoiceAgent WebSocket media buffer.
Parameters
Returns
close
Closes the VoiceAgent connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
id
Returns the VoiceAgentClient id.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Removes a handler for the specified Deepgram.VoiceAgentEvents or Deepgram.Events event.
Parameters
Returns
sendFunctionCallResponse
Send a message to provide a function call response in the middle of a conversation. https://developers.deepgram.com/reference/voice-agent/voice-agent#send.AgentV1SendFunctionCallResponse
Parameters
Returns
sendInjectAgentMessage
Send a message to immediately trigger an Agent statement. https://developers.deepgram.com/reference/voice-agent/voice-agent#send.AgentV1InjectAgentMessage
Parameters
Returns
sendInjectUserMessage
Send a text based message to the agent. https://developers.deepgram.com/reference/voice-agent/voice-agent#send.AgentV1InjectUserMessage
Parameters
Returns
sendMediaTo
Starts sending media from the VoiceAgent (via WebSocket) to the media unit. VoiceAgent works in real time.
Parameters
Returns
sendUpdatePrompt
Send a message to update the system prompt of the agent. https://developers.deepgram.com/reference/voice-agent/voice-agent#send.AgentV1UpdatePrompt
Parameters
Returns
sendUpdateSpeak
Send a message to change the Speak model in the middle of a conversation. https://developers.deepgram.com/reference/voice-agent/voice-agent#send.AgentV1UpdateSpeak
Parameters
Returns
stopMediaTo
Stops sending media from the VoiceAgent (via WebSocket) to the media unit.
Parameters
Returns
webSocketId
Returns the VoiceAgent WebSocket id.
Parameters
This method does not accept parameters.
Returns
Events
These events describe audio received through the Deepgram WebSocket media bridge.
WebSocketMediaStarted
Triggered when the audio stream sent by a third party through a Deepgram WebSocket is started playing.
Event constant: Events.WebSocketMediaStarted
Payload
WebSocketMediaEnded
Triggers after the end of the audio stream sent by a third party through a Deepgram WebSocket (1 second of silence).
Event constant: Events.WebSocketMediaEnded
Payload
VoiceAgentEvents
These events mirror server messages from the Deepgram Voice Agent API. The data field contains the provider event payload.
Unknown
The unknown event.
Event constant: VoiceAgentEvents.Unknown
Payload
HTTPResponse
The HTTP response event.
Event constant: VoiceAgentEvents.HTTPResponse
Payload
Welcome
Receive a welcome message from the server to confirm the websocket has opened. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1Welcome
Event constant: VoiceAgentEvents.Welcome
Payload
Example data:
SettingsApplied
Confirms the server has successfully received and applied the Settings message. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1SettingsApplied
Event constant: VoiceAgentEvents.SettingsApplied
Payload
Example data:
ConversationText
Facilitates real-time communication by relaying spoken statements from both the user and the agent. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1ConversationText
Event constant: VoiceAgentEvents.ConversationText
Payload
Example data:
UserStartedSpeaking
Notifies the client that the user has begun speaking. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1UserStartedSpeaking
Event constant: VoiceAgentEvents.UserStartedSpeaking
Payload
Example data:
AgentThinking
Informs the client when the agent is processing information. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1AgentThinking
Event constant: VoiceAgentEvents.AgentThinking
Payload
Example data:
FunctionCallRequest
Server-initiated message requesting a function call, to be handled by either client or server. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1FunctionCallRequest
Event constant: VoiceAgentEvents.FunctionCallRequest
Payload
Example data:
FunctionCallResponse
Message containing the result of a function call, sent by client or server. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1ReceiveFunctionCallResponse
Event constant: VoiceAgentEvents.FunctionCallResponse
Payload
PromptUpdated
Confirms that a Prompt Configuration change has been applied. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1PromptUpdated
Event constant: VoiceAgentEvents.PromptUpdated
Payload
Example data:
SpeakUpdated
Confirms that a Speak Configuration change has been applied. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1SpeakUpdated
Event constant: VoiceAgentEvents.SpeakUpdated
Payload
Example data:
AgentAudioDone
Get signals that the server has finished sending the final audio segment to the client. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1AgentAudioDone
Event constant: VoiceAgentEvents.AgentAudioDone
Payload
Example data:
Error
Receive errors from the server if an issue has occurred. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1Error
Event constant: VoiceAgentEvents.Error
Payload
Example data:
Warning
Receive warnings from the server if an issue has occurred. https://developers.deepgram.com/reference/voice-agent/voice-agent#receive.AgentV1Warning
Event constant: VoiceAgentEvents.Warning
Payload
Example data:
History
Provide conversation and function call history when starting a new Voice Agent session. https://developers.deepgram.com/docs/voice-agent-history
Event constant: VoiceAgentEvents.History
Payload
Example data:
WebSocketError
The WebSocket error response event.
Event constant: VoiceAgentEvents.WebSocketError
Payload
ConnectorInformation
Contains information about connector.
Event constant: VoiceAgentEvents.ConnectorInformation
Payload