Authentication
Manage user authentication, access tokens, and secure sessions with the Account API.Authentication Methods
Cerevox supports two authentication methods:API Key (Recommended)
OAuth Tokens
Best for: User-facing applications, mobile apps, web appsUse case: Multi-user applications
OAuth Authentication Flow
1. Login
access_token: Short-lived token for API requests (1 hour)refresh_token: Long-lived token to get new access tokens (30 days)expires_in: Seconds until access token expirestoken_type: Token type (usually “Bearer”)
2. Use Access Token
3. Refresh Token
Access tokens expire after 1 hour. Refresh before expiry:4. Revoke Token (Logout)
Complete Authentication Flow
Secure Token Storage
Recommended: Environment Variables
Recommended: Secure Keyring
Server-Side Sessions
Error Handling
Token Lifecycle
1
Login
User provides credentials → Receive access + refresh tokens
2
Use Access Token
Include access token in API requests (valid for 1 hour)
3
Refresh Token
Before expiry, use refresh token to get new access token
4
Logout
Revoke access token when user logs out
Multi-User Application Example
Best Practices
Proactive Token Refresh
Proactive Token Refresh
Refresh tokens before they expire:Prevents failed requests due to expiry
Secure Credential Handling
Secure Credential Handling
Implement Logout
Implement Logout
Always provide logout functionality:Prevents unauthorized access after user leaves
Handle Token Refresh Failures
Handle Token Refresh Failures
Security Checklist
- Use HTTPS for all API requests
- Never commit API keys or tokens to version control
- Store tokens securely (keyring, encrypted storage)
- Implement token refresh before expiry
- Provide logout functionality
- Handle authentication errors gracefully
- Use environment variables for secrets
- Implement rate limiting on login endpoint
- Log authentication events for security monitoring
Next Steps
Usage Tracking
Monitor API usage and billing
Account Overview
Back to Account API overview

