API Token Types
Dub supports two types of API tokens:1. Workspace API Tokens (Recommended)
Workspace API tokens are scoped to a specific workspace and provide granular access control through scopes.- Start with the prefix
dub_ - Scoped to a single workspace
- Support fine-grained permissions via scopes
- Can be set to expire automatically
- Rate limits based on your workspace plan
2. Legacy Personal API Keys
Personal API keys are older tokens that are being phased out.Creating an API Token
- Navigate to your workspace settings
- Go to the API section
- Click “Create Token”
- Select the appropriate scopes for your use case
- (Optional) Set an expiration date
- Copy and securely store your token
Using Your API Token
Include your API token in theAuthorization header using the Bearer authentication scheme:
Authorization Header Format
TheAuthorization header must follow this exact format:
Token Scopes
Workspace API tokens support granular permission scopes to limit what actions a token can perform. Common scopes include:links.read- Read link datalinks.write- Create and update linksanalytics.read- Access analytics datadomains.read- Read domain informationdomains.write- Manage domains
Token Security Best Practices
- Store securely: Use environment variables or secure secret management systems
- Rotate regularly: Periodically rotate your tokens, especially if they may have been exposed
- Use expiration: Set expiration dates on tokens when possible
- Scope appropriately: Only grant the minimum scopes required
- Monitor usage: Regularly review token usage in your workspace settings
Token Expiration
Tokens can be configured to expire automatically. When a token expires:- API requests will return a
401 Unauthorizederror - The error message will indicate: “Unauthorized: Access token expired.”
- You’ll need to create a new token to continue making API requests
Authentication Errors
Missing Authorization Header
Status Code:401 Unauthorized
Invalid API Token
Status Code:401 Unauthorized
Expired Token
Status Code:401 Unauthorized
Misconfigured Header
Status Code:400 Bad Request
Workspace Identification
When using workspace API tokens (tokens starting withdub_), you must identify which workspace the request is for:
The workspace ID associated with a token is verified during authentication. Tokens can only access resources within their associated workspace.