API reference
Client voice
Create voice access token
post
Mints a client-voice access token for one identity of your app.
For your own server to call — never ship the API key to a browser. The token lets your app (a browser or a native app, through @trovacast/sdk/voice) connect to the client-voice socket as identity: place calls to numbers through every dial rule a POST /v1/calls meets (with outgoing, which needs calls:write on this key), and be rung by a number routed to client or a flow’s connect: { client } (with incoming). Signed, short-lived (60–3600 s, 600 by default) and bound to this key: revoking the key disconnects every client it minted for. The audio travels over the socket (PCM16, 8/16/24 kHz) — not WebRTC. Live keys only (422 TEST_MODE_UNSUPPORTED): a test key’s calls have no audio to carry.
Access: an organization key with the voice:client scope. Live keys only: a test key is refused with 422 TEST_MODE_UNSUPPORTED.
Headers
Idempotency-KeystringMakes the request safe to retry: a repeat with the same key and the same body returns the stored success (with
Idempotent-Replayed: true) instead of running again; a 4xx stores nothing. A 5xx is stored and replayed to every retry with the same key (Idempotent-Replayed: true): the first attempt may have taken effect, so check before retrying with a new key — except the errors that provably changed nothing (503 MESSAGING_TRANSPORT,503 WHATSAPP_CONNECT_UNAVAILABLE; see https://trovacast.com/developers/idempotency), which store nothing, so a retry with the same key runs again. 1–255 visible ASCII characters; kept for 24 hours.
Request body
allowedDestinationsstring[]With
outgoing: everything the token may reach, bound into it. An E.164 number (+919812345678) or a prefix (+9180*) — the call must nameto.phonematching one (acontactIdis refused);flow:<id>orapplication:<id>— the call must run one of those (flow: { callFlowId }/{ applicationId }). Numbers and flows together: both must match. A call outside it is refused403 VOICE_DESTINATION_NOT_ALLOWED. Omitted: any destination the dial rules allow.at most 20 items
callerIdsstring[]With
outgoing: the caller IDs (from) its calls may use, bound into it — each one of this organization’s own assigned voice numbers (422 CALLER_ID_NOT_OWNEDotherwise). A call naming anotherfromis refused403 VOICE_CALLER_ID_NOT_ALLOWED. Omitted: any of the organization’s own numbers the dial rules allow.at most 10 items
identitystringRequiredWho the token speaks as: an id of your own for one user or device of your app — letters, digits,
_ . : -, at least one letter. Never a phone number or an email address (identities appear in call events and the audit log). A number routed toclientand a flow’sconnect: { client }ring every app connected as this identity.at most 64 characters
incomingbooleanMay be rung: by a number routed to this identity (
route.kind: client) or a flow’sconnect: { client }.default true
outgoingbooleanMay place calls (to a number, optionally with a flow). Off unless asked for: a token in a browser dials only when your server says so. Needs
calls:writeon this key as well; every dial rule applies to each call.default false
purposestringWith
outgoing: what the token’s calls are for under TRAI/DLT rules (purposeonPOST /v1/calls), bound into it — the app cannot choose it. Every call it places is checked as this purpose (aPROMOTIONALcall needs an assigned 140-seriesfromand a verified voice header).One of
SERVICETRANSACTIONALPROMOTIONALdefault "TRANSACTIONAL"
ttlSecondsintegerHow long the token connects for, in seconds. A call in progress outlives it; a new connection, or a new call, needs a fresh token (
device.updateToken).60–3600default 600
Response 201PublicVoiceAccessToken
expiresAtstring (date-time)RequiredgrantsPublicVoiceAccessTokenGrantsRequired5 fields of
grantsallowedDestinationsstring[] | nullRequiredWhat an outgoing call may reach, as minted; null — any destination the dial rules allow.
callerIdsstring[] | nullRequiredThe caller IDs its calls may use, as minted; null — any of the organization’s own numbers the dial rules allow.
incomingbooleanRequiredoutgoingbooleanRequiredpurposestringRequiredWhat its calls are for, as minted.
One of
SERVICETRANSACTIONALPROMOTIONAL
identitystringRequiredobjectstringRequiredsocketPublicVoiceClientSocketRequiredWhere the client connects (
@trovacast/sdk/voicereads this for you).3 fields of
socketnamespacestringRequiredThe socket.io namespace.
pathstringRequiredThe socket.io path.
urlstringRequiredThe origin to open the socket on.
tokenstringRequiredThe signed token. Give it to your own app; it is shown once and never stored — a retry with the same
Idempotency-Keyanswers the rest of this response with the token redacted. Treat it as a secret for its lifetime.
Errors
400VALIDATION_FAILED —identityis not 1–64 letters, digits,_ . : -with at least one letter, orttlSecondsis out of range.401API_KEY_INVALID — missing, unknown, revoked or expired key.403API_KEY_SCOPE_MISSING —outgoing: trueasked of a key withoutcalls:write.409IDEMPOTENCY_KEY_IN_FLIGHT — the first request with this Idempotency-Key is still running (retry afterRetry-After); or CONFLICT.422TEST_MODE_UNSUPPORTED — a test key. IDEMPOTENCY_KEY_REUSED — this Idempotency-Key was used for a different request.429RATE_LIMITED — retry afterRetry-Afterseconds.500INTERNAL_ERROR — our fault. With an Idempotency-Key, every retry with that key replays this answer (Idempotent-Replayed: true).
curl -X POST 'https://api.trovacast.com/v1/voice/access-tokens' \
-H "Authorization: Bearer $TROVACAST_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H 'Content-Type: application/json' \
-d '{
"allowedDestinations": [
"+919812345678",
"+9180*",
"flow:0b8f3c1e-7d2a-4f5b-9c6d-1e2f3a4b5c6d"
],
"callerIds": [
"+918031152580"
],
"identity": "support-desk.alice"
}'{
"expiresAt": "2026-11-05T10:00:00.000Z",
"grants": {
"allowedDestinations": [
"ALLOWED_DESTINATIONS"
],
"callerIds": [
"CALLER_IDS"
],
"incoming": true,
"outgoing": true,
"purpose": "SERVICE"
},
"identity": "support-desk.alice",
"object": "voice_access_token",
"socket": {
"namespace": "/voice-client",
"path": "/socket.io",
"url": "https://api.trovacast.com"
},
"token": "TOKEN"
}