No backend, and anyone may talk to the agent? A public
agent lets the SDK create sessions with just an
agentId — no token involved, gated by an origin allowlist and rate limits.Create a token on your backend
Your backend exchanges your API key for a single-conversation token.1
Create a session from your backend
Call
POST /v1/agent/sessions with your API key. This is where you set
per-session parameters — user identity, overrides, dynamic variables.2
Return the response to your frontend
The response is the session token. Forward it verbatim.
3
Start the client with the token
Pass the object to
AgentSession.start({sessionToken}) unmodified. The SDK
handles the connection from there.Browser
overrides, dynamic_variables, language, tool_events, timezone, and
world_context belong in your backend’s creation request — the SDK forwards
these options only in public agent mode.Request fields
Unknown fields — top-level or inside
overrides — are rejected with 422.
Overrides
overrides replaces parts of the agent’s published configuration for one session — the agent itself never changes:
language and voice_id — the prompt-shaping fields are rejected with 400 regardless of the agent. Create the session from your backend to use them.
The session record stores which overrides took effect.
Everything else on the request is not an override: dynamic_variables, timezone, record_audio, and tool_events are separate top-level fields. Session length is not settable per session — max_duration_seconds comes from the agent’s conversation configuration.
Response
JSON
Treat the response as opaque and pass it to
start() unmodified. If the SDK does not recognize the transport value, it fails fast with an unsupported_transport error asking you to upgrade the SDK — it never silently degrades.
Token lifetime
- A session token is single-use:
start()consumes it once to establish the conversation. - On network drops the SDK reconnects at the transport level using the same connection state — it never re-creates the session, so you never need a fresh token mid-call.
- Once a session ends, the token is spent. Create a new token for each conversation.
Ending sessions from your backend
A session normally ends from the client side — the user disconnects, or the agent hangs up. To force-end a live session server-side, call the end endpoint with your API key and thesession_id from the creation response:
Request
204. The session record stays readable in conversation history, along with the transcript and recording when the agent stores them. The same endpoint ends in-progress phone calls too.
Keep API keys on the server
Error responses
Session creation fails with standard HTTP statuses; the SDK surfaces them as aFishAgentError with statusCode set.
The complete status-code reference for every
/v1/agent endpoint — error shapes, 400 vs 422, conflict semantics — is on Agents API errors.
Going further
Public agents
The credential-free alternative, with origin allow-lists.
Widget with private agents
Feed the widget session tokens from your backend via
sessionTokenProvider.Web SDK
Everything
AgentSession can do once connected.Dynamic variables
Personalize each session at creation time.

