Creating a personal API key
Navigate to your account settings
Go to your PostHog account settings and select the Personal API Keys section.
Create a new key
Click Create personal API key and give it a descriptive label (e.g., “Production automation”, “CI/CD pipeline”).
Using your API key
Include your API key in theAuthorization header using the Bearer token format:
Example requests
Authentication for different endpoints
Most API endpoints require authentication with a personal API key. However, some endpoints have different requirements:Authenticated endpoints
Require a personal API key in theAuthorization header:
/api/projects/- Project management/api/insights/- Insights and dashboards/api/feature_flags/- Feature flags/api/persons/- Person data/api/cohorts/- Cohorts/api/query/- HogQL queries
Public endpoints
Do not require authentication:/decide/- Feature flag evaluation (uses project token)/capture/- Event ingestion (uses project token)/batch/- Batch event ingestion (uses project token)
Event ingestion endpoints use your project token instead of a personal API key. Find your project token in Project Settings → Project Variables.
Authentication errors
401 Unauthorized
Your API key is missing or invalid:Authorization header.
403 Forbidden
Your API key is valid but lacks permission:Best practices
Use environment variables
Use environment variables
Store API keys in environment variables, not in your code:Then reference them in your application:
Create separate keys for different uses
Create separate keys for different uses
Use different API keys for:
- Development and testing
- Production automation
- CI/CD pipelines
- Third-party integrations
Rotate keys regularly
Rotate keys regularly
Create a new API key and delete the old one periodically (e.g., every 90 days) to minimize security risks.
Limit key exposure
Limit key exposure
- Never commit keys to version control
- Don’t share keys in Slack, email, or support tickets
- Use secret management tools in production (AWS Secrets Manager, HashiCorp Vault, etc.)
- Revoke keys immediately if they’re exposed
Revoking an API key
If an API key is compromised or no longer needed:- Go to Personal API Keys in your account settings
- Find the key you want to revoke
- Click Delete
- Confirm the deletion
401 Unauthorized.