Authentication
HeroBrain uses a secure, token-based authentication system. All API requests must include valid authentication credentials.Overview
HeroBrain supports two authentication methods:- API Keys - For programmatic access and server-side applications
- Clerk JWTs - For authenticated user requests from client applications
API Key Authentication
Creating API Keys
API keys are created through the HeroBrain dashboard or API.Via Dashboard
- Sign in to herobrain.ai
- Navigate to API Platform → API Keys
- Click “Create API Key”
- Configure:
- Name: Descriptive name (e.g., “Production API Key”)
- Environment:
developmentorproduction - Scopes: Permissions for the key
- Click Create
- ⚠️ Copy the key immediately - it won’t be shown again
Via API
Using API Keys
Include your API key in theAuthorization header:
Example Request
API Key Scopes
| Scope | Description | Example Endpoints |
|---|---|---|
read:memories | Read memories and search | GET /memories, POST /memories/search |
write:memories | Create, update, delete memories | POST /memories, PATCH /memories/:id, DELETE /memories/:id |
read:intelligence | Access intelligence features | POST /intelligence/* |
write:webhooks | Manage webhooks | POST /webhooks, DELETE /webhooks/:id |
API Key Security
Best Practices
- Use environment-specific keys: Create separate keys for development and production
- Limit scopes: Only grant necessary permissions
- Rotate regularly: Create new keys and revoke old ones
- Monitor usage: Check API key usage in the dashboard
- Store securely: Use environment variables or secure key management systems
Environment Variables
Managing API Keys
List API Keys
Revoke an API Key
Monitor Usage
Clerk JWT Authentication
Overview
For client-side applications where users are authenticated via Clerk, you can use Clerk JWT tokens directly with HeroBrain APIs.Client-Side Authentication Flow
Server-Side Authentication (Next.js API Routes)
Rate Limiting
Limits by Plan
| Plan | Requests/Month | Requests/Minute | Burst Limit |
|---|---|---|---|
| Free | 1,000 | 10 | 20 |
| Pro | 100,000 | 100 | 200 |
| Enterprise | Custom | Custom | Custom |
Rate Limit Headers
All API responses include rate limit information:Handling Rate Limits
Security Best Practices
API Key Security
- Never commit API keys to version control
- Use environment variables in production
- Rotate keys regularly (recommended: monthly)
- Monitor key usage for suspicious activity
- Use different keys for different environments
Environment-Specific Keys
Key Rotation Strategy
Testing Authentication
Test API Key
Test Clerk JWT
Troubleshooting
Common Authentication Errors
401 Unauthorized
- Check that the
Authorizationheader is present - Verify the API key format:
Bearer hb_... - Ensure the key hasn’t expired
403 Forbidden
- Verify the
tenantIdmatches the API key’s tenant - Check that you’re using the correct tenant ID for your account
429 Too Many Requests
- Check the
X-RateLimit-Retry-Afterheader - Implement exponential backoff
- Consider upgrading your plan
Debugging Authentication
Check API Key Validity
Validate JWT Token
Test Token with API
Support
If you’re having authentication issues:- Check the API status: https://status.herobrain.ai
- Review your code: Ensure correct header format
- Verify your keys: Check expiration and scopes
- Contact support: [email protected] with your request ID