The Sunny Agents SDK supports two authentication modes: custom token exchange and passwordless authentication. With createSunnyChat, all authentication configuration is server-driven — you only specify the auth type and the server provides the necessary details automatically.
For applications with custom authentication providers:
Features:
Email or SMS-based authentication without passwords. The SDK renders a verification UI directly in the chat:
Features:
When using createSunnyChat, auth configuration is fetched via HTTP from the /sdk/config endpoint before any WebSocket connection is established:
Token Exchange:
createSunnyChat with authType: "tokenExchange" — returns immediatelyGET /sdk/config to retrieve token exchange settings (background)idTokenProvider to get the ID tokenauth.upgrade message with access tokenauth.upgraded response — send button spinner becomes send arrowYou can switch the authentication type at runtime:
The SDK automatically refreshes tokens before they expire using a check-on-send strategy: before every outgoing message, the SDK checks the access token’s JWT exp claim and, if the token is within 5 minutes of expiry, requests a fresh ID token from your idTokenProvider, exchanges it for a new access token, and sends an auth.refresh message to the server — all before the user’s message is sent. No timers or background polling are involved; refresh only happens when the user is actively sending messages.
No action is needed from your app. If your idTokenProvider needs to force-refresh, you can do so per provider:
Auth0:
Firebase:
You can pre-populate user data (profile, address, insurance, and dependents) during authentication by passing authUpgradeProfileSync to createSunnyChat. This data is sent alongside the auth.upgrade message, so the user doesn’t need to re-enter information your application already has.
See the Profile Sync guide for full details on all supported data types including insurance and dependents.