Overview
Databuddy API supports two authentication methods:- API Keys - For programmatic access (recommended)
- Session Cookies - For browser-based requests
API Key Authentication
Creating an API Key
API keys are created in the Databuddy dashboard:- Navigate to Organization → API Keys
- Click Create API Key
- Select the appropriate scopes
- Copy the key securely (it’s shown only once)
API Key Format
Databuddy API keys use the following format:dbdy_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4
Sending API Keys
There are two ways to authenticate with an API key:Method 1: x-api-key Header (Recommended)
Method 2: Bearer Token
API Key Scopes
API keys must be granted specific scopes to access different resources:Read access to analytics data. Required for querying websites and executing analytics queries.
Write access to LLM analytics data. Required for tracking LLM usage and costs.
Permission to track events. Required for ingesting analytics events.
Read access to short links. Required for listing and retrieving link data.
Create, update, and delete short links.
Resource-Level Scopes
API keys can be scoped to specific resources:- Global access - Access all resources in the organization
- Website-specific - Access only specified websites
API Key Management
Key Properties
Unique identifier for the API key
Human-readable name for the key
Array of granted scopes (e.g.,
["read:data", "write:links"])Whether the key is currently active
Expiration date (ISO 8601 format). Null for keys that don’t expire.
Revocation date. Null if the key hasn’t been revoked.
Organization the key belongs to
Key Validation
API keys are validated on each request:- Format check - Must start with
dbdy_and be 10-200 characters - Hash lookup - Key is hashed (SHA-256) and looked up in the database
- Status check - Key must be enabled, not revoked, and not expired
- Scope check - Request must match the key’s granted scopes
/packages/api-keys/src/resolve.ts:63-79.
Caching
API keys are cached for 60 seconds with stale-while-revalidate:- Cache duration: 60 seconds
- Stale time: 30 seconds
- Keys are cached by hash to optimize lookup performance
/packages/api-keys/src/resolve.ts:21-34.
Session Authentication
For browser-based requests, Databuddy uses session cookies. Session authentication:- Does not require scopes
- Access is determined by organization membership and role
- Sessions are automatically managed by the dashboard
Security Best Practices
Key Storage
- Store keys in environment variables
- Use a secrets manager (e.g., AWS Secrets Manager, HashiCorp Vault)
- Rotate keys periodically
Key Rotation
- Create a new API key with the same scopes
- Update your application to use the new key
- Revoke the old key after verifying the new one works
Monitoring
- Monitor API key usage in the dashboard
- Set up alerts for unusual activity
- Review access logs regularly