Authentication
Avatarium uses API keys and JWT tokens for authentication. This guide explains how to authenticate your requests.
Authentication Methods
| Method | Use Case | Format |
|---|---|---|
| API Key | Direct REST API access | Authorization: Bearer av_live_xxxxx |
| JWT Token | Dashboard users & consumer platform | Authorization: Bearer <jwt> |
API Keys
API keys are the primary authentication method for SDK and direct API access.
Key Format
av_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
av_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxav_live_prefix: Production keysav_test_prefix: Test/development keys (sandbox mode)
Creating an API Key
- Sign in to the Dashboard (opens in a new tab)
- Navigate to Settings > API Keys
- Click Create API Key
- Give it a descriptive name (e.g., "Production Website")
- Copy the key immediately - it won't be shown again
⚠️
API keys are shown only once at creation. Store them securely and never share them.
Using API Keys
import { AvatariumEmbed } from '@avatarium/react';
// Note: AvatariumEmbed uses iframe embedding (no API key required in component)
// Use your Short ID from the dashboard, not an API key
<AvatariumEmbed
shortId="YOUR_SHORT_ID"
mode="voice"
/>API Key Permissions
API keys have full access to:
- Create and manage conversations
- Send messages and receive responses
- Access avatar information
- TTS synthesis endpoints
Currently, all API keys have full permissions. Scoped permissions (read-only, specific endpoints) are coming soon.
JWT Authentication (Dashboard)
Dashboard users authenticate via Firebase JWT tokens. This is used internally by the dashboard application.
How It Works
- User signs in via Google OAuth
- Firebase issues a JWT token
- Token is sent with each API request
- API verifies token signature against Firebase JWKS
Token Validation
The API validates:
- Signature: Verified against Firebase's public keys (JWKS)
- Issuer: Must be
https://securetoken.google.com/<project-id> - Audience: Must match the Firebase project ID
- Expiration: Token must not be expired
Example JWT Claims
{
"iss": "https://securetoken.google.com/avatarium-prod",
"aud": "avatarium-prod",
"sub": "abc123",
"user_id": "abc123",
"email": "user@example.com",
"email_verified": true,
"exp": 1705312800,
"iat": 1705309200
}Security Best Practices
Do
- Store API keys in environment variables
- Use different keys for development and production
- Rotate keys periodically
- Use server-side proxies for sensitive operations
- Monitor key usage in the dashboard
Don't
- Commit API keys to git repositories
- Expose keys in client-side JavaScript (unless using NEXT_PUBLIC_ pattern)
- Share keys across different applications
- Use production keys in development
Environment Variable Example
.env.local
# Never commit this file to git
NEXT_PUBLIC_AVATARIUM_KEY=av_live_xxxxx
AVATARIUM_SECRET_KEY=av_live_yyyyy # Server-side onlyapp/page.tsx
// Client-side (visible to users)
<Avatar apiKey={process.env.NEXT_PUBLIC_AVATARIUM_KEY} />app/api/avatar/route.ts
// Server-side (hidden from users)
const response = await fetch('https://api.avatarium.ai/v1/...', {
headers: {
'Authorization': `Bearer ${process.env.AVATARIUM_SECRET_KEY}`
}
});Rate Limiting by Auth Type
| Auth Type | Rate Limit | Burst |
|---|---|---|
| API Key (Free) | 10/min | 20 |
| API Key (Pro) | 300/min | 600 |
| JWT (Dashboard) | 60/min | 120 |
| Unauthenticated | 5/min | 10 |
Auth-Specific Rate Limits
Certain sensitive operations have additional limits:
| Operation | Limit | Window |
|---|---|---|
| Password verification | 5 attempts | 1 minute |
| Login attempts | 10 attempts | 1 minute |
| Account creation | 3 accounts | 5 minutes |
Error Responses
Invalid API Key
{
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid or has been revoked"
}
}Missing Authentication
{
"error": {
"code": "UNAUTHORIZED",
"message": "Authentication required. Provide an API key or JWT token."
}
}Expired Token
{
"error": {
"code": "TOKEN_EXPIRED",
"message": "Your authentication token has expired. Please sign in again."
}
}Troubleshooting
"Invalid API key" Error
- Verify the key hasn't been revoked in the dashboard
- Check for extra whitespace in the key
- Ensure you're using the correct environment (live vs test)
- Regenerate the key if issues persist
"401 Unauthorized" on First Request
- Confirm the
Authorizationheader is set correctly - Check the
Bearerprefix is included - Verify the key format (
av_live_orav_test_)
JWT Token Issues
- Ensure the user is signed in
- Check token expiration (tokens last 1 hour)
- Refresh the token if expired
- Verify Firebase configuration
Next Steps
- API Reference - Full endpoint documentation
- Error Codes - Complete error code reference
- BYOK Guide - Use your own AI provider keys