The problem
On a flat-rate plan, all customers look identical from a revenue perspective — they each pay the same $299/month (or $99, or $499). But token consumption can vary 100× or more between customers. You don't know who is causing margin erosion until the invoice lands, 30 days later.
Tag each task with a customer_id
from apeiros import ApeirosAgent
agent = ApeirosAgent(customer_id="acme-corp", model="claude-3-5-sonnet")
agent.start_task("summarize quarterly report", priority="normal")
agent.update_tokens(8_500)
agent.end_task()
print(f"Task cost: ${agent.cost_estimate:.4f}")
# Task cost: $0.0680
Every task you run through ApeirosAgent is recorded in a class-level registry, keyed by customer_id. Tasks accumulate across the lifetime of your process.
Pull the margin report
Once you've run tasks for multiple customers, call customer_report() with your plan price:
print(ApeirosAgent.customer_report(plan_price=299.0))
Output:
════════════════════════════════════════════════════════════════════
CUSTOMER COST REPORT
════════════════════════════════════════════════════════════════════
Customer Tasks Tokens Est. Cost Signal
────────────────────────────────────────────────────────────────
hyperscale-co 18700 793200000 $3173.8400 Normal
nova-ventures 330 12474000 $ 997.9200 Normal
titan-retail 2640 87912000 $ 351.6480 Normal
greenleaf-inc 880 61600000 $ 492.8000 Normal
acme-corp 396 7920000 $ 3.1680 Normal
════════════════════════════════════════════════════════════════════
MARGIN ANALYSIS ($299.00/month flat plan)
════════════════════════════════════════════════════════════════════
Customer Monthly Cost Revenue Margin Status
────────────────────────────────────────────────────────────────
hyperscale-co $ 3173.8400 $ 299.00 -961.5% ✗ underwater
nova-ventures $ 997.9200 $ 299.00 -233.8% ✗ underwater
titan-retail $ 351.6480 $ 299.00 -17.6% ✗ underwater
greenleaf-inc $ 492.8000 $ 299.00 -64.8% ✗ underwater
acme-corp $ 3.1680 $ 299.00 98.9% ✓ healthy
Reading the output
| Column | Meaning |
|--------|---------|
| Monthly Cost | Estimated AI spend for this customer this period |
| Revenue | Your plan price — what they're paying you |
| Margin % | (Revenue − Cost) / Revenue × 100 |
| Status | healthy ≥ 70% · watch 40–70% · thin 0–40% · underwater < 0% |
What to do with each status
Underwater — this customer costs more to serve than they pay you. Three options:
- Enforce a usage cap (see How to set a customer budget and get notified)
- Move them to a higher-tier plan
- Switch to consumption-based pricing for that customer
Watch — profitable, but thinning. Run meter() (see below) to track velocity mid-month. Watch for retry loops and context bloat — the two most common drivers.
Healthy — no action needed. Use as your baseline for new customer onboarding.
Catch problems mid-month with meter()
customer_report() is point-in-time. To see projected monthly spend before the period ends:
print(ApeirosAgent.meter(plan_price=299.0))
══════════════════════════════════════════════════════════════════════════
LIVE METER — 2025-06-01 14:32:11 UTC
══════════════════════════════════════════════════════════════════════════
Customer Cost now $/hr Proj/mo Status
────────────────────────────────────────────────────────────────────────
hyperscale-co $ 142.18 $0.284 $ 204.48 ~ watch
nova-ventures $ 44.80 $0.090 $ 64.80 ✓ healthy
Poll this from a cron job or background task (every 15 minutes is sufficient for most products).
Run the reference demo
To see this against five realistic customer profiles:
python examples/reference_saas.py