Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agents/build/dynamic-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
and they are on the {{plan}} plan. Greet them by name.
```

Pass values as a flat object of strings, numbers, or booleans. Variable names must match `[A-Za-z][A-Za-z0-9_]*` (no hyphens or dots; the dotted `system.*` names are reserved for [system variables](#system-variables)), string values are capped at 100,000 characters, and a request can carry at most 500 variables totaling 1 MiB as UTF-8 JSON. Violations reject session creation with `422`:

Check warning on line 38 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L38

Did you really mean 'booleans'?

<CodeGroup>
```bash API (curl)
Expand Down Expand Up @@ -63,6 +63,8 @@
```
</CodeGroup>

The curl request returns a session token. To hear the result, open the `join_url` from the response in your browser within about 5 minutes. See [Token lifetime](/agents/deploy/authenticated-sessions#token-lifetime).

### Default values

A placeholder is resolved in this order: the value supplied for the session, then the default configured on the agent. What happens when neither exists is set by **If a variable has no value** (`on_missing` in the API):
Expand Down Expand Up @@ -123,11 +125,14 @@
dynamic_variables: { customer_name: user.name, plan: user.plan },
}),
});
if (!response.ok) {
throw new Error(`Session creation failed (HTTP ${response.status})`);
}
const sessionToken = await response.json(); // pass to AgentSession.start({ sessionToken })
```

<Tip>
In `agentId` mode, values arrive from the end user's browser. Treat them as untrusted input, and use `sessionToken` mode when personalization must come from data only your backend knows.

Check warning on line 135 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L135

Did you really mean 'untrusted'?
</Tip>

