Overview
The Modulus Labs QR API uses HTTP Basic Authentication to secure all API requests. You’ll need your Secret Key, which will be provided by Modulus Labs.Your Secret Key
When you sign up, Modulus Labs will provide you with a Secret Key that looks like this:Secret Keys always start with the prefix
sk_ to help you identify them.How Basic Authorization Works
HTTP Basic Auth requires a username and password. For the QR API:- Username: Your Secret Key
- Password: Empty string (leave blank)
Step-by-Step Process
1
Combine username and password
Combine your Secret Key with a colon (
:) and an empty password2
Base64 encode
Apply Base64 encoding to the string from Step 1
3
Add to header
Add the authorization header with “Basic” followed by the Base64 encoded string
Code Examples
Most HTTP clients handle Basic Auth automatically. Here’s how to implement it in different languages:Manual Base64 Encoding
If you need to manually encode the authorization header:Using Command Line
Using JavaScript
Security Requirements
HTTPS Only
All API requests must be made over HTTPS. Calls made over plain HTTP will fail.
Authentication Required
All API requests must include valid authentication credentials or they will fail.
Keep Keys Secure
Never expose your Secret Key in client-side code or public repositories.
Rotate Keys
Regularly rotate your keys and immediately revoke compromised ones.
Authentication Errors
If authentication fails, you’ll receive one of these error responses:| Error Code | Description |
|---|---|
10000003 | Account not found |
10000006 | API Key not found |
10000008 | API Key expired |
10000009 | API Key revoked |
10000010 | API Key suspended |
10000011 | API Key deleted |
10000012 | Unauthorized to perform action |
10000013 | Invalid API Key |
10000015 | Insufficient permissions |
Example Error Response
See the Errors page for a complete list of error codes and how to handle them.
Testing Your Authentication
Use the Ping endpoint to test your authentication:Best Practices
Use Environment Variables
Use Environment Variables
Store your Secret Key in environment variables, never hardcode them in your source code.
Implement Key Rotation
Implement Key Rotation
Regularly rotate your Secret Keys and maintain a grace period where both old and new keys work.
Use Different Keys for Environments
Use Different Keys for Environments
Use separate Secret Keys for sandbox and production environments to prevent accidental charges.
Monitor Authentication Failures
Monitor Authentication Failures
Track authentication failures in your logs to detect potential security issues.
Revoke Compromised Keys Immediately
Revoke Compromised Keys Immediately
If a Secret Key is compromised, contact Modulus Labs support immediately to revoke it.