Skip to main content

API Authentication

The PayRequest API uses OAuth2 with Personal Access Tokens for authentication. All API requests must include a valid access token in the Authorization header.

Creating an Access Token

1

Navigate to API Settings

Go to SettingsAPI 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

Your token is only shown once. Copy it immediately and store it securely. If you lose it, you’ll need to create a new token.

Using Your Token

Include the token in the Authorization 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 default billing.read scope.

Scope Inheritance

The billing.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

  • Never commit tokens to version control
  • Use environment variables or secret management services
  • Encrypt tokens at rest
  • Only request the scopes your application needs
  • Review and audit token permissions regularly
  • Create separate tokens for different integrations
  • Regenerate tokens periodically (every 3-6 months)
  • Revoke tokens that are no longer needed
  • Monitor for unauthorized usage
  • 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:
  1. Go to SettingsAPI Tokens
  2. Find the token you want to revoke
  3. Click the Delete button
  4. Confirm the deletion
Revoking a token is immediate and cannot be undone. Any applications using that token will lose access.

Error Responses

Invalid or Missing Token

HTTP Status: 401 Unauthorized Solution: Ensure you’re including a valid token in the Authorization header.

Insufficient Scope

HTTP Status: 403 Forbidden Solution: Create a new token with the required scopes or update your existing token’s permissions.

Expired Token

HTTP Status: 401 Unauthorized Solution: Generate a new access token from the dashboard.

Example: Complete Authentication Flow