### Custom variables in webhook tools
Expand All @@ -138,18 +143,18 @@
https://ehr.example.com/patients/{{patient_id}}/appointments?clinic={{clinic_id}}
```

- In the URL the value is URL-encoded, like argument values. In header values it is inserted as is. Numbers render as written, booleans as `true` or `false`.

Check warning on line 146 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L146

Did you really mean 'booleans'?
- In a JSON body, a value inside a string is JSON-escaped, like argument values. See [Values in a JSON body](/agents/build/webhook-tools#values-in-a-json-body).
- When the tool declares an argument with the same name as a custom variable, the argument wins: that placeholder is filled from what the agent supplies.
- A placeholder with no value renders as an empty string in the request, unlike in the prompt, where it stays visible.

<Warning>
On a [public agent](/agents/deploy/public-agents) the browser supplies custom values, so anyone can start a session with any `patient_id`. When a templated value identifies a person, don't let it authorize access to their data on its own: create sessions from your backend (`sessionToken` mode), or let the inbound call webhook supply it on phone calls.

Check warning on line 152 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L152

Did you really mean 'templated'?
</Warning>

## System variables

The platform fills a handful of `{{system.*}}` placeholders itself, on every session. You cannot supply or override them: the names you pass in `dynamic_variables` cannot contain a dot, so the two namespaces never collide.

Check warning on line 157 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L157

Did you really mean 'namespaces'?

| Variable | Value | Notes |
|---|---|---|
Expand All @@ -157,7 +162,7 @@
| `system.timezone` | The session's resolved IANA timezone, for example `Asia/Tokyo` | `UTC` when nothing resolves. Always equals the session's `timezone` field; see [which timezone a session uses](/agents/build/time-timezone#which-timezone-a-session-uses). |
| `system.today` | Today's date in that timezone, ISO 8601 `YYYY-MM-DD` | The calendar date at session creation. There is no `system.now`; see [Current date and time](#current-date-and-time). |
| `system.language` | The session language code, one of the [52 supported languages](/agents/build/voice-language#speaking-language) | The `language` [override](/agents/deploy/authenticated-sessions#overrides) when the request carries one, otherwise the agent's [speaking language](/agents/build/voice-language#speaking-language). |
| `system.caller_number` | The human party's number, E.164 | Inbound: the caller (empty if the carrier withheld the number, for example `anonymous` or one of Twilio's placeholder numbers, or it is not a valid E.164 number). Outbound: the number you dialed. Empty on non-phone sessions. |

Check warning on line 165 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L165

Did you really mean 'Twilio's'?
| `system.caller_id_withheld` | `"true"` or `"false"` (text, like every system variable) | `"true"` when an inbound caller's number was withheld, `"false"` for an inbound call with a number, an outbound call, and a WhatsApp call. Empty on non-phone sessions. See [Phone numbers](#phone-numbers). |
| `system.caller_number_spoken` | The same number written for speech, for example `+1; 4 1 5; 5 5 5; 0 1 2 3` | Use it wherever the agent should say the number out loud; see [Reading a number out loud](#reading-a-number-out-loud). Empty whenever `system.caller_number` is empty. |
| `system.dialed_number` | Your workspace number, E.164 | Inbound: the number that was called. Outbound: the number the call was placed from. Empty on non-phone sessions. |
Expand Down Expand Up @@ -191,7 +196,7 @@

#### Withheld caller ID

A caller can hide their number. The carrier then sends no digits (`anonymous`, `restricted`, an empty value) or one of the placeholder numbers Twilio sends in place of a hidden one. All of these count as withheld: `system.caller_number` and `system.caller_number_spoken` are empty, and `system.caller_id_withheld` is `"true"`. An empty `system.caller_number` alone does not tell you why, since it is also empty on non-phone sessions; `system.caller_id_withheld` does, because it is `"true"` only when a caller on a phone call hid their number.

Check warning on line 199 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L199

Did you really mean 'Twilio'?

When the number is withheld, the agent cannot match the caller to a customer record by number, so have it ask who is calling:

Expand Down Expand Up @@ -231,7 +236,7 @@

## Current date and time

With the agent's `context.current_time` switch on, the agent knows the current date and time without any variable: the platform states the date and the session's timezone at the start of every session and refreshes the time on every turn, so "tomorrow morning" or "next Tuesday" resolve correctly even in a long conversation. You don't need a custom `{{today}}` or `{{now}}`, and there is no `system.now`: variables render once, when the session is created, so a templated time would be stale from the first reply onward. When you want the date or timezone as text in a template, for example in a webhook tool URL, use the [`system.today` and `system.timezone`](#system-variables) system variables, which work whether the switch is on or off.

Check warning on line 239 in agents/build/dynamic-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/dynamic-variables.mdx#L239

Did you really mean 'templated'?

See [Time & timezone](/agents/build/time-timezone) for how the timezone is resolved and how the switch works per agent and per session.

Expand Down
2 changes: 2 additions & 0 deletions agents/build/time-timezone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
system prompt's character limit.
</Note>

Both facts also exist as [system variables](/agents/build/dynamic-variables#system-variables), available whether the switch is on or off, for the cases where you want to template them yourself, for example into a webhook tool's URL: `{{system.today}}` is the date at session creation as ISO `YYYY-MM-DD`, and `{{system.timezone}}` is the resolved IANA name (`UTC` when nothing resolves). There is no `{{system.now}}`: variables render once, when the session is created, so a templated clock would freeze at the opening. The per-turn time above is the one to rely on.

Check warning on line 33 in agents/build/time-timezone.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/build/time-timezone.mdx#L33

Did you really mean 'templated'?

## Which timezone a session uses

Expand All @@ -56,6 +56,8 @@
}'
```

