pinecallDocs
The gateway / Tokens

Tokens

How a browser and a phone get a token, what each may do with it, and the log token for one call.

Where a tenant's backend mints a browser's token. It implements LiveKit's standard token endpoint (docs.livekit.io, authentication endpoint), so a stock livekit-client with TokenSource.endpoint(url, { headers }) joins the agent's room with what it answers, and no Pinecall client code is involved. LiveKit's contract, in short: a POST with optional room_name, participant_identity, participant_name, participant_metadata, participant_attributes, room_config; 201 with server_url and participant_token; the endpoint adds its own authentication and refuses with a 4xx the fields a client may not set.

What this runtime adds to LiveKit's mint#

  1. The org check. The endpoint takes the org's key holding talk (the tenant's backend holds it; the browser never sees it) and mints only for an agent somebody holds in the key's org and environment. Nobody holding it is 404, since a token for one is a browser joining a room nothing answers in. The token's room_config is one dispatch to the fleet of the key's environment, its metadata naming the agent, the org, the environment and the holder, so the one worker every org shares asks the gateway for that org's endpoints, declaration and keys.
  2. The contact id, and nothing PII. participant_metadata carries the org's opaque contact id (contact in the body) and nothing else. A name is refused: the log would carry it. What the backend seals in metadata rides the signed dispatch; the browser reads its token and changes none of it.
  3. One dispatch opens one call, where the token was minted. The call the token names is written into a ledger when it is minted, with the org, the environment and the agent it was minted for, and the dispatch that opens the call spends it: the gateway asks the ledger by the call's id at every POST /v1/calls, whatever the worker says. A worker that names another org, environment or agent is answered 404, as for a call nobody opened, and the token is left unspent. A join that creates the room again after the call ended is refused with 409 and token_spent on the agent's log. A second join with the same token while its call is live is bounded by the TTL alone, since LiveKit reads a token's room config only on the join that creates the room: keep it short.

The body#

field whose meaning
agent ours the agent's slug, or room_config.agents[0].agent_name as a stock client sends agentName
scope ours talk (default): publish the microphone, hear the agent. chat: the same room with no microphone. Both write on the call's data channel, the caller's own words; observe and supervise never do. Any other is 400: observe and supervise take the API key
contact ours the org's opaque id for the person; becomes participant_metadata
metadata ours JSON sealed into the call, reaching the worker in the signed dispatch and the agent as metadata of call.started, which an SDK reads as this.call.metadata. A visitor's public log never carries it
ttl_s ours 60 by default; past a day (86 400) it is cut to a day
tuning ours a test room's own voice and models, over the agent for this call alone and kept nowhere, over what its class declares as over what the org set, a model or a voice named on another vendor leaving the first one's voice, plugin and options behind: stt, llm, tts, tts_model, voice, language, temperature, end_of_turn, smart_interruptions (anything else is refused, 400). The sandbox's, by a key that opens pipeline: 403 for production's or for a key without it. It rides the signed dispatch; the worker says it again when it reads the call's config and keys, where it is checked again
log ours what the answer's log_token reads through: public (default) or tenant (Projections)
participant_identity LiveKit's who the browser joins as; web_<12 hex> when absent, and the call's from
participant_attributes LiveKit's published verbatim; the pinecall. prefix is ours and refused
resume ours an earlier answer's resume_token: back into that call while it waits, else a new call that carries it on (below); agent may then be left out
visitor_token ours an earlier answer's visitor_token: the new call's caller is the visitor it names, so every conversation one browser opens is one contact (below)
visitor_ip · user_agent ours the visitor's browser as the server that asks saw it: the address it came from and its User-Agent. They are kept beside the call's facts with the country the gateway reads from the address (below)
room_name · participant_name · participant_metadata LiveKit's refused, 400, each with its reason

The answer is 201 with LiveKit's two fields and three more every SDK ignores:

JSON
{ "server_url": "wss://cloud.pinecall.io", "participant_token": "eyJ…", "call": "call_5f1c…", "log_token": "eyJ…", "resume_token": "eyJ…", "visitor_token": "eyJ…" }

server_url is the LiveKit of the token's environment: the platform's name (PINECALL_DOMAIN) over wss, and for the sandbox wss://<the name>/sandbox when it has a LiveKit of its own (LIVEKIT_SANDBOX_URL); on a deployment with no name, LIVEKIT_PUBLIC_URL, else the environment's LiveKit. call is the room and the id its log will have, so the backend can watch it without decoding a JWT.

The log token#

The participant token dies in a minute; a page shows a call longer than that and after it ends. log_token opens no room (room_join, publish and subscribe all false), carries pinecall.scope: read and the projection asked, and lives four hours. It reads that one call's GET /v1/calls/{call}/events, /state and /recording, as ?token= or as the bearer, before and after the call ends; another call, an agent's log or a supervisor verb is 403. Those three endpoints answer any origin (GET, no credentials): the token the page brings is what opens them. POST /v1/agents/{slug}/dial answers one too.

Resuming a conversation#

