🎤Micdrop

Deploy an AI voice agent on Cloudflare Workers with Durable Objects

Run a real-time voice agent on Cloudflare Workers, one Durable Object per call, with no server to keep up: the architecture, the complete TypeScript code, the providers that run there, the limits and what a minute costs.

November 29, 2026

Godefroy de Compreignac

Key takeaways

  • A voice call is a long lived WebSocket with state, which a plain Worker cannot hold. A Durable Object can: the Worker routes each call to a new one, which runs the whole conversation.
  • Micdrop runs on Workers as it runs in Node. `MicdropServer` takes the server half of a `WebSocketPair`, and the `nodejs_compat` flag provides the Node APIs it uses.
  • The cloud providers run there (OpenAI, Gemini, Mistral, ElevenLabs, Cartesia, Gladia, the AI SDK). Local models and Silero stay on Node, so turns are found in the browser, or with the volume VAD on the server.
  • A Durable Object is billed for the time it stays active, at its full 128 MB. That comes to about a hundredth of a cent per minute of call at the prices of November 2026, before the AI providers.
  • Workers suit a TypeScript team that wants no server and per call scaling. A Node server stays the better home for local models, Silero VAD on phone lines and heavy CPU work.

A voice agent holds a connection open for the length of a call, keeps a conversation in memory, streams audio both ways and talks to two or three AI providers at once. That is the opposite of the request and response a serverless function is built for, which is why most voice frameworks ask for a long running server or a managed cloud of their own.

Cloudflare Workers has the missing piece: Durable Objects, small stateful instances that hold a WebSocket as long as it stays open. This guide runs a complete voice agent there, one Durable Object per call, with Micdrop, the open source TypeScript library this site publishes. The code comes from the Cloudflare example of the repository, which runs on your machine with no Cloudflare account.

The architecture

graph LR
  A[Browser] -->|WebSocket /call| B[Worker]
  B -->|new unique id| C[Durable Object, one per call]
  C <-->|fetch and WebSocket| D[Speech to text]
  C <--> E[LLM]
  C <--> F[Text to speech]
  1. The browser opens a WebSocket to the Worker, on /call.
  2. The Worker creates a Durable Object with a new unique id and forwards the request to it.
  3. The Durable Object creates a WebSocketPair, gives one half back to the browser and hands the other to MicdropServer, which runs the call: it receives the audio of the user, transcribes it, asks the LLM and streams the voice back.
  4. The connections to the AI providers go out from the Durable Object, and everything closes when the call ends.

Each call lives in its own instance, so a thousand calls are a thousand Durable Objects that Cloudflare places and scales without a fleet to size.

Set up the project

Terminal window
npm create cloudflare@latest voice-agent -- --type hello-world --lang ts
cd voice-agent
npm install @micdrop/server @micdrop/openai @micdrop/web
npm install -D vite

The browser side uses @micdrop/web, and the Worker serves the page from its static assets: an index.html with a call button that loads src/client.ts, built by Vite into dist/.

Configure the Worker

@micdrop/server uses Buffer, node:stream and node:events, which Workers provides with the nodejs_compat flag. The config declares the Durable Object class that holds each call:

