Grants and credits
Add credit to a customer's wallet from your backend, exactly once.
Your backend adds credit to a wallet with two calls. Both write a ledger entry and apply it to
the gateway, and both take an idempotency_key that makes them safe to retry: the same key
credits a wallet once, forever.
| Call | For |
|---|---|
POST /v1/customers/{external_id}/grants | Credit without payment, such as a plan's allowance or a goodwill credit. Can expire. |
POST /v1/customers/{external_id}/credits | A top_up you were paid for elsewhere, an adjustment or a refund. Never expires. |
To have customers pay you through Hixel, use Top-ups instead: those are credited for you when Stripe confirms the payment.
Grant a plan allowance#
A monthly allowance is a grant keyed on its billing period, expiring when the period ends:
curl https://api.hixel.dev/v1/customers/org_42/grants \
-H "Authorization: Bearer $HIXEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount_micros": "5000000",
"expires_at": "2026-12-01T00:00:00Z",
"idempotency_key": "plan:org_42:2026-11",
"reason": "Team plan, November"
}'const entry = await hixel.wallets.grant("org_42", {
amount_micros: "5000000",
expires_at: "2026-12-01T00:00:00Z",
idempotency_key: "plan:org_42:2026-11",
reason: "Team plan, November",
});
console.log(entry.id, entry.amount_micros);{
"id": "led_…",
"customer": "org_42",
"wallet_id": "wal_…",
"kind": "grant",
"amount_micros": "5000000",
"idempotency_key": "plan:org_42:2026-11",
"expires_at": "2026-12-01T00:00:00.000Z",
"reason": "Team plan, November",
"actor": { "user_id": null, "label": "key_…" },
"created_at": "2026-11-25T10:00:00.000Z",
…
}Run it from your billing job at the start of each period. If the job runs twice, or retries after a timeout, the second call answers the same entry and grants nothing more.
| Field | Rules |
|---|---|
amount_micros | Positive, at most "1000000000000" ($1,000,000) |
expires_at | Optional. When the unspent part expires; never when left out |
idempotency_key | Required. 1 to 200 characters of visible ASCII, not starting with usage:, expiry: or stripe: |
reason | Optional. Shown on the ledger entry |
When a grant expires with credit left, an expiry entry takes the rest out and you get a
wallet.grant_expired webhook.
Record a payment, an adjustment or a refund#
curl https://api.hixel.dev/v1/customers/org_42/credits \
-H "Authorization: Bearer $HIXEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"kind": "top_up",
"amount_micros": "20000000",
"idempotency_key": "invoice:in_1QxYz",
"reason": "Paid by bank transfer"
}'await hixel.wallets.credit("org_42", {
kind: "top_up",
amount_micros: "20000000",
idempotency_key: "invoice:in_1QxYz",
reason: "Paid by bank transfer",
});kind | amount_micros |
|---|---|
top_up | Positive: purchased credit |
adjustment | Either sign: a correction |
refund | Positive returns purchased credit; negative takes it back |
Use the id of the thing you were paid for (an invoice, an order) as the idempotency_key.
Retries and the idempotency key#
Grants and credits take two keys, which do different jobs:
| Key | Scope and lifetime | What it guarantees |
|---|---|---|
idempotency_key in the body | Per wallet, forever | The ledger credit happens once. The same key with the same values answers the entry it wrote; with another kind, amount or expiry it is refused: 409 credit_idempotency_key_reused, and nothing changes |
Idempotency-Key header | Per environment, 24 hours | A retried call gets the stored response of the first successful one. Only successful responses are stored: a call that failed frees the header's key. The same header key on another request is 409 idempotency_key_reused |
The body key is the one that matters for money: choose it from what you are crediting for (a plan period, an invoice id), so that whoever retries, and whenever, the wallet is credited once. Keys are per wallet: the same body key on two customers credits both. The header is a transport retry; send it too if you like, but never instead of the body key.
When the credit reaches the gateway#
A credit is written to the ledger first and then applied to the gateway, which is what lets the
customer's next request through. Usually that takes moments; if the gateway cannot be reached,
it is retried automatically within minutes. The customer's wallet
counts the credits still on their way (pending_credits) and, rarely, those the gateway refused
for good (rejected_credits). A rejected credit is in the ledger but not spendable; you get a
wallet.credit_rejected webhook, and it needs to
be corrected by Hixel's support.
Every credit sends a wallet.credited webhook.