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
1
Navigate to API Settings
Go to Settings → API Tokens in your PayRequest dashboard.
2
Create New Token
Click the Create New Token button.
3
Configure Token
- Enter a descriptive name (e.g., “MCP Billing Agent”)
- Select the scopes (permissions) your token needs
- Click Create
4
Copy Your Token
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
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
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.