API Authentication
The PayRequest API uses OAuth2 with Personal Access Tokens for authentication. All API requests must include a valid access token in theAuthorization header.
Creating an Access Token
Configure Token
- Enter a descriptive name (e.g., “MCP Billing Agent”)
- Select the scopes (permissions) your token needs
- Click Create
Using Your Token
Include the token in theAuthorization header of every API request:
OAuth Scopes
Scopes define what actions your token can perform. Request only the scopes you need for better security.Available Scopes
| Scope | Description | Use Case |
|---|---|---|
billing.read | Read invoices, subscriptions, transactions | Dashboards, reporting, monitoring |
billing.write | Create and modify invoices and subscriptions | Invoice automation, billing workflows |
billing.agent | Full AI billing agent access | MCP integrations, AI assistants |
customers.read | Read customer information | CRM integrations, customer lookup |
customers.write | Create and modify customers | Customer sync, onboarding automation |
products.read | Read product catalog | Catalog sync, price checks |
products.write | Create and modify products | Product management automation |
Default Scope
If you don’t specify scopes when creating a token, it will receive the defaultbilling.read scope.
Scope Inheritance
Thebilling.agent scope includes all capabilities of billing.read and billing.write, making it ideal for AI-powered billing assistants.
Token Expiration
| Token Type | Expiration |
|---|---|
| Personal Access Token | 6 months |
| Access Token | 15 days |
| Refresh Token | 30 days |
Tokens expire automatically for security. Plan to refresh or regenerate tokens before they expire.
Security Best Practices
Store tokens securely
Store tokens securely
- Never commit tokens to version control
- Use environment variables or secret management services
- Encrypt tokens at rest
Use minimal scopes
Use minimal scopes
- Only request the scopes your application needs
- Review and audit token permissions regularly
- Create separate tokens for different integrations
Rotate tokens regularly
Rotate tokens regularly
- Regenerate tokens periodically (every 3-6 months)
- Revoke tokens that are no longer needed
- Monitor for unauthorized usage
Protect in transit
Protect in transit
- Always use HTTPS (enforced by our API)
- Don’t log or display full tokens
- Use secure headers in requests
Revoking Tokens
To revoke a token:- Go to Settings → API Tokens
- Find the token you want to revoke
- Click the Delete button
- Confirm the deletion
Error Responses
Invalid or Missing Token
401 Unauthorized
Solution: Ensure you’re including a valid token in the Authorization header.
Insufficient Scope
403 Forbidden
Solution: Create a new token with the required scopes or update your existing token’s permissions.
Expired Token
401 Unauthorized
Solution: Generate a new access token from the dashboard.