Events: AI use in tokens, not rand (for 2.3.0); contracts: token fields on the AI status

Site settings → AI, the usage tables and the 80% email show input/output
tokens and the percentage; the rand amounts from the Hub are dropped on
arrival. AiCall stores each call's tokens (migration ai_tokens). v2
/ai/status and /ai/usage carry tokens instead of cents. Needs Hub 2.0.1
for the token figures; older Hubs show the percentage only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 10:59:36 +02:00
co-authored by Claude Opus 5.5
parent e8853cf0c8
commit 38ebce24ab
17 changed files with 725 additions and 169 deletions
+12 -3
View File
@@ -205,15 +205,24 @@ POST /api/installs/ai/status
X-Hub-Install / X-Hub-Timestamp / X-Hub-Signature (as in §3)
{ "protocolVersion": 1 }
→ 200 { "enabled": true, "capReached": false, "capCents": 5000, "usedCents": 812.4,
"usedPercent": 16, "renewsOn": "2026-12-01" }
"usedPercent": 16, "renewsOn": "2026-12-01",
"usedInputTokens": 412000, "usedOutputTokens": 61000, // Hub 2.0.1+
"capInputTokens": 3571000, "capOutputTokens": 714000 } // Hub 2.0.1+
```
- **`enabled: false`** — hide the AI buttons everywhere: the licence's cap is R0, the licence isn't
active (suspended, revoked, or past its grace days), or the Hub's AI isn't set up.
- **`capReached: true`** — show the buttons **disabled** ("This month's AI allowance is used up — it
renews on 1 December"). Reached means there isn't room left for even a small call.
- Amounts are cents (rand) as **charged** to the church, with fractions (a call costs a fraction of a
cent). The month is South African time; `renewsOn` is the 1st of the next month.
- **Churches see tokens, never rand** (Hub 2.0.1, Cross Events 2.3.0). `usedInputTokens` /
`usedOutputTokens` are this month's tokens over all the church's installs (input counts cached
prompt tokens). `capInputTokens` / `capOutputTokens` are an **estimate** of the allowance: what half
the cap buys as input and half as output, at the current model price, exchange rate and markup,
rounded down to a thousand. `usedPercent` is exact (it's worked out in rand). Installs show the
tokens and the percentage, and don't pass the cents on.
- `capCents` / `usedCents` are cents (rand) as **charged** to the church, with fractions (a call costs
a fraction of a cent), for the Hub and for installs before Cross Events 2.3.0. The month is South
African time; `renewsOn` is the 1st of the next month.
### A helper call