Once the token route and Provider are wired and the agent can act, four things are worth knowing. None of them are extra setup. They're behaviours the runtime already has, and the shape of a larger integration. If your site is server-rendered, one opt-in keeps a conversation going across page loads. The last section is the escape hatch for when tokenUrl isn't enough: a custom getToken.
Multiple surfaces
Declare a useSurface on each route, next to the state that route already owns, not one global surface for the whole app. It's active only while its component is mounted, so as the user navigates the active surface swaps automatically and the agent always knows where they are and what's on screen:
// app/tasks/page.tsx
useSurface({ label: "Tasks board", data: { remaining } });
// app/settings/page.tsx
useSurface({ label: "Settings", data: { plan } });You name only the human label; the SDK derives a stable internal id from it, so there's nothing to keep unique across routes. Hang each route's elements and actions off the same component and they come and go with the surface. What should live on a route and what should live in a persistent layout is the first question on Patterns.
Session lifecycle
A voice session winds down on its own when no one's interacting, so an abandoned tab doesn't burn minutes: after about 45 seconds of no interaction it goes idle, and if nothing happens for roughly 120 seconds more, the session ends. This is automatic and not yours to manage; click the button again to start a fresh session. Don't build keep-alive logic around it. (Those are the defaults; the exact thresholds are set on our side, not a prop you configure.)
Server-rendered sites
On a single-page app the co-worker lives as long as the page does. On a server-rendered site (a storefront theme, a PHP, Rails or Django app) every click loads a new document, which would end the conversation. Add resume and it carries on:
<CoworkkitProvider tokenUrl="/api/coworkkit/session" resume>
{children}
</CoworkkitProvider>When the page is left, the session is kept for this tab; the next page rejoins it within a moment and the co-worker picks the thread up with that page's actions. It stays quiet while the page loads. A muted microphone stays muted.
Good to know: it works in the same tab only, so a link opened in a new tab starts fresh. A session can be resumed for up to 30 minutes after it started. After a page load some browsers need one tap to turn sound back on; the button shows it. And the co-worker must be told to wait for the next page: that waiting time is off by default, so ask us to enable it for your co-worker.
Minutes & metering
Voice is metered by the minute of live session, per coworker, against a prepaid balance you manage in the portal under Settings → Plan & Billing. The meter starts when the person joins the session, not when your route mints it: the seconds they spend on the browser’s microphone prompt aren’t counted, and a session nobody joins ends on its own after two minutes and costs nothing. You meter nothing in your own code to keep our balance — but if you want to re-bill or cap your own users, every session's minutes reach your backend through the sessions API and signed webhooks; see Usage, quotas & webhooks. There is no per-request accounting to reconcile: idle time past the cut above isn't billed because the session is already over.
- Running low: the account owner gets a low-balance email, and the portal shows a banner on the dashboard. Sessions keep starting.
- At zero: new sessions are refused at the token route. Your route relays an
out_of_creditreason and the button's ring says Out of credit to the user (every ring status). A session that is already running when the balance reaches zero is ended by the runtime at that point. Nothing in your app breaks; the button simply won't connect until the balance is topped up, which takes effect immediately. - Daily limit: each coworker has a daily session limit set by its plan; past it the ring says Line busy until the day rolls over. Ask us if you need more.
If you want your own copy in front of the user instead of the ring's, branch on the reason your route relays. The Backends page lists every value.
Testing your integration
useAction, useSurface, and useElement are ordinary React hooks, and the handlers you pass them are ordinary functions. Unit-test those handlers directly, with no agent in the loop. The hooks themselves no-op without a Provider, so a hook test only needs to assert what your app does, not the wire. To confirm the agent actually perceives your annotations end to end, use the Watch panel; its Catalogue tab is the ground truth for what's exposed.
Custom getToken
tokenUrl covers the common case: a same-origin route, called with the browser's own cookies. When you need more, such as a bearer header from your auth client, a cross-origin API, or an existing fetch wrapper, pass getToken instead: an async function that fetches the session itself. Pass one or the other, never both. This is the reference implementation; it makes the same request tokenUrl does:
<CoworkkitProvider
getToken={async (ctx) => {
const res = await fetch("/api/coworkkit/session", {
method: "POST",
headers: { "content-type": "application/json" /* add your auth header here */ },
body: JSON.stringify(ctx ?? {}),
});
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw Object.assign(new Error(body.error ?? "session mint failed"), {
reason: body.reason,
status: res.status,
});
}
return res.json(); // relay the session unchanged
}}
>The contract: return the route's response unchanged; on failure throw with reason and status so the FAB can say why (Out of credit, Setup needed, …) instead of a generic Can't connect.
ctx carries the same hints tokenUrl posts (the user's language and timeZone), so send it as the body and your route forwards them exactly as before. A function can't be passed from a Server Component, so a Provider with getToken lives in a client component ("use client"), such as your own Providers.