🎤Micdrop

Migrate a Voice Agent from Vapi to Micdrop

A Vapi assistant is a JSON configuration that runs on Vapi’s platform, which calls your server URL for tools and events. With Micdrop, the assistant is TypeScript code on your own Node.js server: the same server runs the call, executes the tools and receives the end of call report. Your phone numbers stay at your telephony provider, which streams each call to that server, and you pay each AI provider directly with your own keys.

This page maps each Vapi concept to its place in a Micdrop project. Field names come from the Vapi documentation.

Start from the phone template

The phone template is a working agent on Twilio, Telnyx, Vonage or Plivo, with a first message, the end call tool, transfers, recording and an end of call report already wired:

Terminal window
npm create micdrop@latest my-agent -- --template phone --telephony twilio

The rest of this page points to the files of that project. Templates describes it, and the AI providers it can start with.

Concepts side by side

VapiMicdrop
AssistantThe options of MicdropServer, in src/server.ts
model.messages, the system messagesystemPrompt of the agent
model.provider and model.modelThe agent class and its model, in src/ai.ts
transcriberstt, a speech to text provider
voicetts, a text to speech provider
A speech to speech modelrealtime, a realtime model in place of the three
firstMessagefirstMessage
Function tools and the tool-calls eventTools with an execute function
endCall toolendCallTool()
transferCall tooltransferCallTool()
dtmf events from the keypaddtmfInput()
end-of-call-reportThe End event of MicdropServer
artifactPlan.recordingEnabledMicdropRecorder
Dynamic variables, {{name}}Call parameters, read with waitForParams
Phone numbersThe webhook of your number, at your telephony provider
@vapi-ai/web@micdrop/web, and @micdrop/react-native on a phone

Assistant

The model, the transcriber and the voice of an assistant become three providers, built in src/ai.ts. The system message of model.messages becomes systemPrompt:

new MicdropServer(transport, {
turns: { vad: 'silero' },
firstMessage: 'Hello, thanks for calling. How can I help you?',
stt: new GladiaSTT({ apiKey: process.env.GLADIA_API_KEY! }),
agent: new OpenaiAgent({
apiKey: process.env.OPENAI_API_KEY!,
model: 'gpt-5.2',
systemPrompt: 'You answer the phone for a small company.',
tools: [endCallTool()],
}),
tts: new ElevenLabsTTS({
apiKey: process.env.ELEVENLABS_API_KEY!,
voiceId: process.env.ELEVENLABS_VOICE_ID!,
}),
})

turns: { vad: 'silero' } has the server find the turns of the caller, since a phone line streams its audio continuously. AI providers lists every provider, and a fallback switches to another one when the first fails.

First message

firstMessage takes the sentence the assistant says as the call connects, like firstMessageMode: "assistant-speaks-first". The other modes map to:

firstMessageModeMicdrop
assistant-speaks-firstfirstMessage: 'Hello…'
assistant-speaks-first-with-model-generated-messagefirstMessage: { generate: true }
assistant-waits-for-userLeave firstMessage out

Tools

A Vapi function tool declares its parameters as JSON Schema, and Vapi posts a tool-calls message to your server URL, which answers with results. A Micdrop tool declares its parameters with Zod and runs in the process of the call, so its result goes straight back to the model:

import { z } from 'zod'
const tools = [
endCallTool(),
{
name: 'book_appointment',
description: 'Books an appointment for the caller',
inputSchema: z.object({ date: z.string(), time: z.string() }),
execute: async ({ date, time }) => bookAppointment(date, time),
},
]

The execute function receives typed arguments and returns any value, which the agent hands to the model. The same tools work with a realtime model.

End call

The endCall tool of Vapi maps to endCallTool(). The model calls it once the caller says goodbye, and the call ends after the goodbye has played. Its description option tells the model when to call it, which covers what endCallMessage and the tool messages set on Vapi:

endCallTool({
description:
'Call this tool once the caller has said goodbye, after saying goodbye yourself',
})

