Overview
BYOI lets you identify your users inside a Thesys-published agent. Instead of requiring end-users to create a Thesys account, you sign a lightweight JWT on your backend and pass it to the embedded agent. Thesys verifies the signature and scopes every conversation to the user ID you provide. What you get:- Per-user conversation history — no Thesys login required
- Full control over user identification
- Works with both the embed widget and direct iframe embedding
- Automatic token refresh when JWTs expire mid-session
Quick Setup
Generate your Identity Secret
Sign a JWT on your backend
| Claim | Type | Required | Description |
|---|---|---|---|
externalUserId | string | Yes | Your app’s unique user identifier |
exp | number | Recommended | Expiration timestamp (Unix seconds) |
Pass the token to the agent
- Embed Widget (Recommended)
- Direct iframe
identityToken for the initial token and getIdentityToken for automatic refresh on expiry:getIdentityToken callback, gets a fresh token, and retries the failed request seamlessly.The widget supports three display modes: tray (default), full-screen, and chatbar.Automatic Token Refresh
When a JWT expires during an active conversation, the Thesys agent automatically requests a fresh token from the parent window usingpostMessage. If a new token is provided, the failed request is retried seamlessly — the user never sees an error.
How it works
Embed Widget
If you’re using the embed widget, token refresh is handled automatically — just provide thegetIdentityToken callback as shown in Step 3 above. No additional setup needed.
Direct iframe
For direct iframe embeds, add amessage event listener on your parent page:
PostMessage Protocol
| Direction | Message Type | Payload |
|---|---|---|
| iframe → parent | THESYS_IDENTITY_TOKEN_REFRESH_NEEDED | (none) |
| parent → iframe | THESYS_IDENTITY_TOKEN_REFRESHED | { identityToken: string } |
How It Works Under the Hood
- Thesys verifies the JWT signature using your Identity Secret (HS256)
- The
externalUserIdclaim is extracted and used to scope conversations - Each unique
externalUserIdgets its own isolated conversation history - If no identity token is provided, users are anonymous (session-based)
- If a user is logged into Thesys and has an identity token, the identity token takes priority
Secret Rotation
If you need to rotate your Identity Secret:- Click Rotate Secret in the BYOI section of the publish panel
- Copy the new secret to your backend environment
- Redeploy your backend
Token Errors
| Error | Cause | Resolution |
|---|---|---|
| Session Expired | JWT exp has passed | Handled automatically if token refresh is configured; otherwise the user must refresh the page |
| Authentication Failed | Signature doesn’t match (secret was rotated?) | Ensure your backend uses the current Identity Secret |
| Invalid Identity Token | Missing externalUserId claim | Add the required claim to your JWT payload |
| Identity Not Configured | No secret has been generated | Generate a secret in the publish panel |
FAQ
Do I need to re-publish my agent after generating or rotating the secret?
Do I need to re-publish my agent after generating or rotating the secret?
Can I use the same secret across multiple agents?
Can I use the same secret across multiple agents?
What JWT algorithm is supported?
What JWT algorithm is supported?
Is there a token size limit?
Is there a token size limit?
externalUserId and exp are read by Thesys.Can I add custom claims to the JWT?
Can I add custom claims to the JWT?
externalUserId and exp. Extra claims are ignored.What happens if I don't set up token refresh?
What happens if I don't set up token refresh?
Does BYOI work with the chatbar widget type?
Does BYOI work with the chatbar widget type?
tray, full-screen, and chatbar.