The AI content system tracks costs per-generation and enforces per-tenant monthly budgets. This prevents runaway spending while allowing tenants on higher tiers to use more AI features.
Per-Generation Cost Breakdown
Costs vary by content type (different prompt sizes) and provider. These are estimates using Anthropic (primary provider) with claude-sonnet-4-20250514.
| Content Type | Avg Input Tokens | Avg Output Tokens | Est. Cost |
|---|
gap_narrative | ~1,500 | ~800 | ~$0.016 |
remediation_playbook | ~800 | ~600 | ~$0.011 |
evidence_suggestion | ~400 | ~300 | ~$0.007 |
policy_suggestion | ~600 | ~500 | ~$0.009 |
The initial backfill of all 8 tenants cost $0.043 total. AI content generation is very cost-effective at current scale.
Monthly Projections at Scale
Assumes one gap_narrative regeneration per tenant per day, plus occasional playbook/suggestion requests. Uses Anthropic primary pricing.
| Tenants | Daily Narratives | Monthly Est. | Notes |
|---|
| 10 | 10 | ~$5 | Current scale |
| 100 | 100 | ~$50 | Small MSP |
| 1,000 | 1,000 | ~$500 | Mid-market |
| 10,000 | 10,000 | ~$5,000 | Enterprise (consider batch pricing) |
Content-hash caching significantly reduces actual costs. If a tenant’s data hasn’t changed, the nightly backfill skips regeneration entirely — no provider call, no cost.
Tier-Based Budget Defaults
Each tenant has a monthly budget set in ai_content_budgets. Defaults are assigned based on subscription tier.
| Tier | Monthly Budget | Daily Regen Limit | Notes |
|---|
| Free | $0.50 | 2 | Enough for basic narrative updates |
| Startup | $5.00 | 10 | Regular narrative + occasional playbooks |
| Growth | $25.00 | 50 | Full content generation |
| Professional | $100.00 | 200 | Unlimited practical usage |
Setting a tenant’s budget
-- View current budget
SELECT tenant_id, monthly_limit_usd, current_month_cost_usd, is_enabled
FROM ai_content_budgets
WHERE tenant_id = '<tenant_id>';
-- Update budget
UPDATE ai_content_budgets
SET monthly_limit_usd = 25.00
WHERE tenant_id = '<tenant_id>';
Creating a budget for a new tenant
Budgets are created automatically when a tenant first requests AI content. To manually create one:
INSERT INTO ai_content_budgets (tenant_id, monthly_limit_usd, is_enabled)
VALUES ('<tenant_id>', 5.00, true)
ON CONFLICT (tenant_id) DO NOTHING;
Budget Enforcement
When a tenant’s current_month_cost_usd reaches their monthly_limit_usd, new generation jobs for that tenant are skipped. The content stays at its last generated version until the budget resets.
Reset Schedule
| Reset | Cron | What It Resets |
|---|
| Daily regen counter | ai-budget-daily-reset (00:01 UTC) | Per-tenant daily regeneration count |
| Monthly cost counter | ai-budget-monthly-reset (00:05 UTC, 1st of month) | Per-tenant current_month_cost_usd back to 0 |
Budget Warning Alerts
The ai-alert-budget-warnings cron runs hourly and sends a Slack alert when any tenant reaches 80% of their monthly budget.
-- Check which tenants are approaching their budget
SELECT
tenant_id,
monthly_limit_usd,
current_month_cost_usd,
ROUND((current_month_cost_usd / monthly_limit_usd) * 100, 1) AS pct_used
FROM ai_content_budgets
WHERE current_month_cost_usd >= monthly_limit_usd * 0.8
ORDER BY pct_used DESC;
Cost Monitoring
View today’s costs by provider
SELECT * FROM v_ai_provider_usage;
View monthly costs by tenant
SELECT * FROM v_tenant_ai_budget_status
ORDER BY current_month_cost_usd DESC;
View cost per generation (recent)
SELECT
content_type,
provider,
cost_usd,
created_at
FROM ai_generation_queue
WHERE status = 'completed'
AND cost_usd > 0
ORDER BY created_at DESC
LIMIT 20;