Authentication
aiOla uses a secure two-tier authentication system that combines API keys with JWT access tokens. This approach provides both security and flexibility, allowing you to keep sensitive credentials on the backend while enabling frontend applications to make authenticated requests.
How Authentication Works
Overview
aiOla’s authentication flow follows this pattern:
- API Key Exchange: Your backend application uses an API key to request an access token
- Token Generation: aiOla’s authentication service returns a JWT access token
- API Requests: Your application uses the access token to make authenticated requests to aiOla services
Why This Architecture?
This two-tier system provides several key benefits:
🔐 Enhanced Security
- API Key Protection: Your sensitive API key never leaves your backend
- Token Rotation: Access tokens have limited lifespans and can be rotated regularly
- Principle of Least Privilege: Frontend applications only receive temporary access tokens
🏗️ Architectural Flexibility
- Frontend Freedom: Client applications can authenticate without exposing secrets
- Scalable Design: Generate tokens for multiple clients from a single API key
- Environment Separation: Different tokens for development, staging, and production
🛡️ Risk Mitigation
- Limited Exposure: If a token is compromised, it expires automatically
- Centralized Control: Revoke access by rotating the API key on your backend
- Audit Trail: Track token generation and usage patterns
Implementation Guide
Backend: Token Generation
Your backend is responsible for exchanging API keys for access tokens:
Frontend: Using Access Tokens
Once you have an access token, use it in the Authorization header:
Security Best Practices
API Key Management
Never expose your API key in frontend code or version control
✅ Do:
- Store API keys in environment variables
- Use secure secret management systems in production
- Rotate API keys regularly
- Limit API key access to necessary backend services only
❌ Don’t:
- Include API keys in frontend applications
- Commit API keys to version control
- Share API keys across environments
- Store API keys in plain text files
Token Handling
Backend Token Management
Frontend Token Management
Environment Configuration
Development Setup
Production Setup
For production deployments, consider:
Enterprise Endpoints
Enterprise Configuration
Error Handling
Common Authentication Errors
401 Unauthorized
Solutions:
- Verify token is included in Authorization header
- Check token format:
Bearer <token>
- Generate a new access token
403 Forbidden
Solutions:
- Verify API key has correct permissions
- Check if API key is active and not revoked
- Contact support for permission adjustments
FAQ
How long do access tokens last?
Access tokens typically last 30 minutes. The SDK handles token management internally, but you should implement refresh logic for long-running applications.
Can I use the same access token across multiple applications?
Yes, access tokens can be shared across applications, but consider security implications. For better isolation, generate separate tokens for different services.
What happens if my API key is compromised?
Immediately rotate your API key in the aiOla dashboard. All existing access tokens will become invalid, requiring new token generation.
Can I extend token lifetime?
Token lifetimes are fixed for security reasons. Implement automatic token refresh in your applications instead.
Do I need different API keys for different environments?
Yes, use separate API keys for development, staging, and production environments for better security and monitoring.
Next Steps
- STT Integration: Learn how to implement Speech-to-Text with authentication
- TTS Integration: Explore Text-to-Speech implementation patterns
- Streaming: Set up real-time streaming with proper authentication
- Quickstart: Follow our Quickstart Guide for a complete setup example
Need Help? If you encounter issues with authentication, contact our support team.