Skip to main content

Authentication

Manage user authentication, access tokens, and secure sessions with the Account API.

Authentication Methods

Cerevox supports two authentication methods:

API Key (Recommended)

Best for: Server-side applications, scripts, automation
Get API key: cerevox.ai

OAuth Tokens

Best for: User-facing applications, mobile apps, web apps
Use case: Multi-user applications

OAuth Authentication Flow

1. Login

Response fields:
  • 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 expires
  • token_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)

After revoking, the access token can no longer be used for API requests.

Complete Authentication Flow

Secure Token Storage

Never store tokens in:
  • Source code
  • Version control (git)
  • Client-side storage (localStorage, cookies without security)
  • Plain text files

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

Refresh tokens before they expire:
Prevents failed requests due to expiry
Never hardcode credentials!
Always provide logout functionality:
Prevents unauthorized access after user leaves
Gracefully handle expired refresh tokens

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