Jump to

  • Quickstarts
  • API reference
  • Webhook events
  • Error codes
  • SDKs

API reference

Client voice

Create voice access token

post/v1/voice/access-tokens

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-Keystring

    Makes 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 name to.phone matching one (a contactId is refused); flow:<id> or application:<id> — the call must run one of those (flow: { callFlowId } / { applicationId }). Numbers and flows together: both must match. A call outside it is refused 403 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_OWNED otherwise). A call naming another from is refused 403 VOICE_CALLER_ID_NOT_ALLOWED. Omitted: any of the organization’s own numbers the dial rules allow.

    at most 10 items

  • identitystringRequired

    Who 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 to client and a flow’s connect: { client } ring every app connected as this identity.

    at most 64 characters

  • incomingboolean

    May be rung: by a number routed to this identity (route.kind: client) or a flow’s connect: { client }.

    default true

  • outgoingboolean

    May 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:write on this key as well; every dial rule applies to each call.

    default false

  • purposestring

    With outgoing: what the token’s calls are for under TRAI/DLT rules (purpose on POST /v1/calls), bound into it — the app cannot choose it. Every call it places is checked as this purpose (a PROMOTIONAL call needs an assigned 140-series from and a verified voice header).

    One ofSERVICETRANSACTIONALPROMOTIONAL

    default "TRANSACTIONAL"

  • ttlSecondsinteger

    How 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)Required

  • grantsPublicVoiceAccessTokenGrantsRequired

    5 fields of grants
    • allowedDestinationsstring[] | nullRequired

      What an outgoing call may reach, as minted; null — any destination the dial rules allow.

    • callerIdsstring[] | nullRequired

      The caller IDs its calls may use, as minted; null — any of the organization’s own numbers the dial rules allow.

    • incomingbooleanRequired

    • outgoingbooleanRequired

    • purposestringRequired

      What its calls are for, as minted.

      One ofSERVICETRANSACTIONALPROMOTIONAL

  • identitystringRequired

  • objectstringRequired

  • socketPublicVoiceClientSocketRequired

    Where the client connects (@trovacast/sdk/voice reads this for you).

    3 fields of socket
    • namespacestringRequired

      The socket.io namespace.

    • pathstringRequired

      The socket.io path.

    • urlstringRequired

      The origin to open the socket on.

  • tokenstringRequired

    The signed token. Give it to your own app; it is shown once and never stored — a retry with the same Idempotency-Key answers the rest of this response with the token redacted. Treat it as a secret for its lifetime.

Errors

Request
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"
}'
Response 201 (json)
{
  "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"
}