A visitor's conversation outlives the page. LiveKit's own answer is two halves, and the runtime does both: a visitor who comes back in time sits back down in the same room, and one who comes back later gets a new session that opens on the old one's history (livekit.com, keep your agent in the room on reconnect).

  • The call waits for its visitor. A widget call does not end when the visitor's seat leaves: a reload, a closed tab and a dropped line look alike to LiveKit (CLIENT_INITIATED). It waits five minutes (A_VISITOR_RETURNS_S) and then ends itself, as caller_hung_up; the visitor's room outlives that wait by a minute (departure_timeout, LiveKit's own 20 s otherwise), so the room is never the one that goes first. A phone caller's call still ends with the leg.
  • A hang-up is said. Since a hang-up disconnects the seat as a reload does, the page says it first: POST /v1/calls/{call}/hangup?token= with the call's log_token, which reads the call for as long as it lasts, from any page, 202, and the call ends at once as caller_hung_up. A participant_token says it too while it lives, which is a minute unless the mint asked for more: a page that hangs up with it after that is refused 401, and its call waits. Over HTTP, with fetch's keepalive, so a tab that closes the same instant still completes it. The DataChannel topic pinecall.hangup from a seat of the call's own (talk or chat) says the same, for a page that has no token at hand — but a seat that leaves the room as it publishes loses the message with the room more often than not, so a page says it at the door. A browser that disconnects without either leaves the call to wait.
  • The resume token. Every answer carries resume_token, signed with the gateway's own key, naming the call and nothing else, for 30 days. It joins no room and reads no log. The browser keeps it beside the conversation; the backend sends it back as resume, with the org's key as for any mint.
  • Back in time. When the call is not sealed and an agent is still in its room, the answer seats the visitor in that room again, under the identity the call opened with, so the agent's session takes them back. call is the same call, and the token carries no dispatch: no second call can open from it. The log token reads the call from its start.
  • Back later. Otherwise the answer is a new call whose dispatch names continues. Its worker is handed, with POST /v1/calls, the turns of that call and of the calls it carried on in turn (ten at most), read back from their logs by the gateway with the private values opened: what was said and what the tools did, never anything the browser sent. The model opens on them and the agent greets nobody. The visitor's identity and contact are the earlier call's unless the body names others.

A resume token of another org or world reads as a call nobody opened (404), one for another agent than agent is 400, and anything that is not a live resume token of this gateway's is 403.

One visitor, every conversation#

Every answer carries visitor_token too: signed with the gateway's own key, naming one web visitor (web_<12 hex>), the org and the environment it was minted in, for a year. It joins no room, reads no log and resumes no call. The browser keeps it and its next mint sends it back as visitor_token: the new call's caller is that visitor, whatever conversation it is, so the console's list holds one row for the person and their calls under it, and an agent that remembers by contact remembers them. A token of another org or environment, an expired one or one that is not the gateway's names nobody, and the mint opens a new visitor; it is never refused. Who the call is with is, in this order: participant_identity, the call a resume carries on, the visitor token, a new visitor. A caller the tenant named is theirs to name again: the answer's token then names a new visitor, which nothing reads unless it is sent.

A page Pinecall hosts keeps the token in a cookie of the page's own name, pinecall_visitor (HttpOnly, Secure, SameSite=None, Partitioned, Path=/pinecall), set on every ticket's answer: the page's script never reads it, and in a frame of another site (a widget) it is that site's visitor, as a browser that refuses third parties' cookies allows.

Where the visitor was. The page's door reads the browser's own request: the address it came from, through the proxies the box trusts (PINECALL_TRUSTED_PROXIES), and its User-Agent. At POST /v1/tokens the tenant's server says them (visitor_ip, user_agent), as @pinecall/room/server's browserOf reads them off its own request. The gateway adds the country the address is in, from DB-IP's "IP to Country Lite" table (db-ip.com, CC BY 4.0), which the runtime's image carries packed (PINECALL_COUNTRIES_FILE); a box without it says no country. The three ride the signed dispatch to the worker, which says them again when it opens the call (POST /v1/calls), and are kept beside the call's facts: a row of GET /v1/sessions?visitors=true says them as visitor (Shapes, Visitor). No entry of the call carries them, so no app reads them, and the public projection never could.

Refusals#

400 a scope this endpoint does not mint, a field that is ours, a pinecall. attribute, no agent named, a resume for another agent · 401 no key of ours · 403 a key without talk, a resume that is no live resume token · 404 nobody holds that agent, a resume of a call of another org or world · 429 a quota, in its own sentence · 503 every worker of the fleet is full: fleet.full on the agent's log and a sentence naming POST /v1/callbacks.

A stock client#

TypeScript
import { Room, TokenSource } from "livekit-client";

const tokens = TokenSource.endpoint("https://clinica.example/token");   // the tenant's backend
const room = new Room();
await room.connect(...(await tokens.fetch({ agentName: "clinica-norte" })));

The backend's /token forwards the body to POST /v1/tokens with Authorization: Bearer pc_live_…, adding what it knows: contact, metadata, and the resume the page kept.