Overview
Tambo requires authentication to identify users and scope threads. You must provide either:userKey- A user identifier (server-side or trusted environments)userToken- An OAuth access token (client-side with token exchange)
Authentication Methods
userKey (Server-Side)
UseuserKey when you control user identity on the server:
- Server-rendered apps (Next.js App Router)
- Trusted environments where user ID is verified server-side
- Backend-controlled authentication
userToken (Client-Side)
UseuserToken with OAuth or JWT tokens:
- Client-side apps (SPA, React, Vite)
- OAuth providers (Auth0, Clerk, Firebase Auth)
- Token-based authentication
Authentication States
Monitor auth state withuseTamboAuthState():
Auth State Types
Thread Scoping
Threads are automatically scoped to the authenticated user:Token Exchange Flow
When usinguserToken, Tambo performs a token exchange:
- Client provides OAuth access token
- Tambo validates token with OAuth provider
- Tambo extracts user identity (sub, email, etc.)
- Tambo issues internal session token
- Client uses session token for API calls
Auth Warnings
TamboProvider emits console warnings for common auth issues:
Missing Authentication
userKey or userToken prop.
Invalid Configuration
userKey or userToken.
Token Exchange Error
Integration Examples
Next.js App Router
Server-side user identification:Clerk
OAuth token from Clerk:Auth0
OAuth token from Auth0:Firebase Auth
OAuth token from Firebase:MCP Authentication
MCP servers receive authentication automatically:Server-Side MCP
Tambo’s internal MCP server receives an access token automatically:Client-Side MCP
Pass auth headers to MCP servers:Security Best Practices
Never Expose API Keys
Validate Tokens Server-Side
When usinguserKey, verify the user is authenticated:
Use Short-Lived Tokens
Refresh tokens before expiry:Handle Unauthenticated State
Block UI when unauthenticated:Environment Variables
Required
Optional
Next Steps
- Learn about Threads and how they’re scoped to users
- Explore MCP authentication for external integrations
- See Streaming for real-time updates
- Check the API Reference for full provider options