This guide helps you migrate from Deepgram JavaScript SDK v3 to v4.0.0. The v4 release updates the Voice Agent API from the preview spec to the official V1 spec. No other APIs were affected — if you are not using the Voice Agent API, no changes are required.
npm install @deepgram/sdk
# or
pnpm add @deepgram/sdk
# or
yarn add @deepgram/sdkconst agent = deepgram.agent("/agent");const agent = deepgram.agent("/v1/agent/converse");
// Or use the default (v4 defaults to the V1 endpoint)
const agent = deepgram.agent();The settings message type changed from SettingsConfiguration to Settings, and the schema was restructured to use nested provider objects.
v3
const agent = deepgram.agent();
agent.on(AgentEvents.Open, () => {
agent.configure({
audio: {
input: {
encoding: "linear16",
sampleRate: 24000,
},
output: {
encoding: "linear16",
sampleRate: 16000,
container: "wav",
},
},
agent: {
listen: {
model: "nova-3",
keyterms: ["deepgram"],
},
think: {
provider: {
type: "open_ai",
},
model: "gpt-4o-mini",
instructions: "You are a helpful AI assistant.",
functions: [
{
name: "get_weather",
description: "Get the weather for a location.",
url: "https://api.example.com/weather",
headers: [{ key: "authorization", value: "Bearer ..." }],
method: "POST",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "The city name." },
},
},
},
],
},
speak: {
model: "aura-2-thalia-en",
},
},
context: {
messages: [{ role: "assistant", content: "Hello!" }],
replay: true,
},
});
});v4
const agent = deepgram.agent();
agent.on(AgentEvents.Open, () => {
agent.configure({
audio: {
input: {
encoding: "linear16",
sample_rate: 24000,
},
output: {
encoding: "linear16",
sample_rate: 16000,
container: "wav",
},
},
agent: {
language: {
type: "en",
},
listen: {
provider: {
type: "deepgram",
model: "nova-3",
keyterms: ["deepgram"],
},
},
think: {
provider: {
type: "open_ai",
model: "gpt-4o-mini",
},
prompt: "You are a helpful AI assistant.",
functions: [
{
name: "get_weather",
description: "Get the weather for a location.",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "The city name." },
},
},
endpoint: {
url: "https://api.example.com/weather",
method: "POST",
headers: { authorization: "Bearer ..." },
},
},
],
},
speak: {
provider: {
type: "deepgram",
model: "aura-2-thalia-en",
},
},
},
greeting: "Hello!",
});
});v3
agent.updateInstructions("You are now a pirate assistant.");v4
agent.updatePrompt("You are now a pirate assistant.");v3
agent.updateSpeak("aura-2-zeus-en");v4
agent.updateSpeak({
provider: {
type: "deepgram",
model: "aura-2-zeus-en",
},
});v3
agent.injectAgentMessage("Hold on while I look that up for you.");v4
agent.injectAgentMessage("Hold on while I look that up for you.");Note: The method signature is the same, but the wire format changed from
{ message }to{ content }. The SDK handles this internally.
v3
agent.on(AgentEvents.FunctionCallRequest, (data) => {
// data.function_call_id: string
// data.function_name: string
// data.input: Record<string, any>
console.log(`Function: ${data.function_name}`, data.input);
});v4
agent.on(AgentEvents.FunctionCallRequest, (data) => {
// data.functions: Array<{ id: string, name: string, arguments: string, client_side: boolean }>
for (const fn of data.functions) {
console.log(`Function: ${fn.name}`, JSON.parse(fn.arguments));
}
});v3
agent.functionCallResponse({
function_call_id: "abc-123",
output: JSON.stringify({ temperature: 72 }),
});v4
agent.functionCallResponse({
id: "abc-123",
name: "get_weather",
content: JSON.stringify({ temperature: 72 }),
});v3
agent.on(AgentEvents.InstructionsUpdated, () => {
console.log("Instructions updated");
});
agent.on(AgentEvents.FunctionCalling, () => {
console.log("Function is being called");
});v4
agent.on(AgentEvents.PromptUpdated, () => {
console.log("Prompt updated");
});
// FunctionCalling event was removed in v4v3
agent.on(AgentEvents.Welcome, (data) => {
console.log(`Session: ${data.session_id}`);
});v4
agent.on(AgentEvents.Welcome, (data) => {
console.log(`Request: ${data.request_id}`);
});v3
agent.on(AgentEvents.AgentStartedSpeaking, (data) => {
console.log(`Latency: ${data.total_latency}ms`);
});v4
// This event now requires experimental mode to be enabled
agent.configure({
experimental: true,
// ... rest of config
});
agent.on(AgentEvents.AgentStartedSpeaking, (data) => {
console.log(`Latency: ${data.total_latency}ms`);
});v4
// ElevenLabs
agent.configure({
// ...
agent: {
speak: {
provider: {
type: "eleven_labs",
model_id: "eleven_turbo_v2",
},
},
// ...
},
});
// Cartesia
agent.configure({
// ...
agent: {
speak: {
provider: {
type: "cartesia",
model_id: "sonic-english",
voice: { mode: "id", id: "a0e99841-438c-4a64-b679-ae501e7d6091" },
language: "en",
},
},
// ...
},
});- Agent Endpoint: Default endpoint changed from
/agentto/v1/agent/converse - Settings Message: Wire format changed from
SettingsConfigurationtoSettings - Provider Nesting: Listen, think, and speak models now use nested
providerobjects - Audio Properties:
sampleRate(camelCase) changed tosample_rate(snake_case) - Instructions → Prompt:
updateInstructions()renamed toupdatePrompt(),instructionsfield renamed toprompt - Function Calls: Request format changed from single function to array of functions, response fields renamed
- Welcome Event:
session_idchanged torequest_id
FunctionCallingevent (removed entirely)InstructionsUpdatedevent (replaced withPromptUpdated)context.messagesandcontext.replayfields (removed from schema)- Strict
AudioFormatunion type (replaced with loose encoding/sample_rate/container fields) - Hardcoded think provider union types (replaced with generic provider objects)
- Third-Party TTS Providers: Support for ElevenLabs, Cartesia, and OpenAI TTS via
provider.type - Language Configuration: New
agent.language.typefield for specifying agent language - Greeting Message: New
greetingfield for an initial agent message at connection start - Experimental Flag: New
experimentalboolean to opt into experimental features likeAgentStartedSpeaking - Custom LLM Endpoints: New
endpointconfiguration for think and speak providers
- Update to latest version:
npm install @deepgram/sdk - Update agent endpoint if explicitly set (default is now
/v1/agent/converse) - Restructure
agent.listento use{ provider: { type: "deepgram", model, keyterms } } - Restructure
agent.thinkto use{ provider: { type, model }, prompt, functions } - Restructure
agent.speakto use{ provider: { type: "deepgram", model } } - Rename
instructionstopromptin think configuration - Rename
sampleRatetosample_ratein audio input/output - Replace
updateInstructions()calls withupdatePrompt() - Update
updateSpeak()calls to pass full provider config object - Update
FunctionCallRequestevent handlers for new array format - Update
FunctionCallResponseto use{ id, name, content }instead of{ function_call_id, output } - Replace
AgentEvents.InstructionsUpdatedwithAgentEvents.PromptUpdated - Remove any
AgentEvents.FunctionCallinghandlers - Replace
context.messages/context.replaywithgreetingif applicable - Update
Welcomeevent handlers to userequest_idinstead ofsession_id - Add
experimental: trueif you needAgentStartedSpeakingevents - Test all Voice Agent connections and event handlers