wrangler.jsonc
{
"name": "voice-agent",
"main": "src/worker.ts",
"compatibility_date": "2026-11-01",
// Buffer, node:stream and node:events, which @micdrop/server uses
"compatibility_flags": ["nodejs_compat"],
// The page of the call, built into dist/
"assets": { "directory": "dist" },
// One Durable Object per call
"durable_objects": {
"bindings": [{ "name": "VOICE_CALL", "class_name": "VoiceCall" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["VoiceCall"] }],
// CPU time each incoming message may use, 30 s by default
"limits": { "cpu_ms": 30000 }
}

Run npx wrangler types once, so TypeScript knows the Env of the Worker and its VOICE_CALL binding.

The Worker and the Durable Object

src/worker.ts
import { OpenaiAgent, OpenaiSTT, OpenaiTTS } from '@micdrop/openai'
import { MicdropServer } from '@micdrop/server'
import { DurableObject } from 'cloudflare:workers'
declare global {
interface Env {
OPENAI_API_KEY: string
}
}
export default {
async fetch(request, env) {
const url = new URL(request.url)
if (url.pathname !== '/call') {
return new Response('Not found', { status: 404 })
}
if (request.headers.get('Upgrade') !== 'websocket') {
return new Response('Expected a WebSocket', { status: 426 })
}
// A new Durable Object for each call
const call = env.VOICE_CALL.get(env.VOICE_CALL.newUniqueId())
return call.fetch(request)
},
} satisfies ExportedHandler<Env>
/** One call, from the first word to the hang up */
export class VoiceCall extends DurableObject<Env> {
async fetch(): Promise<Response> {
const [client, server] = Object.values(new WebSocketPair())
server.accept()
const apiKey = this.env.OPENAI_API_KEY
const call = new MicdropServer(server, {
firstMessage: 'Hi! What can I do for you?',
agent: new OpenaiAgent({
apiKey,
systemPrompt:
'You are a friendly assistant. Your answers are spoken out loud, so keep them short and conversational.',
}),
stt: new OpenaiSTT({ apiKey, language: 'en' }),
tts: new OpenaiTTS({ apiKey, voice: 'alloy' }),
})
call.on('End', ({ duration }) => {
console.log(`Call ended after ${duration} s`)
})
return new Response(null, { status: 101, webSocket: client })
}
}

MicdropServer takes the server half of the pair exactly as it takes a ws socket in Node. The provider packages open their own connections with a fetch and an Upgrade header, the way Workers sends authentication headers along, so they need no setting of their own.

The browser

The client does not know it talks to a Worker. It connects to the same origin that served the page:

src/client.ts
import { Micdrop } from '@micdrop/web'
const url = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/call`
document.getElementById('call')!.addEventListener('click', async () => {
if (Micdrop.isStarted || Micdrop.isStarting) await Micdrop.stop()
else await Micdrop.start({ url })
})
Micdrop.on('StateChange', (state) => {
console.log(state.isUserSpeaking ? 'Listening' : 'Waiting', state.conversation)
})
// The assistant can hang up on its own
Micdrop.on('EndCall', () => Micdrop.stopAfterAnswer())

The client captures the microphone, runs the voice activity detection in the browser and streams audio only while the user speaks. That last point matters on Workers, as the next sections show.

Run it locally, then deploy

wrangler dev runs the Worker and its Durable Objects on your machine, with no Cloudflare account. Keep the key in .dev.vars:

Terminal window
echo "OPENAI_API_KEY=sk-..." > .dev.vars
npx vite build && npx wrangler dev

Open http://localhost:8787, start the call and talk. To deploy, set the key as a secret and publish:

Terminal window
npx wrangler secret put OPENAI_API_KEY
npx vite build && npx wrangler deploy

Authenticate the call

The Worker is the place to refuse a call before it costs anything: check a token in the query string or a cookie, and answer 401 before creating the Durable Object.

const token = url.searchParams.get('token')
if (!token || !(await isValidToken(token, env))) {
return new Response('Unauthorized', { status: 401 })
}

For parameters that the client sends once connected, a user id or the language of the call, waitForParams and handleError take the socket of the pair as in Node, as the parameters and authentication guide shows.

Which providers run on Workers

Every provider package that talks to its API over fetch and WebSockets runs in a Durable Object:

PackageComponents
@micdrop/openaiAgent, STT, TTS, Realtime, classifier
@micdrop/geminiAgent, STT, TTS, Live, classifier
@micdrop/mistralAgent, STT, TTS
@micdrop/elevenlabsTTS
@micdrop/cartesiaTTS
@micdrop/gladiaSTT
@micdrop/ai-sdkAgent, with the providers of the AI SDK that run there

Through the AI SDK, that includes Anthropic, Groq and the other hosted models it supports. The local models, Whisper, Kokoro, Piper and the others, load a model or a native runtime, so they stay on a Node server.

Turns on Workers

Something has to decide when the user starts and stops speaking. In a browser call, the client does it, and the Durable Object never runs a VAD.

When the server has to find the turns, turns: { vad: 'volume' } works on Workers, since the volume VAD is plain TypeScript. Silero and the semantic turn detection load an ONNX model through onnxruntime-node, a native module Workers cannot run.

Phone calls from a Durable Object

The telephony transports take the socket of the pair too, so a Durable Object can answer the media stream of Twilio, Vonage, Telnyx or Plivo. A phone line carries no turns, so the server finds them with the volume VAD:

import { TwilioTransport } from '@micdrop/telephony'
const transport = new TwilioTransport(server)
new MicdropServer(transport, { turns: { vad: 'volume' }, agent, stt, tts })

Silero tells a voice from the noise of a street much better than a level threshold, and RNNoise cleans the line before it. A phone agent that takes noisy callers is therefore better served by a Node server today.

Limits to plan for

Read on the Cloudflare documentation on 29 November 2026. Check the Durable Objects limits and the Workers limits before you size a deployment, as they change.

  • CPU time. Each incoming WebSocket message gives the Durable Object up to 30 seconds of CPU, raised to 5 minutes with limits.cpu_ms. A call spends most of its time waiting on the network, which costs no CPU.
  • Memory. An isolate has 128 MB, far more than a call with cloud providers uses.
  • Duration. A Durable Object stays alive while its WebSocket is open, so a call lasts as long as it needs.
  • Connections. A Worker waits on at most 6 connections at once while they open, WebSockets included. A call opens one or two per provider.
  • Plan. Durable Objects exist on the free plan, where a Worker gets 10 ms of CPU per request. Real calls need the Workers paid plan.

What a minute costs on Cloudflare

The Durable Objects pricing, read on 29 November 2026, bills two things beyond the $5 monthly minimum of the Workers paid plan:

  • Duration, at $12.50 per million GB seconds past 400,000 included each month, counted for the full 128 MB while the object is active. A minute of call is 60 × 0.125 = 7.5 GB seconds, about $0.0001.
  • Requests, at $0.15 per million past one million included. Incoming WebSocket messages count as one request every 20 messages, outgoing ones are free. Since the browser streams audio only while the user speaks, this line stays small next to the duration.

A call keeps timers and connections to its providers open, so its Durable Object does not hibernate while it lasts. Even so, Cloudflare adds about a hundredth of a cent per minute. The AI providers remain the bill: speech to text, tokens and voice, at their own prices, on your keys.

Workers or a Node server

Cloudflare WorkersYour Node server
OperationsNothing to keep up, each call scales aloneA process to deploy, monitor and size
Cloud providersThe packages listed aboveEvery package
Local modelsOut of reachWhisper, Kokoro, Piper and the others
Server turn detectionVolume VADSilero, Smart Turn, semantic detection
PlacementClose to the user, on the Cloudflare networkWhere you deploy it

The code of the call is the same on both: a MicdropServer with the same agent, tools and providers. Moving from one to the other changes the few lines that accept the WebSocket.

How this compares with Python voice frameworks

Pipecat, the most used open source voice framework, recommends a bot process per session, and offers Pipecat Cloud as its managed runtime for those processes. LiveKit Agents runs workers that join a WebRTC room, on your servers or on LiveKit Cloud. Both are mature, and both bring what a Durable Object does not: video, rooms, SIP and large communities.

What changes with a TypeScript library is the unit of deployment. A Micdrop call is an object in a JavaScript runtime rather than a process, so it fits a Durable Object, and the serverless platform plays the part a managed voice cloud would. For a team already on Cloudflare, that removes the only server the voice feature would have added.

Frequently asked questions

Can a Cloudflare Worker hold a WebSocket for a whole voice call?

A Durable Object can. The Worker routes the upgrade request to a Durable Object, which accepts its half of a WebSocketPair and stays alive as long as the socket is open. Each incoming message gets its own CPU budget, so a long call is no problem.

Does the OpenAI Realtime API work on Cloudflare Workers?

Yes. @micdrop/openai runs on Workers with all its components, the Realtime model included, and so does Gemini Live from @micdrop/gemini. The browser code stays the same as with a cascade of speech to text, LLM and text to speech.

Can I run Silero VAD or Whisper on Workers?

No. Both need onnxruntime-node or another native runtime, which Workers cannot load. In a browser call the client finds the turns, and on the server the volume VAD works. Local models belong on a Node server.

Do Durable Objects hibernate during a call?

No. A call keeps timers and connections to its providers open, so the object stays active and is billed for that time. At the prices of November 2026, that is about a hundredth of a cent per minute.

Can I answer phone calls on Cloudflare Workers?

Yes. The telephony transports of Twilio, Vonage, Telnyx and Plivo take the socket of a WebSocketPair, with the volume VAD for the turns. For noisy lines, Silero and RNNoise on a Node server find the turns more reliably.

Getting started

The Cloudflare Workers documentation is the reference for this setup, and the example runs with pnpm dev:cloudflare from the repository, with mock models when no key is set. To understand why a WebSocket is enough for a browser call, read WebSocket or WebRTC for a voice agent.

Keep reading