// CONTENTS Part 10 · AI operations

// PART 10

Rate limits and cost control

Chapter 43 / 60 2 min read English Part 10 of 15

Rate limits protect the platform; cost limits protect the budget. Both have hard numbers, and both have a panel that watches them.

Hard limits (from SystemLimits)

Limit Default Constant
Tokens per LLM request 128,000 MAX_LLM_TOKENS_PER_REQUEST
LLM requests per minute 60 MAX_LLM_REQUESTS_PER_MINUTE
Script execution time 300 s MAX_SCRIPT_EXECUTION_SECONDS
Loop iterations 100,000 MAX_LOOP_ITERATIONS

API-level rate limiting defaults (enforced with the governor crate, per-IP and per-user tracking plus WebSocket message limits): General 100 req/s global, Auth 10 req/s on login endpoints, API 50 req/s per token.

The cost model

Cost per conversation is derived from the tokens the provider reports, not from an estimate:

cost_usd = tokens_in / 1_000_000 * price_in + tokens_out / 1_000_000 * price_out

Prices come from the pricing.models table in ops/slo.yaml — the single price source for the gate. A model that is not in the table is a configuration error, not a free call: the checker refuses to guess. The mock and the free gateway model are priced at zero, so a CI run can never accrue a bill.

SLO targets (from ops/slo.yaml):

Objective Target
Cost per conversation (cost.conversation_usd) ≤ USD 0.010 mean, 1-day rolling
Cost per tenant per day (cost.tenant_day_usd) ≤ USD 10.00 hard quota, alert at 80 %

Where to watch cost

The Analytics → Operations → LLM cost & tokens panel answers: tokens, spend, cost per conversation, spend per tenant, daily quota burn — with the number of failed calls alongside. The SQL underneath:

# Which bot is burning? Sort by cost in the last hour.
psql -h localhost -U postgres -d botserver -c   "SELECT b.name, COUNT(*) AS calls, SUM(m.estimated_cost) AS cost
     FROM llm_metrics m JOIN bots b ON b.id = m.bot_id
    WHERE m.timestamp > NOW() - INTERVAL '1 hour'
    GROUP BY b.name ORDER BY cost DESC LIMIT 10;"

Levers, in the order to pull them

  1. Drain the offender — UPDATE bots SET is_active = false WHERE name = '<bot>'; stops new work for that bot only; reversible.
  2. Tighten history — per-bot history-limit in Vault caps the context growth that quietly inflates every turn.
  3. Enable/raise caching — llm-cache, llm-cache-semantic and llm-cache-threshold in config.csv remove repeated calls.
  4. Downgrade the model — a smaller quantized model for simple bots.
  5. Pricing data — GB_LLM_PRICING (inline JSON) feeds the accounting when the shipped table does not cover a model.

What a breach means

Symptom First place to look
Cost per conversation over budget context growth (history limit), tool loops, a model change
Tenant quota alert at 80 % the tenant’s top bots by spend; drain before the hard quota stops the tenant
Failed calls rising with cost flat provider errors, not spend — see the outage runbook

Found a mistake? Open an issue · All books

// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move