The response is a session token for your client. To check the result yourself, open its `join_url` in your browser within about 5 minutes. See [Token lifetime](/agents/deploy/authenticated-sessions#token-lifetime).

<Note>
Phone-number inference is country-level only. Countries that span several
timezones (the US, Canada, Australia, Russia, Brazil) are skipped. Set the
Expand Down
54 changes: 39 additions & 15 deletions agents/deploy/authenticated-sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
</Step>
</Steps>

Create the session when the user starts the call. The token is valid for about 5 minutes and starts one conversation: see [Token lifetime](#token-lifetime).

<CodeGroup>
```bash API (curl)
curl --request POST https://api.fish.audio/v1/agent/sessions \
Expand Down Expand Up @@ -100,23 +102,37 @@

`timezone` overrides the agent's configured timezone for this session, so the agent speaks in your user's local date and time. The default is UTC: see [Time & timezone](/agents/build/time-timezone).

On the client, fetch the token from your backend and pass it to the SDK unchanged:
<Tip>
To try a session before you write a client, run the curl request and open the
`join_url` from the response in your browser.
</Tip>

On the client, fetch the token from your backend and pass it to the SDK unchanged. Check that your backend answered with a token before you hand the body to the SDK:

```javascript Browser
import { AgentSession } from "@fishaudio/agent-client";

const sessionToken = await fetch("/api/voice-session", { method: "POST" }).then(r =>
r.json()
);

const session = await AgentSession.start({ sessionToken });
// Run this from a click handler, once per call.
async function startCall() {
try {
const response = await fetch("/api/voice-session", { method: "POST" });
if (!response.ok) {
throw new Error(`Could not create a session (HTTP ${response.status})`);
}
return await AgentSession.start({ sessionToken: await response.json() });
} catch (error) {
showCallFailed(error); // your UI
}
}
```

`start()` rejects with a [`FishAgentError`](/agents/deploy/web-sdk#errors) when the token, the microphone, or the connection fails.

More on what the SDK can do once connected is in the [Web SDK](/agents/deploy/web-sdk) reference.

<Note>
`overrides`, `dynamic_variables`, `tool_events`, `timezone`, and
`context` belong in your backend's creation request. The SDK forwards

Check warning on line 135 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L135

Did you really mean 'backend's'?
these options (and its `language` shorthand for `overrides.language`) only in
[public agent](/agents/deploy/public-agents) mode.
</Note>
Expand All @@ -126,12 +142,12 @@
| Field | Type | Description |
| ------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agent_id` | string, required | The agent to talk to. It must have a [published version](/agents/deploy/versions-publishing). |
| `name` | string, optional | Display name for this session in the console's Conversations list, up to 128 characters. Omit it to show the session's start time instead. API-key requests only: keyless (public) creation rejects it with `400`. |

Check warning on line 145 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L145

Did you really mean 'keyless'?
| `overrides` | object, optional | Replace parts of the published configuration for this session. See [Overrides](#overrides). |
| `dynamic_variables` | object, optional | Up to 50 entries of string, number, or boolean values, substituted into `{{placeholders}}`. See [Dynamic variables](/agents/build/dynamic-variables). |
| `dynamic_variables` | object, optional | Up to 500 entries of string, number, or boolean values, substituted into `{{placeholders}}`. See [Dynamic variables](/agents/build/dynamic-variables). |
| `tool_events` | boolean, optional | Stream tool lifecycle events (`toolCallStarted` / `toolCallCompleted` / `toolCallFailed`) to the client. Default `true`; set `false` to keep tool inputs and outputs off the client. |
| `end_user_id` | string, optional | Your identifier for the end user, up to 256 characters. Stored on the session, returned on [session queries](/agents/monitor/conversation-history) where you can also filter by it, and echoed in [webhook](/agents/monitor/webhooks) payloads and [custom LLM](/agents/build/custom-llm) requests. |
| `metadata` | object, optional | Your own key-value namespace. Stored and returned verbatim on session queries and webhooks, never read or interpreted by the platform. |

Check warning on line 150 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L150

Did you really mean 'namespace'?
| `llm_extra_body` | object, optional | JSON object (at most 16 KB) forwarded verbatim to your [custom LLM](/agents/build/custom-llm) endpoint on every request as `fishaudio_extra_body`, for example the chat or thread the user is in. Not stored or returned on session reads; ignored when the agent uses a platform model. |
| `record_audio` | boolean, optional | Whether to record this session's audio. Overrides the agent's [recording setting](/agents/monitor/conversation-history#what-gets-stored) for this session only; omit it to use the agent's configuration. |
| `timezone` | string, optional | IANA timezone (like `Asia/Tokyo`) for the agent's sense of local time. Invalid names are rejected with `422`. See [Time & timezone](/agents/build/time-timezone). |
Expand Down Expand Up @@ -160,7 +176,7 @@
"agent_id": "YOUR_AGENT_ID",
"overrides": {
"first_message": "Welcome back, {{name}}, picking up where we left off.",
"voice_id": "802e3bc2b27e49c2995d23ef70e6ac89",

Check warning on line 179 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L179

Did you really mean 'voice_id'?
"language": "ja"
}
}
Expand All @@ -182,7 +198,7 @@
}
```

On [public agents](/agents/deploy/public-agents), keyless (browser-created) sessions may override only `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.

Check warning on line 201 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L201

Did you really mean 'keyless'?

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](/agents/build/configuration#call-duration).

Expand All @@ -195,23 +211,31 @@
"max_duration_seconds": 1800,
"transport": "livekit",
"livekit_url": "wss://example.livekit.cloud",
"token": "<participant token>"
"token": "<participant token>",
"join_url": "https://fish.audio/agents/join/#..."
}
```

| Field | Description |
| ---------------------- | ----------------------------------------------------------------------------------------------------------- |
| `session_id` | The session's id. Use it later to look up the [conversation record](/agents/monitor/conversation-history). |
| `expires_at` | Deadline for the client to connect. Create the token right before starting, not ahead of time. |
| `max_duration_seconds` | Hard cap on session length. |
| `expires_at` | Deadline for the client to connect, about 5 minutes after creation. See [Token lifetime](#token-lifetime). |
| `max_duration_seconds` | Hard cap on session length. It counts from when the session is created, not from when the client joins. |
| `transport` | Which transport the SDK uses for this session; `livekit` today. |
| `livekit_url`, `token` | Connection details for that transport, consumed by the SDK. |
| `join_url` | A link that opens this session in the browser, for trying it without writing a client. It carries the token, so anyone with the link can join this one session. Treat it as a secret. Do not parse it, because its format can change. |

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.
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. If you pass something that is not this response, such as your backend's error body or only the `token` string, `start()` rejects with `invalid_session_token` (from `@fishaudio/agent-client` NEXT_SDK_VERSION).

Check warning on line 228 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L228

Did you really mean 'backend's'?

## Token lifetime

- A session token is **single-use**: `start()` consumes it once to establish the conversation.
- A session token is valid for **about 5 minutes** after creation. `expires_at` is the exact deadline for the client to connect.
- A session token belongs to **one conversation**. When that conversation ends, the token cannot start another.
- `join_url` carries the same token and has the same deadline.
- Until `expires_at`, anyone who has the token or the link can join that session. Treat both as secrets.
- Every call to `POST /v1/agent/sessions` creates a new session. Create it when the user starts the call, not ahead of time such as on page load.
- A session that no client joins before the deadline ends with status `failed` and end reason [`room_join_timeout`](/agents/monitor/conversation-history#status-and-end-reason). It is not billed. The status can read `pending` for a minute or two after the deadline.
- A session nobody has joined yet counts toward your concurrent lines for a short time after creation. Creating many sessions without joining them can return `429`.
- On network drops the SDK reconnects at the transport level; 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.

Expand Down Expand Up @@ -241,13 +265,13 @@

| Status | Meaning |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | A keyless (public-agent) request sent an override [public sessions don't accept](#overrides), or a `name`. |

Check warning on line 268 in agents/deploy/authenticated-sessions.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/authenticated-sessions.mdx#L268

Did you really mean 'keyless'?
| `401` | Invalid API key. A request with no `Authorization` header at all is treated as a public-agent request instead. |
| `402` | Quota exceeded. |
| `401` | Invalid API key. A request with no `Authorization` header at all is treated as a public-agent request instead. So is an empty key, such as an unset `$FISH_API_KEY`. |
| `402` | Out of credit: the account has no trial balance or API credit left. |
| `403` | Public-agent request rejected: the agent is not public, or the page's `Origin` is not on the allow-list. |
| `409` | Conflict: most commonly the agent has no published version yet. [Publish](/agents/deploy/versions-publishing) to resolve. |
| `422` | The request body failed validation: an unknown field, an unsupported `language` code, an invalid `timezone`, or an invalid dynamic variable. |
| `429` | Every [concurrent line](/agents/pricing#concurrent-calls) of the team is in use (the code `concurrency_limit_exceeded`, with `retry_after`), or a public-agent request exceeded the per-agent or per-IP rate limit. |
| `429` | Every [concurrent line](/agents/pricing#concurrent-calls) of the team is in use (the code `concurrency_limit_exceeded`, with `retry_after`), or a public-agent request exceeded the per-agent or per-IP rate limit. See [Billing and rate limits](/api-reference/agent-errors#billing-and-rate-limits). |

The complete status-code reference for every `/v1/agent` endpoint (error shapes, `400` vs `422`, conflict semantics) is on [Agents API errors](/api-reference/agent-errors).

Expand Down
10 changes: 8 additions & 2 deletions agents/deploy/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: "Deploy Your Voice Agent"
sidebarTitle: "Overview"
description: "Choose where users meet your agent and who may start sessions: widget, SDKs, or phone; public or authenticated"

Check warning on line 4 in agents/deploy/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/overview.mdx#L4

Did you really mean 'SDKs'?
icon: "plug"
---

Your agent is one artifact with many front doors. Deploying it is two independent decisions:

1. **Where users meet your agent**: a prebuilt widget, your own UI built on the SDKs, a phone number, or a custom client.

Check warning on line 10 in agents/deploy/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/overview.mdx#L10

Did you really mean 'SDKs'?
2. **Who may start sessions**: anyone visiting your pages, or only clients your backend has vouched for.

Every surface runs the same agent with the same published configuration, and the browser surfaces work with either access mode.
Expand Down Expand Up @@ -48,7 +48,7 @@

## Who may start sessions

The widget and the SDKs each work with **either** access mode; pick per agent. Phone numbers skip this decision entirely: inbound calls connect through [telephony](/agents/telephony/inbound-calls), not a browser session.

Check warning on line 51 in agents/deploy/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/overview.mdx#L51

Did you really mean 'SDKs'?

<CardGroup cols={2}>
<Card title="Public agents" icon="globe" href="/agents/deploy/public-agents">
Expand Down Expand Up @@ -83,7 +83,7 @@
| A ready-made call button in a React Native app | [React Native widget](/agents/deploy/react-native-widget) |
| A phone line callers dial in to | [Phone numbers](/agents/telephony/phone-numbers) and [transfers](/agents/telephony/transfers) |
| Server-side session creation and history retrieval | [Authenticated sessions](/agents/deploy/authenticated-sessions) and [conversation history](/agents/monitor/conversation-history) |
| A client on a stack the SDKs don't cover | [Wire protocol](/agents/deploy/protocol) |

Check warning on line 86 in agents/deploy/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/overview.mdx#L86

Did you really mean 'SDKs'?

## How a browser session starts

Expand All @@ -100,10 +100,16 @@
```javascript Your frontend
import { AgentSession } from "@fishaudio/agent-client";

// sessionToken = the create-session response, passed through unchanged
const session = await AgentSession.start({ sessionToken });
// Your backend route runs the request above and returns the response.
const response = await fetch("/api/voice-session", { method: "POST" });
if (!response.ok) throw new Error(`Could not create a session (HTTP ${response.status})`);

// Pass the response through unchanged.
const session = await AgentSession.start({ sessionToken: await response.json() });
```

Create the session when the user starts the call: the token is valid for about 5 minutes and starts one conversation. To try a session without a frontend, open the `join_url` from the response in your browser. See [Token lifetime](/agents/deploy/authenticated-sessions#token-lifetime).

<Tip>
Agents marked [public](/agents/deploy/public-agents) skip the backend step
entirely: the SDK connects with just an `agentId`.
Expand Down
11 changes: 8 additions & 3 deletions agents/deploy/protocol.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: "Voice Agents Wire Protocol"
sidebarTitle: "Wire Protocol"
description: "The realtime message contract between clients and agent sessions, for platforms the SDKs don't cover"

Check warning on line 4 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L4

Did you really mean 'realtime'?

Check warning on line 4 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L4

Did you really mean 'SDKs'?
icon: "network-wired"
---

Everything the SDKs do rides a small, versioned wire protocol: two JSON message channels, plus the transport's standard transcription and state mechanisms. The transport is WebRTC, built on LiveKit: audio travels as WebRTC [media tracks](https://docs.livekit.io/home/client/tracks/), the message channels ride LiveKit's reliable [data channels](https://docs.livekit.io/home/client/data/messages/), and any platform with a [LiveKit client SDK](https://docs.livekit.io/home/client/connect/) can implement it. This page documents that contract for consumers that cannot use the SDKs: custom native stacks or ports to new platforms.

Check warning on line 8 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L8

Did you really mean 'SDKs'?

Check warning on line 8 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L8

Did you really mean 'SDKs'?

<Note>
This is an escape hatch. For web and React apps, use the [Web
Expand All @@ -16,7 +16,7 @@

## The protocol package

Every message shape on this page is published as TypeScript definitions in `@fishaudio/agent-protocol`, with zero runtime dependencies. This page documents the protocol as of package version **0.1.0**. The package is the source of truth for shapes; this page fixes the semantics.
Every message shape on this page is published as TypeScript definitions in `@fishaudio/agent-protocol`, with zero runtime dependencies. This page documents the protocol as of package version **1.0.0**. The package is the source of truth for shapes; this page fixes the semantics.

```bash npm
npm install @fishaudio/agent-protocol
Expand All @@ -40,12 +40,17 @@
"max_duration_seconds": 1800,
"transport": "livekit",
"livekit_url": "wss://...",
"token": "<participant JWT>"
"token": "<participant JWT>",
"join_url": "https://fish.audio/agents/join/#..."
}
```

The response is a discriminated union on `transport`. The `livekit` arm carries `livekit_url` and `token`: [connect](https://docs.livekit.io/home/client/connect/) a LiveKit-compatible WebRTC client with them before `expires_at` (the join deadline), then [publish your microphone track and subscribe](https://docs.livekit.io/home/client/tracks/) to the agent's audio track.

- `expires_at` is about 5 minutes after creation, and the token is for this one session. See [Token lifetime](/agents/deploy/authenticated-sessions#token-lifetime).
- Check for a `201` before you read the body. An error response has no `transport`.
- `join_url` opens the same session in a browser. Use it to hear the agent before your client is ready. A custom client ignores it.

<Warning>
If you receive a `transport` value you don't recognize, fail with an explicit
"unsupported transport" error. New transport arms may be introduced, each
Expand Down Expand Up @@ -173,7 +178,7 @@
{ "type": "session.ended", "reason": "conversation_timeout" }
```

