🎤Micdrop

Grok Voice Agent API in Node.js

A realtime model running on the Grok Voice Agent API by xAI. It hears the user and answers with its own voice, in place of a speech to text, an agent and a text to speech.

The API speaks the protocol of the OpenAI Realtime API, so GrokVoice extends OpenaiRealtime and shares its handling of turns, interruptions and tool calls. What differs is the session: the voices, the reasoning switch and the tools the API runs itself, such as a web search or a search of X.

Installation

Terminal window
npm install @micdrop/grok @micdrop/openai

The same package also provides a speech to text and a text to speech. The providers page shows what every provider covers.

Usage with MicdropServer

import { GrokVoice } from '@micdrop/grok'
import { endCallTool, MicdropServer } from '@micdrop/server'
import { WebSocketServer } from 'ws'
const wss = new WebSocketServer({ port: 8081 })
wss.on('connection', (socket) => {
new MicdropServer(socket, {
firstMessage: { generate: true },
realtime: new GrokVoice({
apiKey: process.env.XAI_API_KEY || '',
model: 'grok-voice-latest', // Default model
voice: 'eve', // Default voice
systemPrompt: 'You are a helpful assistant',
language: 'en', // Optional, helps the transcription of the user
reasoningEffort: 'none', // Optional, the first word comes sooner
tools: [endCallTool()], // Automatically end call when user requests
}),
})
})

The Micdrop client detects when the user speaks, so the turn detection of the API is turned off. The audio of each turn goes to the API at 16 kHz as the client records it, is committed when the client closes the turn, and the answer is asked for right after. Tools go in the tools option or are added with addTool(), as with any agent.

When the user interrupts, the answer is cancelled and the conversation of the model is cut where the user most likely stopped hearing it.

Server Tools

serverTools hands the API tools it runs on its own during the answer, next to the tools of the agent that run in your server:

const realtime = new GrokVoice({
apiKey: process.env.XAI_API_KEY || '',
systemPrompt: 'You answer questions about the news.',
reasoningEffort: 'none',
serverTools: [
{ type: 'web_search', allowed_domains: ['reuters.com', 'apnews.com'] },
{ type: 'x_search', from_date: '2026-11-01' },
],
})
ToolWhat it does
web_searchSearches the web, within allowed_domains or outside excluded_domains
x_searchSearches posts on X, by handles and dates
file_searchSearches the collections given as vector_store_ids
mcpCalls the tools of a remote MCP server

The API bills these searches on top of the minutes of the call.

Events

GrokVoice emits the events of an agent, and two of its own.

EventPayloadDescription
AudioBufferA chunk of the voice of the model, PCM 16 bits, 24 kHz, mono.
PartialMessagestringThe transcript of the answer so far.
MessageMicdropConversationItemA message, a tool call or a tool result was added to the conversation.
ToolCallMicdropToolCallA tool declared with emitOutput ran, with its parameters and output.
CancelLastUserMessagenoneThe last user message was dropped because it carried no intent.
SkipAnswernoneThe model gave no spoken answer.
EndCallnoneThe model decided that the call is over.
FailednoneThe connection could not be restored after its retries.

Options

OptionTypeDefaultDescription
apiKeystringRequiredYour xAI API key
systemPromptstringRequiredInstructions of the model
modelstring'grok-voice-latest'grok-voice-latest, which follows the newest model, or grok-voice-3.0
voicestring'eve'eve, ara, leo, rex, sal and twenty more, or a custom voice id
languagestringundefinedLanguage of the user, as a BCP-47 code, for the transcription
keytermsstring[]undefinedNames and terms the transcription should expect, 100 at most
reasoningEffort'none' | 'high'undefinedWhether the model reasons before speaking, which it does unless set to none
serverToolsGrokServerTool[][]Tools the API runs itself, see above
replaceRecord<string, string>undefinedWords to say differently from how they are written, such as { nginx: 'engine x' }
speednumberundefinedSpeed of the voice, from 0.7 to 1.5
toolsTool[][]Tools the model can call, such as the built-in endCallTool()
connectionTimeoutnumber5000Time to open the connection, in milliseconds
retryDelaynumber1000Delay before reconnecting, in milliseconds
maxRetrynumber3Reconnection attempts before giving up

Reasoning

Grok Voice reasons before it speaks unless told otherwise. GrokVoice leaves the choice to the model, so set reasoningEffort: 'none' for the soonest answer, as the examples of this page do.

Speaking a Fixed Text

say(), and the firstMessage of the server when it is a text, has the model read the text word for word with a forced message of the API. The text lands in the conversation of the model as said by the assistant, once.

Voices

GrokTTS.listVoices() lists the voices Grok Voice speaks with, the same as its text to speech:

import { GrokTTS } from '@micdrop/grok'
const voices = await GrokTTS.listVoices({
apiKey: process.env.XAI_API_KEY || '',
})

GrokVoice.listModels() returns the models the documentation of the API lists, without calling it.

Reconnection

When the connection closes, GrokVoice reconnects and sends the conversation written so far to the new session. The answer in progress ends with the old session. What the call sends while the connection opens waits for it and goes out once it is back. After maxRetry failed attempts, Failed is emitted and every later answer ends right away.