API Key Authentication
ContentStats.io uses API keys to authenticate requests. Include your API key in theX-API-Key header for every request.
Getting Your API Key
Access Dashboard
Go to Dashboard → API Keys
Key Formats
API keys come in two formats:| Environment | Prefix | Example |
|---|---|---|
| Production | cs_live_ | cs_live_sk_abc123... |
| Test | cs_test_ | cs_test_sk_xyz789... |
Test keys are for development only. They work with the API but don’t charge your account.
Using API Keys
Environment Variables
Recommended approach — store keys in environment variables:Request Headers
All API requests require:Authentication Errors
401 Unauthorized
Missing or invalid API key:X-API-Key header is present and correctly formatted.
403 Forbidden
Valid key but insufficient permissions:402 Payment Required
Insufficient balance:Security Best Practices
Never Expose Keys in Code
Never Expose Keys in Code
❌ Don’t do this:✅ Do this:
Don't Commit Keys to Git
Don't Commit Keys to Git
Add
.env to your .gitignore:.gitignore
Rotate Keys Regularly
Rotate Keys Regularly
Rotate API keys every 90 days or immediately if compromised:
- Create a new key
- Update your application
- Delete the old key
Use Server-Side Only
Use Server-Side Only
Never call the API from client-side JavaScript. Use a backend proxy:
Audit API Key Usage
Audit API Key Usage
Monitor your keys in the Dashboard:
- Last used timestamp
- Request count
- Associated resources
Managing Multiple Keys
You can create multiple API keys for:- Different environments (development, staging, production)
- Team members (track usage per person)
- Applications (separate keys per service)
Key Organization
Rate Limiting
API keys are subject to rate limits based on your plan:| Plan | Rate Limit |
|---|---|
| Free | 60 requests/minute |
| Pro | 300 requests/minute |
| Enterprise | Custom |
Rate limits are per API key. See Rate Limits for details.
Key Rotation Example
Testing Your Authentication
Verify your API key works:Success Response
Success Response
Compromised Key?
If your API key is exposed:- Delete it immediately in the Dashboard
- Create a new key
- Update your application
- Review usage logs for unauthorized activity
