Drachtio for Node.js SIP-to-AI Bridges in 2026: B2BUA Without the Pain
Drachtio is connect-style middleware for SIP, with a C++ Sofia core and a Node.js framework on top. In 2026 it is the fastest path from carrier trunk to OpenAI Realtime if you live in JavaScript and rtpengine.
The Node.js telephony developer in 2026 has two real options: write your own glue around the Sofia SIP stack, or use Drachtio. Drachtio runs Sofia inside a separate C++ daemon and gives you a connect-flavored middleware layer to wire signaling logic, dialogs, and B2BUA bridges in maybe 200 lines of TypeScript.
Background
Drachtio was created by Dave Horton (formerly at Twilio) and is now maintained as drachtio-server (C++) and drachtio-srf (Node.js). The C++ side parses SIP, manages transports, transactions, and dialogs. The Node side talks to drachtio-server over a TCP control connection and exposes Express-style middleware for INVITE, REGISTER, OPTIONS, MESSAGE, and so on.
The killer feature for AI voice is createB2BUA. You receive an INVITE, decide what to do, and Drachtio creates a paired UAS+UAC dialog with media steered through rtpengine. Hangup propagates automatically. The same pattern handles SIP-to-WebRTC gateway use cases where one leg is a carrier trunk and the other leg is your in-browser AI agent.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
Recent activity on the drachtio-server repo shows commits in April 2026, which means it is alive and current. The associated Docker images on Hub are updated within the same window.
Architecture
graph LR
A[SIP Carrier] --> B[drachtio-server C++]
B <-->|TCP control| C[Node.js drachtio-srf]
C -->|SDP rewrite| D[rtpengine]
D -->|RTP| E[Media Sink]
E -->|WebSocket| F[OpenAI Realtime]
C -->|signaling| G[Tenant logic / DB]
// Minimal drachtio-srf B2BUA to a WebRTC AI agent
const Srf = require('drachtio-srf');
const srf = new Srf();
srf.connect({host: '127.0.0.1', port: 9022, secret: 'cymru'});
srf.invite(async (req, res) => {
try {
const { uas, uac } = await srf.createB2BUA(req, res,
'sip:[email protected]',
{ localSdp: req.body, proxyRequestHeaders: ['from','to'] }
);
[uas, uac].forEach(d => d.on('destroy', () => {
uas.destroy(); uac.destroy();
}));
} catch (err) {
console.error('B2BUA failed', err);
}
});
CallSphere implementation
CallSphere does not run Drachtio in production. Every inbound and outbound call across our six verticals (Healthcare AI on FastAPI :8084 to OpenAI Realtime, Real Estate AI, Sales Calling AI with 5 concurrent outbound, Salon AI, IT Helpdesk AI, After-Hours AI with Twilio simul call+SMS and 120-second timeout) terminates on Twilio Programmable Voice. We use TwiML
Build steps
- Run drachtio-server in Docker on a publicly routable IP (or behind your SBC); expose 5060 UDP/TCP and 9022 TCP for the control connection.
npm install drachtio-srf rtpengine-client.- Connect to drachtio-server with the shared secret and write an invite handler that decides routing per call.
- For AI bridges, use createB2BUA and proxy the audio through rtpengine to your media bridge or directly to a SIP-enabled AI like LiveKit or Pipecat.
- Use the Dialog object to handle re-INVITE, BYE, and INFO (DTMF).
- Add a registrar middleware if you need to host SIP endpoints; otherwise stick to trunk-mode B2BUA.
- Deploy behind a process manager (PM2, systemd) and monitor active dialogs as a Prometheus metric.
Pitfalls
- drachtio-server and srf must agree on protocol version; pin both via Docker tags.
- The control connection is plaintext by default; deploy on a private network or use a VPN.
- rtpengine SDP rewriting needs careful handling for SRTP-to-RTP and Opus codec negotiation.
- B2BUA dialogs are independent until you wire destroy events; forgetting that leaks one leg.
- Drachtio is single-process per drachtio-server instance; scale horizontally with multiple processes behind a SIP load balancer like Kamailio.
FAQ
Is Drachtio production-grade? Yes. It powers commercial CPaaS and contact-center products and has been in active development for over a decade.
Drachtio or pure Sofia bindings? Drachtio's middleware model is faster to ship. Pure Sofia gives you finer control if you need it, at 5-10x the lines of code.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
Can Drachtio host the media? No. Drachtio is signaling. Pair it with rtpengine, FreeSWITCH, or your AI media bridge.
How does Drachtio compare to Asterisk PJSIP? Drachtio is signaling-only, Node-friendly, and stateless if you let it be. Asterisk is a full PBX. Different tools for different problems.
Does Drachtio support SIP REFER? Yes, both inbound and outbound. Useful for transferring calls into a Twilio SIP domain or back to a human queue.
Sources
- drachtio-srf documentation
- drachtio-server on GitHub
- Building a SIP-to-WebRTC Gateway with Python and Drachtio
- Bridging AudioBridge and SIP with Drachtio - Meetecho
Start a 14-day trial to skip the bridge entirely, see pricing, or book a demo to compare a Drachtio reference build against our managed Twilio stack.
Try CallSphere AI Voice Agents
See how AI voice agents work for your industry. Live demo available -- no signup required.