Sent once, right before the server ends the call (before the agent leaves the room or the room is deleted), so a client learns the cause instead of inferring it from the disconnect. `reason` is `user_hangup` (the user hung up, or a backend ended the session through the API), `agent_hangup` (the agent hung up or the workflow reached an end node), `conversation_timeout` (the session reached its maximum duration), `escalated` (the call was transferred to a human), or `internal_error` (from 1.0.0: the runtime itself failed and closed the session, for example its process was stopped for exceeding its memory limit). The values match `end_reason` on the [session record](/agents/monitor/conversation-history#status-and-end-reason); treat the set as open, per the [compatibility rules](#compatibility-rules). A call that drops without this message has no announced reason: the SDKs report `connection_lost` once reconnection fails.
Sent once, right before the server ends the call (before the agent leaves the room or the room is deleted), so a client learns the cause instead of inferring it from the disconnect. `reason` is `user_hangup` (the user hung up, or a backend ended the session through the API), `agent_hangup` (the agent hung up or the workflow reached an end node), `conversation_timeout` (the session reached its maximum duration), `escalated` (the call was transferred to a human), `llm_endpoint_failure` (from 0.4.0: a [custom LLM](/agents/build/custom-llm) failed repeatedly and the agent hung up), or `internal_error` (from 1.0.0: the runtime itself failed and closed the session, for example its process was stopped for exceeding its memory limit). The values match `end_reason` on the [session record](/agents/monitor/conversation-history#status-and-end-reason); treat the set as open, per the [compatibility rules](#compatibility-rules). A call that drops without this message has no announced reason: the SDKs report `connection_lost` once reconnection fails.

Check warning on line 181 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L181

Did you really mean 'SDKs'?

## Client events: `client-event`

Expand Down Expand Up @@ -211,7 +216,7 @@
- Agent segments stream incrementally, paced to audio playback. An interrupted segment closes containing only the words actually spoken; there is no residual text.
- User segments are interim until final; each interim update **replaces the entire segment text** under the same segment id.

**Agent state** is published as the sticky `lk.agent.state` [participant attribute](https://docs.livekit.io/home/client/state/participant-attributes/) with values `initializing`, `idle`, `listening`, `thinking`, and `speaking`. Sticky means a client that connects late or reconnects reads the current value immediately. The SDKs derive their three public modes from this attribute plus transcript segment open/close.

Check warning on line 219 in agents/deploy/protocol.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/protocol.mdx#L219

Did you really mean 'SDKs'?

## Compatibility rules

Expand Down
4 changes: 3 additions & 1 deletion agents/deploy/public-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

The response is the same session token an authenticated request returns. The SDK consumes it internally. Everything else (events, methods, client tools) works exactly as in the [Web SDK](/agents/deploy/web-sdk).

If you run the curl request yourself, open the `join_url` from the response in your browser to talk to the agent. The token is valid for about 5 minutes and starts one conversation: see [Token lifetime](/agents/deploy/authenticated-sessions#token-lifetime).

## Restrict origins

By default, any website can start sessions on a public agent. To limit that to your own sites, turn on **Restrict origins** on the **Deploy** page and add each web origin that may start sessions (`restrict_origins` and `allowed_origins` in the API). A request whose `Origin` doesn't match any entry is then rejected with `403`.
Expand All @@ -65,7 +67,7 @@

An entry matches only on **exact scheme + host + port**. The host is case-insensitive, and a trailing slash on an entry is tolerated.

| Allowlist entry | Browser origin | Allowed |

Check warning on line 70 in agents/deploy/public-agents.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/public-agents.mdx#L70

Did you really mean 'Allowlist'?
| ------------------------- | ------------------------------ | ------------------------------ |
| `https://app.example.com` | `https://app.example.com` | Yes |
| `https://app.example.com` | `https://APP.example.com` | Yes (host is case-insensitive) |
Expand Down Expand Up @@ -93,11 +95,11 @@
backend becomes the gate, and the platform-side public limits no longer apply.
</Note>

## Treat public input as untrusted

Check warning on line 98 in agents/deploy/public-agents.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/public-agents.mdx#L98

Did you really mean 'untrusted'?

On the public path, the entire session request originates in the visitor's browser. The platform enforces its own guardrails (public sessions accept only the `language` and `voice_id` [overrides](/agents/deploy/authenticated-sessions#overrides), rejecting everything else with `400`), but anything that passes through verbatim is attacker-controllable:

- **`metadata`** is stored and returned exactly as sent, never interpreted by the platform. When you read it back in [conversation history](/agents/monitor/conversation-history) or [webhooks](/agents/monitor/webhooks), treat it as untrusted data, never as proof of who the visitor is.

Check warning on line 102 in agents/deploy/public-agents.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

agents/deploy/public-agents.mdx#L102

Did you really mean 'untrusted'?
- **`dynamic_variables`** are chosen by the page that starts the session. Don't inject anything through them that the visitor shouldn't control. See [Dynamic variables](/agents/build/dynamic-variables).

For trusted attribution (a verified `end_user_id`, server-set metadata), create sessions from your backend instead.
Expand All @@ -110,7 +112,7 @@
| ------------------------ | -------------------------------------------------------------------------- |
| `agent_not_public` | The agent's public switch is off. |
| `origin_forbidden` | The agent restricts origins and the page's origin is not in `allowed_origins` (HTTP `403`). |
| `insufficient_credit` | The agent owner's account has no Agent credit left (HTTP `402`). Top up to resume. |
| `insufficient_credit` | The agent owner's account has no trial balance or API credit left (HTTP `402`). Top up to resume. |
| `session_request_failed` | Other creation failures, for example the agent has no published version. |

## When to use session tokens instead
Expand Down
Loading
Loading