Available on Blnk Core 0.10.1 and later.
transactions:write and balances:read, while your reporting service might only need *:read.
This keeps each service limited to the access it needs. If a key is exposed, you can revoke that key without rotating your master key or affecting the rest of your system.
Before you start
Scoped API keys require secure mode. When secure mode is enabled, Blnk requires every request to include a valid key in theX-Blnk-Key header.
Start by enabling secure mode and setting a strong secret_key in your configuration:
secret_key becomes your master key. Use it once to create your first scoped API key with POST /api-keys.
After that, use scoped keys for normal API traffic.
Create and use a scoped key
Create a scoped key
Use the master key to create your first scoped key. In this example, we create a key for a payments service:
A successful request returns
| Parameter | Description |
|---|---|
name | A readable label for the key, such as a service or environment name. |
owner | The team, service, or tenant that owns the key. Blnk stores this as owner_id. See Owner context. |
scopes | The permissions assigned to the key, using resource:action format. See Scopes. |
expires_at | When the key stops working, in ISO 8601 format. |
201 Created.Save the key
On success, the response includes the plaintext key in the Copy the
key field:201 Created
key value immediately and store it in your secrets manager or as an environment variable. Wire that value into the service that will call Blnk.Use the scoped key
Pass the scoped key in the Blnk checks that the key is valid, not expired or revoked, and that its scopes cover the endpoint you’re calling. This key has
X-Blnk-Key header on every request.transactions:write, so it can create transactions but cannot create ledgers without ledgers:write.API key tracking
When you create a record with a scoped API key, Blnk adds the key’sapi_key_id to the resource meta_data under BLNK_GENERATED_BY.
This lets you trace which key created a ledger, balance, transaction, or identity.
The master key does not add this field. Only scoped API keys authenticated through X-Blnk-Key do.
API key tracking
BLNK_GENERATED_BY automatically on POST requests. You do not need to include it in your request body. If you send your own meta_data, Blnk merges this field into it.
Error handling
Structured errors are available from Blnk Core 0.15.0 and later.
401 Unauthorized response.
| Code | When it happens |
|---|---|
AUTH_INVALID_API_KEY | The key is incorrect, malformed, incomplete, or sent with the wrong header. |
AUTH_EXPIRED_API_KEY | The key has expired or has been revoked. |
401 Unauthorized
| Code | What to do |
|---|---|
AUTH_INVALID_API_KEY | Check that the full key value is being sent in the X-Blnk-Key header. |
AUTH_EXPIRED_API_KEY | Create a replacement key with the same scopes, update the service using it, then revoke the old key. See Manage API keys. |
X-Blnk-Key header, are covered in Secure your Blnk server.
Related docs
Scopes
Pick the right permissions.
Owner context
How Blnk isolates key management.
Manage keys
List, revoke, and delegate keys.