1
Your backend mints a session
Call
POST /v1/token with your organization API key. The session it returns already carries the organization, the user, and the billing group.2
Your page fetches it
Expose a small endpoint of your own that returns that response to the signed-in user.
3
The SDK takes it from there
Pass the response to
initSidenet({ auth }). The SDK refreshes it on its own for as long as the session lives.Minting the session
Authorization header — no org id, no user id.
user and billing_group are both required, and both are objects with a required id and an optional name. A changed name renames the user or group in Studio; omitting it never blanks one you sent before. Full schema in the API reference.The auth object
Automatic refresh
Whilerefresh_token is present the SDK keeps the session alive by itself: it refreshes ahead of expiry, and retries once if a request still comes back 401. The open conversation is never interrupted.
Persisting across reloads
onRefresh hands you an object that is itself a valid auth, so restoring it is just a spread:
Keep the
expiresAt that onRefresh includes. Re-deriving it from expires_in would treat a stale token as fresh, and the first request after a reload would 401.When it fails
onError fires once with a reason. What you do depends on fatal:
Swapping in a fresh session needs no teardown — it replaces the credential in place, as a unit, and the conversation on screen survives:
copilotId is init-only.
Helpers
Upgrading from v2.0.123 or earlier
Upgrading from v2.0.123 or earlier
Session tokens replaced the old browser-side credential in v2.0.124. The identity fields are gone from
initSidenet():