Overview
The Freya Client SDK connects a Freya agent directly from the browser. You build whatever UI you want; the SDK handles WebRTC transport, microphone input, remote audio playback, and the real-time event stream between the page and the agent. The SDK is loaded as a script tag — no build step or package manager required.How it works
The connection flow has two parts: your backend mints a short-lived token, and the browser uses that token to open a WebRTC session.- The user does something on your page that should start a session (a button click, a page load, etc.)
- Your page calls your own backend — never the Freya API directly
- Your backend calls
POST /api/token/embedwith your API key and returns the token to the browser - The browser passes the token to
FreyaClient, which connects to the agent over WebRTC - Events fire as the conversation unfolds — transcripts, speaking state, tool calls — and you handle them however your UI needs
Minting a token
Token minting must happen server-side. The API key used must have the Issue web call tokens permission (calls:web-token), which allows it to mint tokens for in-browser calls and external embed integrations. You can set this when creating a key from the API Keys button in the sidebar.
token, expiresAt, and baseUrl. Pass all three to FreyaClient.
Installation
Add the script to your page. The SDK is served directly from the Freya dashboard:window.Freya.FreyaClient globally. No build step, bundler, or package manager is needed.
Quick start
Configuration
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
baseUrl | string | Yes | — | Freya API origin returned by the token endpoint |
token | string | Yes | — | Short-lived embed JWT |
mode | "call" | "chat" | No | "call" | "call" activates the microphone; "chat" is text-only |
metadata | Record<string, unknown> | No | {} | Arbitrary key-value pairs forwarded to the agent session |
customerVariables | Record<string, string> | No | {} | Variables injected into the agent’s system prompt at runtime |
iceServers | RTCIceServer[] | No | [] | TURN/STUN servers for production deployments |
Modes
Call mode
The microphone is activated whenconnect() resolves. The agent hears the user in real time and responds with voice. This is the default.
Chat mode
The microphone stays off. Send text withsendMessage() and listen to botLlmText or botTranscript for the agent’s response. If the agent has TTS configured, audio is still played.
Token lifecycle
- Tokens expire after
ttlSeconds(default 300 seconds). Mint a fresh one each time the user starts a new session rather than caching across page loads. - Set
allowedOriginon the server to the exact origin of the embedding page. The Freya backend rejects WebRTC connection attempts from other origins. - Tokens are single-use for establishing a session. Once a session is open the token is consumed.
Next steps
Client Reference
Full reference for all FreyaClient methods, events, and their payloads.
Agents
Configure the agent your embed session connects to — voice, system prompt, and tools.