Skip to main content
This guide walks through the headline qlaud workflow — minting a qlk_live_… key per end-user of your app, enforcing a per-user spending cap, and generating invoices from per-key usage.

Mental model

You hold one master key (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 as QLAUD_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:
Revocation propagates to our cache immediately — the key stops working on the next request, no waiting for TTL.

What you didn’t have to build

  • Per-user usage tracking → usage_events table on our side
  • Per-user spending caps → max_spend_micros column, KV-cached check
  • Failed-payment handling for AI usage → 402 from 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

  • Webhookscap_exceeded, low_balance, key_revoked. POST to your URL on event.
  • Per-key rechargePOST /v1/keys/:id/credit to 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 with qlaud.keys.create(), qlaud.usage.list(), etc.