qlk_live_…
key per end-user of your app, enforcing a per-user spending cap, and
generating invoices from per-key usage.
Mental model
| Stripe pattern | qlaud equivalent |
|---|---|
Customer | A qlk_live_… key with name: "user_<id>" |
| Subscription / metered usage | Per-key usage_events we record on every API call |
| Spending limit | max_spend_usd enforced on the key |
| Webhook on overage | (coming soon) cap_exceeded webhook |
| Invoice | GET /v1/usage → fold into Stripe InvoiceItem.create() |
scope: 'admin') that lets you mint and revoke
per-user keys. Every other key is scope: 'standard' and can only be used
for inference.
Architecture
Step 1 — Mint your master key
In the dashboard, create a key with scope Master (admin). Store it asQLAUD_MASTER_KEY in your backend’s secret manager.
Never expose this key to clients — it can mint other keys.
Step 2 — Mint a per-user key on signup
When a user signs up to your app, mint a qlaud key for them with their monthly cap.The
secret is returned once at creation time. Save it immediately — we
only store its SHA-256 hash. If you lose it, you must revoke the key and
mint a new one.Step 3 — Use the per-user key for inference
In your app’s request flow, swap the master key for the user’s key when calling qlaud. The cap is enforced gateway-side — you don’t need any extra logic.Step 4 — Bill at month-end
Pull per-user spend from qlaud and create Stripe invoice items.Optional — date-range billing
/v1/usage defaults to month-to-date. Pass from_ms and to_ms (UTC
milliseconds) to scope to any window:
Optional — drill down to one user
Revoking a key
When a user churns or you need to roll a key:What you didn’t have to build
- Per-user usage tracking →
usage_eventstable on our side - Per-user spending caps →
max_spend_microscolumn, KV-cached check - Failed-payment handling for AI usage →
402from qlaud, propagate to user - Per-provider billing reconciliation → one wallet, one invoice from us
- Storing customer-facing AI prices → catalog already includes our 7% markup
Coming soon
- Webhooks —
cap_exceeded,low_balance,key_revoked. POST to your URL on event. - Per-key recharge —
POST /v1/keys/:id/creditto add credit on a single user-key without touching your master wallet (for “user paid you, push credit to their key” flows). @qlaud/sdk— Stripe-SDK-shaped Node + Python clients withqlaud.keys.create(),qlaud.usage.list(), etc.