Authentication
The AnySpend Platform API uses API keys for authentication. Each key is scoped to a single organization and carries a specific set of permissions.Creating an API key
Open the AnySpend Dashboard
Navigate to anyspend.com/dashboard and sign in to your account.
Create a new key
Click Create API Key, give it a descriptive name (e.g., “Production Backend” or “CI/CD Pipeline”), and select the permission level.
API key format
All AnySpend API keys start with the prefixasp_:
Passing your API key
You can authenticate requests using either of two headers:- X-API-Key header
Authorization: Bearer method is preferred as it follows standard OAuth 2.0 conventions and is supported by most HTTP clients and API testing tools.
Permission levels
Each API key is assigned one or more permissions. Permissions follow a hierarchy where higher levels include all lower-level capabilities.| Permission | Grants access to | Use case |
|---|---|---|
| read | GET on all resources — list and retrieve payment links, products, transactions, customers, analytics | Dashboards, reporting tools, read-only integrations |
| write | Everything in read + POST, PATCH, DELETE on all resources — create payment links, update products, manage webhooks | Backend services, automation, standard integrations |
| admin | Everything in write + manage API keys, organization settings, and billing | Infrastructure management, CI/CD, admin tooling |
The permission hierarchy means a key with write permission automatically has read access. A key with admin permission has both write and read access.
Permission hierarchy
Example: checking permissions
If a route requireswrite permission and your key only has read, you will receive a 403 error:
Creating API keys via the API
If you have a key withadmin permission, you can programmatically create new keys:
Listing and revoking keys
List all keys
key_prefix for identification:
Revoke a key
401 error.
Quick Pay — open tier (no auth)
The Quick Pay endpoint does not require authentication. It is designed for one-shot payments where you do not need an AnySpend account:Key rotation best practices
Rotating your API keys periodically reduces the risk of compromised credentials. Here is a recommended approach:Create a new key
Use the dashboard or API to create a new key with the same permissions as the one being rotated.
Update your application
Deploy the new key to your application’s environment variables or secrets manager.
Verify the new key works
Confirm your application is successfully making requests with the new key by checking the
last_used_at timestamp.Security best practices
Never expose keys in client-side code
Never expose keys in client-side code
API keys should only be used in server-side code (backend services, serverless functions, CI/CD pipelines). Never include them in:
- Frontend JavaScript bundles
- Mobile app source code
- Public GitHub repositories
- Browser-accessible configuration files
Use environment variables
Use environment variables
Store your API key in an environment variable rather than hardcoding it:Add
.env to your .gitignore to prevent accidental commits.Use least-privilege permissions
Use least-privilege permissions
Create keys with only the permissions they need:
- A reporting dashboard only needs read
- A backend that creates payment links needs write
- Only infrastructure tooling should use admin
Monitor key usage
Monitor key usage
Regularly check
last_used_at on your keys to identify unused keys that should be revoked. Unused active keys are a security risk.Set expiration dates
Set expiration dates
For temporary integrations, CI/CD tokens, or contractor access, always set an
expires_at timestamp so keys automatically become inactive.Authentication error codes
| HTTP status | Code | Meaning |
|---|---|---|
401 | key_missing | No API key was provided in the request headers |
401 | key_invalid | The API key does not match any active key |
401 | key_expired | The API key has passed its expires_at timestamp |
401 | key_revoked | The API key was explicitly revoked |
403 | insufficient_permissions | The API key does not have the required permission level |
HypeDuel