Skip to main content
Available on Blnk Core 0.10.1 and later.
Your master key has full access to your Blnk server. Use it only for admin actions, like creating and revoking API keys. For everything else, use scoped API keys. Each key can be limited to a specific owner, set of scopes, and expiry date. For example, your payments service might only need 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 the X-Blnk-Key header. Start by enabling secure mode and setting a strong secret_key in your configuration:
The 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.
Do not commit the master key to version control. In production, store it in a secret manager or inject it through environment variables.

Create and use a scoped key

1

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 201 Created.
2

Save the key

On success, the response includes the plaintext key in the key field:
201 Created
Copy the 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.
Blnk shows the plaintext key only once. After creation, the key is hashed at rest and cannot be retrieved again.If you lose it, create a new key and revoke the old one.
3

Use the scoped key

Pass the scoped key in the X-Blnk-Key header on every request.
Blnk checks that the key is valid, not expired or revoked, and that its scopes cover the endpoint you’re calling. This key has 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’s api_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 sets 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.
You can use BLNK_GENERATED_BY for audit trails, service attribution, and tenant-level tracing. For example, if each tenant or service uses its own scoped key, you can filter records by meta_data.BLNK_GENERATED_BY to see what that key created.

Error handling

Structured errors are available from Blnk Core 0.15.0 and later.
When a scoped key fails authentication, Blnk returns a 401 Unauthorized response.
401 Unauthorized
To resolve the error: Other authentication errors, such as a missing X-Blnk-Key header, are covered in Secure your Blnk server.

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool. To ask questions or discuss issues, please contact us or join our Discord community.