What is already wired
`POST /api/ai/generate` accepts a signed-in session or a scoped Bearer API key. The API key is hashed at rest; revocation, account status and a fixed-window rate limit are rechecked in one atomic D1 update before the request proceeds.
The credit ledger is append-only. A request reserves credits before the provider call, then settles the actual usage afterwards. A definitive provider rejection releases the reservation; a successful call leaves the settled debit in the ledger.
Ledger and billing invariants use D1 batch statements so a request cannot both fail and leave a charge, or settle twice. Every request carries an idempotent request id.