For developers working on Allternit phone calls. The voice worker never calls the runtime directly: cloud-api queues and relays every call request to the runtime’s allternit-api, waking a sleeping cloud computer if needed. Events and thread rendering are described in Channel events, connect API and phone tools. User docs: Calls and texts in threads.

Signature scheme

These four routes skip the Clerk session check. cloud-api signs every request it relays to them (runtime_relay::relay_signed_request_to_runtime_with, keyed with the runtime’s stored credential_hash). Each request carries: path is the request path without the query string, for example /api/v1/voice/calls/call_1/events. The body is hashed exactly as sent; a DELETE hashes the empty string. The runtime compares signatures in constant time. The HMAC key is relay_key = sha256_hex(device_token): the ASCII bytes of the lowercase hex digest, not the raw token. cloud-api only stores that digest as credential_hash, so it can sign without the raw token. A signature made with the raw token is rejected. Known-answer vector (device token tok-123, ts 1700000000, POST, path /api/v1/voice/calls, body {}):
  • relay_key = c8963414bf6c4c869eeac5f8a057c3dc574d422f1b108397b66f67bab3d2f981
  • signature = 34edb38cb1c7839397d5993a055972d2f352b42164bcdfd935264cdcae1d1576 (send as v1=34edb38cb1c7839397d5993a055972d2f352b42164bcdfd935264cdcae1d1576)
The credential hash is now a signing secret for relays: treat runtime_devices.credential_hash as secret. Anyone with database access can forge relayed requests; runtimes are only reachable through the cloud relay.

Routes

Start a call

POST /api/v1/voice/calls
The runtime resolves the thread with the caller’s number (from for inbound, to for outbound), so calls and texts from one person share a thread, stores a voice_calls row and returns { "threadId": "…", "sessionId": "…" }. Repeating a callId returns the same ids. ownerId must match the signed owner, and the number must belong to that owner and bot (403 otherwise; 404 for an unknown number). numberId is optional and the body can carry line (see the call line). For a linked_phone line there is no number lookup; see Calls on a linked phone.

Write call events

POST /api/v1/voice/calls/{callId}/events with { "events": [{ "type", "n", "payload", "occurredAt" }] }.
  • Each event becomes a bot_events row on the call’s thread with the idempotency key call:<callId>:<type>:<n>. Replays are counted as duplicates.
  • Event types must start with call.. Every payload gets callId.
  • The actor comes from payload.speaker: caller is the caller’s number, human is payload.by (or the owner), anything else is the bot.
  • call.transcript.delta with final: false is ignored (counted in ignored); interim text belongs to the live stream.
  • call.ended marks the call ended and stops any turn still running.
  • Response: { "written": 4, "duplicates": 0, "ignored": 1 }. An unknown callId is a 404.

Run a turn

POST /api/v1/voice/calls/{callId}/turn with { "text": "…", "segmentId": "…" } answers text/event-stream. Each data: line is JSON: A native bot session is streamed: the runtime subscribes to the Gizzi session’s event stream and forwards text.delta as words arrive (cut at word boundaries) and a tool event when a tool starts and when it finishes (done or error). Each tool step is also written to the thread as agent.tool.started, agent.tool.completed or agent.tool.failed. The turn is sent exactly as channel messages are (same model, bot instructions, memory and project permissions). The runtime adds a short spoken-style instruction server-side so replies stay brief. A call that has ended answers 409. A caller cannot click an approval, so a tool that asks for one stops the turn and the stream carries a spoken-friendly error telling the caller to approve it in the app. A turn that runs longer than 120 seconds is aborted with an error. Only one turn runs per call. A new turn aborts the running one first, and closing the stream aborts it too.
A vendor-bound session or one placed on another Allternit has no local event stream. Those turns run the channel path and answer once, so the reply arrives as sentence chunks of the finished text and no tool events are sent. The runtime logs that fallback. The stream shape is the same either way.

Abort (barge-in)

DELETE /api/v1/voice/calls/{callId}/turn aborts the running turn the way the Stop button does (the Gizzi turn is stopped and the stream closes within 100 ms) and always returns 204, even when nothing was running.

Where the device token comes from

The runtime reads its own device token from env ALLTERNIT_RUNTIME_DEVICE_TOKEN plus ALLTERNIT_RUNTIME_OWNER_ID, or else from the shared runtime-identity.json ($ALLTERNIT_RUNTIME_IDENTITY_PATH, default ~/.config/allternit/runtime-identity.json), re-reading it when allternit-node rotates the token. An expired identity counts as absent. With no source, signed requests answer 503. Provisioned cloud computers get both env vars at pairing time. The verifier is the shared relay_auth module, also used by other relayed envelopes. See cmd/allternit-api/docs/VOICE_CALLS.md.

Call controls from the app

The app sends hangup, mute, hold, DTMF, transfer, listen and takeover to cloud-api, not to a local gateway: POST /api/v1/voice/calls/{callId}/control with the signed-in user’s Clerk token (sendCallControl in allternit-ai src/lib/gateway/call.ts). listen and takeover answer { "token", "url", "room" }, which the app passes to joinCallAudio. Desktop, ai.allternit.com and the m.allternit.com PWA use this one path.

Other signed relays

The voice routes are not the only runtime paths that trust cloud-api instead of a platform signature. cloud-api has already checked Discord’s, Slack’s, Teams’ or the mail provider’s own signature, so the runtime would otherwise accept any caller who could reach the path. Those paths now require the same x-allternit-runtime-sig headers, verified with RelayedAuth, and the owner comes from the verified signature: Public webhooks signed by the platform itself (Telegram, WhatsApp, raw Discord interactions) are unchanged. Responses are the same as for the voice routes: 401 for a missing or bad signature, 503 when the runtime has no device token yet.

