Overview
Plausible uses API key-based authentication. All API requests must include a valid API key as a Bearer token in theAuthorization header.
Creating an API Key
Navigate to API Keys settings
Go to your API Keys settings page in your Plausible account.
Create a new key
Click ”+ New API Key” and provide:
- Name: A descriptive name for the key (e.g., “Production Analytics Dashboard”)
- Team: Select which team this key should be scoped to
Choose scopes
The scope is automatically determined based on the key type:
- Stats API keys get
stats:read:*scope - Sites API keys get
sites:provision:*scope (Enterprise only)
Authentication Method
Include your API key in theAuthorization header as a Bearer token:
Example Request
API Key Types
Team-Scoped Keys
Modern API keys are scoped to a specific team:Characteristics:
- Bound to a single team
- Only works with sites owned by that team
- User must be a team member (guests cannot use team keys)
- Subject to team-based rate limits
- Generated with a 6-character prefix for identification
Legacy Keys (Deprecated)
Older API keys created before team-scoping:Characteristics:
- Work across all teams the user belongs to
- Can access sites where user is a guest
- Subject to user-based rate limits
- Cannot be created through the UI anymore
API Scopes and Permissions
stats:read:*
Default scope - Allows reading analytics dataPermissions
Permissions
- Query aggregate statistics
- Access breakdown reports
- Retrieve timeseries data
- View realtime visitor counts
- Read site metadata
sites:read:*
Read-only access to site configurationsPermissions
Permissions
- List all sites
- Get site details
- List goals
- List custom properties
- View site guests
- List teams
sites:provision:*
Full provisioning access - Requires Enterprise planPermissions
Permissions
- All
sites:read:*permissions - Create new sites
- Update site settings
- Delete sites
- Create and delete goals
- Manage custom properties
- Create shared links
- Invite and remove guests
The scopes use wildcard matching. For example, if an API key has
sites:* scope, it matches both sites:read:* and sites:provision:*.Authentication Errors
The API returns specific error messages for authentication failures:Missing API Key
401 Unauthorized
Cause: No Authorization header provided or header format is incorrect
Solution: Include the header as Authorization: Bearer YOUR_API_KEY
Invalid API Key
401 Unauthorized
Causes:
- API key doesn’t exist
- API key has been deleted
- Key is valid but doesn’t have access to the requested site
- Team-scoped key used for a site in a different team
Invalid API Key with Site Access
For Stats API requests:401 Unauthorized
Causes:
- Site ID doesn’t exist
- API key doesn’t have permission to access the site
- User is not a member of the site’s team
Insufficient Scope
401 Unauthorized
Cause: API key doesn’t have the required scope for the endpoint
Solution: Create a new API key with the appropriate scope or use a different key
Rate Limiting
API keys are subject to rate limits to ensure fair usage:Hourly Limit
Burst Limit
All keys are subject to a burst limit to prevent abuse:Rate Limit Errors
Hourly Limit Exceeded
429 Too Many Requests
Burst Limit Exceeded
429 Too Many Requests
Rate limits are enforced per team (for team-scoped keys) or per user (for legacy keys), not per API key. Multiple keys for the same team share the same rate limit.
Security Best Practices
Store keys securely
Store keys securely
- Never commit API keys to version control
- Use environment variables or secret management services
- Rotate keys periodically
- Delete unused keys immediately
Use team-scoped keys
Use team-scoped keys
- Create separate keys for each team
- Limit blast radius if a key is compromised
- Easier to track usage and manage access
Principle of least privilege
Principle of least privilege
- Only request the scopes you need
- Use
stats:read:*for read-only analytics access - Only use
sites:provision:*when you need write access
Monitor API usage
Monitor API usage
- Track which keys are being used
- Watch for unusual patterns
- Delete keys that haven’t been used in 90+ days
Troubleshooting
API key works in one environment but not another
API key works in one environment but not another
Problem: Key works locally but fails in productionCommon causes:
- Whitespace or newlines in the environment variable
- Key was copied incorrectly (missing characters)
- Using a different key than intended
Getting 401 errors despite valid key
Getting 401 errors despite valid key
Problem: Authentication fails even with correct API keyCommon causes:
- Team-scoped key used for site in different team
- User is a guest on the site (team keys require membership)
- Site was transferred to another team
Site locked or upgrade required errors
Site locked or upgrade required errors
Problem: Getting 402 Payment Required errorsCommon causes:
- Team subscription has lapsed
- Required feature not available on current plan
- Attempting to use Sites API without Enterprise plan
Implementation from Source
API key authentication is implemented in:- Key structure:
lib/plausible/auth/api_key.ex:44-58 - Authorization logic:
lib/plausible_web/plugs/authorize_public_api.ex:50-65 - Scope verification:
lib/plausible_web/plugs/authorize_public_api.ex:156-173 - Rate limiting:
lib/plausible_web/plugs/authorize_public_api.ex:187-214
For self-hosted instances, rate limits and some authentication behaviors can be configured via environment variables.