Voice Socket

Connection Auth

The Voice Socket accepts two credentials on connect. Which one you use depends on whether the client can keep a secret and set request headers.

Client Credential How
Server / device ek_ API key Authorization: Bearer ek_… header on the handshake
Browser Ephemeral token ?token=evt_… query param

Both require the key (or the key that minted the token) to have the voice:connect scope.


Server: API key on the handshake

Anything that can set request headers and keep your key secret should send it directly — no token round-trip:

new WebSocket(`wss://core.eurekatechlabs.com/v1/voice/${agentId}`, {
  headers: { Authorization: `Bearer ${process.env.EUREKA_API_KEY}` },
});

An x-api-key: ek_… header is also accepted.


Browser: ephemeral token

Browsers can't set headers on a WebSocket, and putting a long-lived ek_ key in a URL leaks it into logs and history. So you mint a short-lived token server-side and pass only that to the browser.

Mint it (your server)

POST/v1/voice/tokens

Required scope: voice:connect

curl -X POST https://platform.eurekatechlabs.com/v1/voice/tokens \
  -H "Authorization: Bearer ek_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "agentId": "agt_xxxxxxxxxxxx" }'
{ "token": "evt_xxxxx.yyyyy", "expiresIn": 60, "agentId": "agt_xxxxxxxxxxxx" }

Inline agent? Send an agent config instead of agentId (see Inline agents). Either way, use the agentId from the response in the socket URL.

Connect (browser)

new WebSocket(`wss://core.eurekatechlabs.com/v1/voice/${agentId}?token=${token}`);

Token properties

  • Short-lived — about 60 seconds. Mint it immediately before connecting; don't cache or reuse it across sessions.
  • Bound to a single {product, org, agent}. The agentId in the URL must match the one the token was minted for, or the connection is rejected.
  • Scoped — minting requires voice:connect; the token carries only the permission to open one voice session.

What gets checked, in order

When you connect, the server:

  1. Reads the credential — ?token= if present, otherwise the Authorization / x-api-key header. Missing both → close 4401.
  2. For a token: verifies signature + expiry and that its agent matches the URL → invalid 4401, wrong agent 4403.
  3. Authorizes the session (key valid, agent belongs to the product, wallet has balance). Declined → 4409; empty wallet → 4403.
  4. Checks the agent config is valid → otherwise 4422.
  5. Applies per-product concurrency + rate limits → over the cap → 4429.

Full close-code table in Limits & Errors.


Always use `wss`

Connect over wss:// only. Audio and transcripts are live conversation data — never send them over an unencrypted socket.