Quickstart — Server
From a server (or any host that can set request headers), skip the token step — send your ek_ key straight on the WebSocket handshake. This example uses Node and the ws library.
Only do this where the key stays secret — your own backend, a device you control. In a browser, use the token flow instead.
Step 1 — Connect with your API key
npm install wsimport WebSocket from 'ws';
const AGENT_ID = 'agt_xxxxxxxxxxxx';
const ws = new WebSocket(
`wss://core.eurekatechlabs.com/v1/voice/${AGENT_ID}`,
{ headers: { Authorization: `Bearer ${process.env.EUREKA_API_KEY}` } }
);
ws.on('open', () => console.log('socket open'));The key must have the voice:connect scope. No ?token= is needed — the header is the credential.
Step 2 — Receive audio and events
Binary frames are agent voice (PCM s16le, 24 kHz, mono). Text frames are JSON events.
ws.on('message', (data, isBinary) => {
if (isBinary) {
// Agent voice — write to a speaker, file, or your own telephony leg.
speaker.write(data); // data is a Buffer of Int16 PCM @ 24 kHz
return;
}
const frame = JSON.parse(data.toString());
switch (frame.type) {
case 'session.created': console.log('session', frame.sessionId); break;
case 'transcript': console.log(frame.role, frame.text); break;
case 'interrupted': flushPlayback(); break;
case 'tool.called': console.log('tool', frame.name, frame.args); break;
case 'session.ended': console.log('ended', frame.reason); break;
case 'error': console.error(frame.code, frame.message); break;
}
});Step 3 — Send audio
Send raw PCM (s16le, 24 kHz, mono) as binary frames. Here we pipe a source that already produces 24 kHz PCM:
audioSource.on('data', (chunk) => {
if (ws.readyState === WebSocket.OPEN) ws.send(chunk); // Buffer → binary frame
});If your source is a different rate (e.g. 8 kHz telephony or 48 kHz mic), resample to 24 kHz mono before sending. Oversized frames are dropped server-side — keep frames at or below 64 KB.
Step 4 — End the session
ws.send(JSON.stringify({ v: 1, type: 'end' }));
// or simply: ws.close();The session finalizes, bills, and fires call.ended to your webhooks — same as a phone call.
Bridging your own telephony
If you already run telephony (your own SIP/carrier/Twilio media stream), the Voice Socket is the AI brain: decode your call's audio to 24 kHz PCM, send it in, and play the agent's returned audio back down your leg. You own the transport; we own the agent.