Cloud-api routes the call worker uses

The worker authenticates to cloud-api with a bearer token (ALLTERNIT_VOICE_WORKER_TOKEN). The wire shapes are defined by the worker’s cloud_client.rs. How cloud-api translates for the runtime:
  • call.started becomes the create body above (callId, botId, ownerId, numberId, line, from, to, direction, room, startedAt). The cloud queues its own copy first with seq 0, so the worker’s own call.started is a duplicate.
  • Every other event becomes {"events":[{type, n, payload, occurredAt}]} with one entry. n counts that event type within the call. Delivery retries with backoff for 24 hours and wakes a sleeping cloud computer.
  • A turn is relayed to the runtime’s SSE POST …/turn; each text.delta becomes a delta line, tool progress and keep-alives are not spoken. If the worker drops the connection before done, cloud-api calls the runtime’s DELETE …/turn. If the runtime does not answer within 20 seconds, the worker gets a 504.
Cloud-api migration 030 adds the columns behind this (voice_bot_config.name, voice_calls.sip_call_id and consent_ref, voice_call_events.seq and at_ms). The runtime saves the spoken name with PUT /api/v1/voice/bot-config/{botId} (name; recording accepts "off", "consented" or a boolean; transferTargets is the owner-approved warm-transfer list, see Phone numbers).

Calls on a linked phone

A bot’s own real phone (Android over adb, iPhone over iCTRL) can be wired to the Mac running Allternit Desktop with a call cable: the phone’s headset port goes to a USB sound card, so the Mac input device carries the caller’s voice and the Mac output device carries the bot’s voice into the phone’s mic. User guide: Let your bot talk on its own phone. The rest of the call (worker, turns, events, controls, UI) is the same as a SIP call.

Flow

  1. Desktop’s watcher sees the phone ringing (Android: dumpsys telephony.registry polled every second; iPhone: the incoming-call screen via screen_text), waits one ring (3.5 s) and answers (KEYCODE_CALL, or a tap on Accept). If the input or output device is missing it doesn’t answer and raises a needs-you notice Call audio cable not found for <phone>. For an outbound call, the bridge starts when an approved phone.call.dial goes off-hook.
  2. Desktop calls POST /api/v1/voice/linked-calls on cloud-api.
  3. A hidden window in Desktop joins the returned room with livekit-client: it publishes the input device (echo cancellation, noise suppression and auto gain off) and plays the agent’s audio to the output device with setSinkId.
  4. The allternit-voice worker is dispatched to the room and runs the bot as it does for a SIP call. Its POST /api/v1/voice/calls sends line and no numberId.
  5. When the carrier call ends, Desktop leaves the room. When the room goes away (for example after hangup), Desktop ends the carrier call.

Rooms and identities

  • Room name: call-lp-<uuid>. It keeps the call- prefix the worker accepts.
  • Desktop joins as participant identity linked-phone-<deviceId>, kind Standard. The worker treats a participant whose identity starts with linked-phone- exactly like the SIP caller: its audio is the caller, and when it leaves the call ends.
  • Agent dispatch metadata is a JSON string in the job metadata: {source: "linked_phone", botId, ownerId, line, direction: "inbound" | "outbound", from, to}. The worker parses job.metadata as JSON into its attributes.
  • Controls: hangup deletes the room. mute, unmute, listen, takeover and release work as usual. dtmf, transfer and hold are not supported; the worker acks with call.state.changed unchanged plus {unsupported: "<action>"} and never fails the call.

cloud-api routes

POST /api/v1/voice/linked-calls checks that the bot belongs to the owner and that the owner’s plan includes voice. It creates the room with the agent dispatch above and records a row in voice_linked_call_rooms (room primary key, owner_id, runtime_id, bot_id, line jsonb, direction, created_at, ended_at). The worker’s POST /api/v1/voice/calls with a linked_phone line is trusted only for a room in that table, and owner, runtime and bot come from that row rather than from the phone-number directory. The app uses GET /api/v1/voice/calls/live on ai.allternit.com and the PWA, polling every 5 seconds while a phone mirror is open, to find a live call on that phone. Desktop uses its own bridge status (window.allternit.phones.callBridgeStatus() and onCallBridgeEvent) plus the thread’s call events. In cloud-api’s voice_calls, number_id is nullable and the table has line (jsonb) and line_kind.

Runtime

  • The create body takes an optional number_id and line. For a linked_phone line the number lookups are skipped.
  • The thread is resolved with thread_routes::channel_thread(db, rt, bot_id, "phone", key, …) where key is linked:<deviceId>:<caller E.164>, or linked:<deviceId>:unknown when the caller’s number is withheld (a from that isn’t E.164 is allowed).
  • Sender roles apply as for phone numbers: a caller matching the owner’s identity is the owner, anyone else is a stranger handled under the receptionist policy.
  • In the runtime’s voice_calls, number_id is nullable and line holds the line as JSON text.

Billing

When a linked-phone call ends, cloud-api records its seconds as engine cloud usage through the existing voice usage path, so it counts as Cloud Voice minutes. It follows ALLTERNIT_VOICE_BILLING_MODE like other Cloud Voice usage.

Desktop settings and IPC

Per-phone settings live on the phone’s stored record (Android StoredPhone, iPhone IosLinkRecord):
window.allternit.phones exposes callBridgeGet(serial), callBridgeSet(serial, cfg), callBridgeStatus() ([{serial, deviceId, label, platform, enabled, state: "idle" | "ringing" | "answering" | "live" | "ending" | "error", room?, error?, platformSupport}]) and onCallBridgeEvent(cb). The settings sheet is Call audio in the linked phone row’s menu (ConnectedPhoneRow).