Deploy Blnk
Local install or Blnk Cloud.
Enable secure mode
Modify yourblnk.json configuration file to enable secure mode. Set server.secure to true and provide a strong server.secret_key.
blnk.json
Authentication methods
Blnk supports authentication via the X-Blnk-Key header.Master key authentication
The master key (server.secret_key) provides full access to all API endpoints. Use it only for administrative tasks and initial setup.
Generating fine-grained API keys
Available on version 0.10.1 or later.
Create an API key
Use the master key to bootstrap keys for each owner. Starting in 0.14.3, a non-master key withapi-keys:write can also create keys, but only within its own owner context and with scopes it already holds. See the Create API key reference for complete documentation.
| Parameter | Description |
|---|---|
name | The name of the API key or service account. |
owner | Owner identifier for the new key. You choose this value (e.g. team name, service name, user ID). It is stored as owner_id on the key record and defines the key’s owner context. When you authenticate with a non-master API key, Blnk always uses the caller’s owner_id — a different owner value in the request returns 403 Forbidden. |
scopes | A list of permissions granted to the API key (e.g., ledgers:read, balances:write). |
expires_at | The expiration date and time for the API key in ISO 8601 format. |
Owner context
Available on version 0.14.3 or later.
owner_id field on the key record. When you call the API key management endpoints (create, list, revoke), Blnk checks whether the caller is allowed to act on that owner.
| Caller | What it can manage |
|---|---|
Master key (server.secret_key) | Keys for any owner. Pass owner in the request to target a specific owner. The master key is a global server secret and is not bound to an owner_id. |
| Non-master API key | Keys for its own owner_id only. Blnk resolves the effective owner from the authenticated key, not from caller-supplied owner values. |
k1 has owner_id = merchant_a.
k1can create, list, and revoke keys formerchant_ak1cannot manage keys formerchant_b, even if the request body or query includes"owner": "merchant_b"- The master key can manage keys for both
merchant_aandmerchant_b
api-keys:read, api-keys:write, or api-keys:delete can delegate key management within their owner context, subject to two additional rules:
- Scope inheritance: A non-master key can grant only scopes it already holds. You cannot mint a key with broader permissions than the caller.
- No cross-owner access: The effective owner always comes from the caller’s
owner_id, never from a different value in the request.
Use the API key
Understanding Scopes
Scopes define what resources an API key can access and what actions it can perform, formatted asresource:action.
Available resources
| Resources | Description |
|---|---|
* | All resources |
ledgers | Ledger management |
balances | Balance operations |
accounts | Account operations |
identities | Identity management |
transactions | Transaction processing |
balance-monitors | Balance monitoring |
hooks | Hook-related permissions (hook management endpoints require the master key as of 0.14.3) |
api-keys | API key management |
search | Search operations |
reconciliation | Reconciliation tasks |
metadata | Metadata management |
backup | Backup operations |
Available actions
| Actions | Description |
|---|---|
* | All actions |
read | View operations — GET/HEAD |
write | Modify operations — POST/PUT/PATCH |
delete | Delete operations — DELETE |
Examples
ledgers:read: Can only view ledgerstransactions:write: Can create/modify transactions*:*: Full access to all resources and actions
Security best practices
Master key management
- Use a strong, randomly generated master key
- Never share or commit it to version control
- Store it in environment variables or secret management tools
- Rotate keys regularly
API key management
- Create separate API keys for different services
- Set expiration dates for API keys
- Grant only necessary scopes
- Regularly audit and revoke unused keys
- Monitor API key usage
Configuration management
- Exclude
blnk.jsonfrom version control (.gitignore) - Store sensitive configurations in environment variables
- Implement secure secret rotation procedures
Access control
- Follow the principle of least privilege
- Regularly review API key permissions
- Implement role-based access control (RBAC)
- Maintain audit logs of key activities
- Register and manage transaction hooks with the master key only
Monitoring and auditing
- Track failed authentication attempts
- Monitor API key usage patterns
- Set up alerts for suspicious activity
- Regularly review access logs
Regular updates
- Keep all components up to date
- Monitor security advisories
- Schedule regular maintenance windows
Error handling
Authentication failures return specific error messages:| Status Code | Message |
|---|---|
| 401 Unauthorized | ”Authentication required. Use X-Blnk-Key header” “Invalid API key” “API key is expired or revoked” |
| 403 Forbidden | ”Insufficient permissions for resource:action” “Unknown resource type” “cannot manage API keys for another owner” “cannot grant scopes broader than caller” “hook management requires master key” |