Authentication
The GAIA API uses WorkOS session-based authentication. All API requests require a valid session token to be included in the request.Authentication Flow
GAIA supports multiple authentication flows for different platforms:Web Application (Default)
-
Initiate OAuth Flow
-
User Redirected to WorkOS
- User authenticates with WorkOS AuthKit
- Supports email/password, social logins, and SSO
-
OAuth Callback
-
Session Cookie Set
wos_sessioncookie is set with sealed session token- Cookie is httpOnly and secure in production
- Redirects to frontend with active session
Desktop Application
-
Initiate Desktop OAuth
-
Desktop Callback
Returns deep link redirect:
Mobile Application
-
Initiate Mobile OAuth
Response:
-
Mobile Callback
Returns deep link redirect:
Making Authenticated Requests
Using Cookie Header
Include the session token in theCookie header:
WebSocket Authentication
For WebSocket connections, authentication is handled differently:Browser/Desktop (Cookie-based)
Mobile (Protocol-based)
For mobile apps that cannot send cookies, use theSec-WebSocket-Protocol header:
Session Token Format
Session tokens are sealed (encrypted) JWT tokens containing:- user_id - Unique user identifier
- email - User’s email address
- name - User’s display name
- picture_url - User’s profile picture URL (optional)
Token Lifecycle
- Expiration: Session tokens expire based on WorkOS configuration (typically 7-30 days)
- Refresh: Tokens are automatically refreshed by the authentication middleware
- Revocation: Tokens can be revoked by logging out
Error Responses
401 Unauthorized
Returned when authentication is missing or invalid:- Missing
wos_sessioncookie - Expired session token
- Invalid or corrupted token
403 Forbidden
Returned when authenticated but not authorized:- Attempting to access another user’s resources
- Insufficient permissions for the operation
Security Best Practices
Store tokens securely
Store tokens securely
- Web: Rely on httpOnly cookies (automatically handled)
- Mobile: Use secure storage (Keychain on iOS, Keystore on Android)
- Desktop: Use secure credential storage
- Never store tokens in localStorage or sessionStorage
Use HTTPS
Use HTTPS
- Always use HTTPS in production
- Session cookies are marked
securein production - Prevents token interception via man-in-the-middle attacks
Handle token expiration
Handle token expiration
- Implement automatic re-authentication when receiving 401 errors
- Provide clear UI for users to re-authenticate
- Consider implementing token refresh logic
Logout properly
Logout properly
- Clear session cookies on logout
- Redirect to login page
- Invalidate any cached user data
Getting User Information
Authenticated requests automatically include user context. The API identifies the current user from the session token. User information is accessible via theget_current_user dependency:
Client ID Metadata (OAuth Discovery)
For MCP integrations using URL-formatted client IDs, GAIA provides an OAuth Client ID Metadata Document:This metadata document enables OAuth flows without pre-registration, following the draft-ietf-oauth-client-id-metadata-document specification.
Next Steps
Rate Limits
Understand rate limits and quotas
Make Your First Request
Start using the Chat API