To end the call on phrases the assistant says, as endCallPhrases does, listen to its messages and call endCall() on the agent:

agent.on('Message', (message) => {
if (message.role === 'assistant' && /have a nice day/i.test(message.content)) {
agent.endCall()
}
})

maxDurationSeconds becomes a timer of your own that calls agent.endCall().

Transfers

The transferCall tool of Vapi with a destination of type: "number" maps to transferCallTool(), which the phone template adds when TRANSFER_NUMBER is set in .env. The agent transfers the caller when they ask for a person, after announcing it, through the API of the telephony provider.

TRANSFER_MODE=cold, the default, is the blind transfer of Vapi. TRANSFER_MODE=warm matches its warm transfers that speak a summary: the person reached hears a summary the model wrote, then the caller joins them.

Phone numbers

Vapi routes a number to an assistant with its assistantId, or asks your server with an assistant-request. With Micdrop, the number points its voice webhook to your server, and that webhook decides which agent answers:

ProviderWebhook of the phone template
Twiliohttps://<host>/twilio/voice
Telnyxhttps://<host>/telnyx/webhook
Vonagehttps://<host>/vonage/answer
Plivohttps://<host>/plivo/answer

A number you imported into Vapi from Twilio or Telnyx already lives in your account at that provider: change its webhook, and it rings your server. A free number of Vapi stays on Vapi, so buy one at your telephony provider.

To answer several numbers with different assistants, read transport.call.to, the number called, and pick the system prompt and the tools from it.

For an outbound call, ask your provider to dial the number with the same document the webhook returns. With Twilio, create the call with the TwiML of twilioStreamTwiml():

import { twilioStreamTwiml } from '@micdrop/telephony'
await fetch(
`https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Calls.json`,
{
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(`${accountSid}:${authToken}`).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
To: '+14155550100',
From: yourTwilioNumber,
Twiml: twilioStreamTwiml({ url: `wss://${host}/twilio/stream` }),
}),
}
)

Dynamic variables

Vapi fills {{name}} in the prompt from assistantOverrides.variableValues. With Micdrop, the webhook passes parameters to the stream, waitForParams hands them to the call, and the prompt is a template literal:

const params = await waitForParams(transport, (value) => value)
createAi({
systemPrompt: `You answer the phone for Acme. The caller's number is ${params.caller}.`,
})

The phone template passes the number of the caller this way. Validate the parameters with a Zod schema in place of (value) => value, as Auth and parameters shows.

Server events and the end of call report

Vapi posts events to your server URL. With Micdrop, the call runs in your process, so the events are listeners:

Vapi eventMicdrop
end-of-call-reportserver.on('End', ({ conversation, duration }) => …)
conversation-update, transcriptserver.on('Message', (item) => …)
status-update with endedThe End event
tool-callsThe execute function of each tool
assistant-requestThe webhook of your number

The phone template logs the conversation in its End listener. Replace the log with a write to your database or a request to your CRM.

Recording

artifactPlan.recordingEnabled maps to MicdropRecorder, which collects the audio of each message with its text. The phone template writes them to RECORDINGS_DIR, one WAV file per message and the transcript, in src/recording.ts. Replace the writes with an upload to your storage.

Web calls

A call from a page goes through your server too. Where @vapi-ai/web starts an assistant with vapi.start(assistantId) and a public key, @micdrop/web connects to your WebSocket, so the keys of the providers stay on the server:

import { Micdrop } from '@micdrop/web'
await Micdrop.start({ url: 'wss://example.com/call' })
Micdrop.on('StateChange', (state) => console.log(state.conversation))

The call-start, call-end and speech-start events of the Vapi SDK are fields of the call state: isStarted, isAssistantSpeaking and isUserSpeaking. The Next.js, Vite and Expo templates start from a working page or app.

What you run yourself

Your server now holds the call for its whole length, so deploy it where a process keeps a WebSocket open, close to the media region of your telephony provider. Check the signature of the webhooks and streams of your provider, as Telephony explains for each of them. Call history, dashboards and analytics are yours to build from the End event and the recorder.