Overview
Each conversation starts by callingPOST /v1/sessions, which returns a session_id and an
agent_url. Every subsequent real-time call for that conversation — the WebSocket, WebRTC
signalling, and end — goes to agent_url, not necessarily the host that served the open
request. When the conversation ends, call POST {agent_url}/v1/sessions/{sid}/end to close it
cleanly.
agent_url exists because the WebSocket/WebRTC connection is served by a separate, stateless
process from the one that opens sessions. In most deployments it resolves to the same public
API host behind a reverse proxy — treat the value as opaque and always use what the response
returns rather than assuming it equals your base URL.Lifecycle stages
1
Open
POST /v1/sessions creates the session. At this point the server:- Resolves the credential to a kiosk and workspace.
- Loads the knowledge base and guardrail rules into a fast cache.
- Runs
OnSessionStartfraud checks. - Returns a
session_id(UUID) and anagent_url.
agent_url is the base URL for every subsequent real-time call — see the note above.
detected_language currently just echoes the preferred_language you sent (no real
detection yet); it is omitted if you didn’t send one. A disclosure_text field is planned
for a future EU AI Act disclosure feature but is not populated by the server today.
ice_servers (TURN/STUN credentials) is included only when TURN relay is configured for
your workspace — see WebRTC voice.See Language support for how to send preferred_language.2
Interact
While the session is open, the device sends messages over a WebSocket (text mode), streams
real-time audio over WebRTC (voice mode), or bridges a telephone call (voip mode). Each turn
runs through the full pipeline:
- FraudGuard checks the input.
- Guardrail rules gate the input.
- The prompt is built (persona + knowledge + history).
- The LLM generates a response.
- Tool calls are executed (up to 5 per turn).
- Guardrail rules check the output (PII, blocked phrases).
- Conversation history is updated.
3
End
POST {agent_url}/v1/sessions/{sid}/end closes the session. The server:- Flushes all usage events to the database.
- Releases the WebRTC peer connection if one exists.
- Marks the session as closed with
end_reason: clean.
204 No Content. Calling it on an already-closed session returns
400 SESSION_ENDED.Conversation history
The server maintains a rolling conversation history for the duration of the session. History is trimmed automatically when it approaches 8,000 tokens — the two most recent turns are always preserved regardless of length. History is not persisted after the session ends. If you need conversation logs, listen to the usage events or build your own persistence layer on top of the API.Automatic session closure
Two independent mechanisms can close a session without the device callingend:
Hard time limit — every session has a maximum duration (default 4 hours, overridable per
kiosk by a session_time_limit guardrail rule). 60 seconds before the deadline, the WebSocket
sends a session_expiring warning frame (or, for voice, a session_expiring event on the
WebRTC control data channel); at the deadline the connection is closed with
end_reason: time_limit. Reconnecting after this point returns SESSION_ENDED.
Idle abandonment — a background worker sweeps for sessions with no activity on a fixed
interval and closes genuinely idle or disconnected sessions with end_reason: abandoned. Usage
data is flushed as part of the cleanup either way.
Both
time_limit and abandoned closures count toward your plan’s usage. Always call end
explicitly (end_reason: clean) when the conversation is genuinely finished — it’s faster and
keeps your analytics accurate.