Overview
The Composite Analytics API uses API keys to authenticate requests. You can view and manage your API keys in the Analytics Dashboard. There are two types of API keys:Start with
pk_ and are safe to use in client-side code (browsers, mobile apps)Start with
sk_ and should only be used in server-side applicationsAuthentication Methods
SDK Authentication
The easiest way to authenticate is using the Composite SDK:HTTP Header Authentication
For direct API calls, include your API key in theAuthorization header:
Query Parameter Authentication
As an alternative, you can pass the API key as a query parameter:Header authentication is preferred over query parameters for security reasons, as query parameters may be logged in server access logs.
API Key Types
Public Keys (pk_)
Public keys have limited permissions suitable for client-side use:
| Permission | Allowed |
|---|---|
| Send events | ✅ |
| Send session recordings | ✅ |
| Identify users | ✅ |
| Read own user profile | ✅ |
| Read project configuration | ✅ |
| Access admin endpoints | ❌ |
| Read other users’ data | ❌ |
| Modify project settings | ❌ |
Secret Keys (sk_)
Secret keys have full API access:
| Permission | Allowed |
|---|---|
| All public key permissions | ✅ |
| Read all events | ✅ |
| Read all users | ✅ |
| Export data | ✅ |
| Modify project settings | ✅ |
| Manage team members | ✅ |
| Access billing | ✅ |
| Delete data | ✅ |
API Key Management
Creating API Keys
- Log in to the Analytics Dashboard
- Navigate to Settings → API Keys
- Click “Create New Key”
- Choose key type (Public or Secret)
- Add a descriptive label
- Set permissions (for secret keys)
- Copy the key immediately (it won’t be shown again)
Key Rotation
Regularly rotate your API keys for security:1
Create new key
Generate a replacement key in the dashboard
2
Update applications
Deploy your applications with the new key
3
Verify functionality
Confirm all services are using the new key
4
Revoke old key
Delete the old key from the dashboard
Revoking Keys
To immediately revoke a key:Environment Configuration
Development vs Production
Use different keys for different environments:Environment Variables
Store API keys in environment variables:CI/CD Configuration
Configure keys in your CI/CD pipeline:- GitHub Actions
- Vercel
- Netlify
- Docker
Rate Limiting
API keys are subject to rate limits:| Key Type | Requests/Second | Requests/Day | Burst Limit |
|---|---|---|---|
| Public | 100 | 1,000,000 | 1,000 |
| Secret | 1,000 | 10,000,000 | 10,000 |
Rate Limit Headers
The API returns rate limit information in response headers:Handling Rate Limits
Implement exponential backoff when rate limited:Security Best Practices
Use Environment Variables
Never hardcode API keys in your source code
Rotate Keys Regularly
Change your API keys every 90 days
Limit Key Permissions
Use public keys when possible, limit secret key scope
Monitor Key Usage
Track API key usage in the dashboard
Security Checklist
- Store keys in environment variables
- Use public keys in client-side code
- Keep secret keys on secure servers only
- Rotate keys regularly
- Monitor for unusual API activity
- Use HTTPS for all API calls
- Implement proper error handling
- Never log API keys
OAuth 2.0 (Coming Soon)
We’re working on OAuth 2.0 support for more secure third-party integrations:Troubleshooting
401 Unauthorized Error
401 Unauthorized Error
403 Forbidden Error
403 Forbidden Error
Your API key doesn’t have permission for this operation:
- Public keys cannot access admin endpoints
- Check the key’s permission settings in the dashboard
- Use a secret key for server-side operations
429 Too Many Requests
429 Too Many Requests
You’ve exceeded the rate limit:
- Implement exponential backoff
- Batch your requests when possible
- Consider upgrading your plan for higher limits
- Check the Retry-After header for when to retry
API Key Not Working in Production
API Key Not Working in Production
Common issues and solutions:
- Ensure environment variables are set in production
- Check for typos or extra whitespace in the key
- Verify the key is for the correct environment (test vs live)
- Confirm the key has the necessary permissions
API Key Scopes
When creating secret keys, you can limit their scope:| Scope | Description |
|---|---|
events:write | Send events and session data |
events:read | Read events and sessions |
users:write | Create and update user profiles |
users:read | Read user profiles |
projects:write | Modify project settings |
projects:read | Read project configuration |
team:write | Manage team members |
billing:read | View billing information |
billing:write | Modify billing settings |