Skip to main content
The SDK authenticates with a session token that your backend mints. Your organization API key stays on your server and never reaches a browser.
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

Because the session carries identity, the browser sends nothing but an 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

While refresh_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.
Don’t run your own refresh loop alongside onRefresh. Refresh tokens are single-use, so two refreshers race and one will present a token the other already spent — which revokes the session.

Persisting across reloads

onRefresh hands you an object that is itself a valid auth, so restoring it is just a spread:
Use sessionStorage, not localStorage. Refresh tokens are single-use, so two tabs sharing one pair means one eventually presents a token the other already spent — and the API revokes the session for both.
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:
This is also how you change who the user is: identity lives in the session, so mint a session for the new user and pass it here. Only copilotId is init-only.

Helpers

Session tokens replaced the old browser-side credential in v2.0.124. The identity fields are gone from initSidenet():