Lakshmi — Goddess of Prosperity (Cost Optimization)
Lakshmi ensures wealth flows wisely: every dollar of cloud and API spend is deliberate.
Cloud spend
- Tag every resource with
service,env, andownerso costs are attributable. Untagged spend is unaccountable spend. - Right-size instances from actual utilization metrics, not guesses. If CPU sits under 20% for a week, downsize.
- Delete idle resources: unattached volumes, old snapshots, forgotten load balancers. Dev environments shut down nights and weekends (scheduled scale-to-zero).
- Set billing alerts at 50%, 80%, and 100% of monthly budget, per account and per project. An alert at 100% only is an autopsy, not an alarm.
- Prefer managed services (RDS, managed Redis, Vercel) until scale genuinely justifies self-hosting — engineer time is the most expensive resource.
- Watch egress: cross-region and internet-out traffic bills quietly. Keep chatty services in one region; put static assets behind a CDN.
- Review the bill line-by-line monthly; the top five line items usually hide at least one surprise.
- Buy savings plans / reserved capacity only for proven steady-state load — never in month one.
AI-native specifics (the big line item)
- Choose the smallest model that passes evals. Run the eval suite (see
agni) against a cheaper model before defaulting to the flagship; route easy requests to small models, hard ones to large. - Cache LLM responses: exact-match cache for deterministic calls, embedding-similarity cache where tolerable. Identical prompt twice = paying twice for nothing.
- Use prompt caching for long shared prefixes (system prompts, tool definitions, few-shot examples) — order prompts static-first so the prefix actually hits cache.
- Cap
max_tokenson every call to what the feature actually needs. Unbounded output is unbounded cost. - Trim context: send only the relevant retrieved chunks, not whole documents. Context bloat is the silent cost multiplier.
- Use the batch API (50% discount) for anything not user-facing-latency-bound: evals, backfills, classification jobs, nightly summaries.
- Estimate before bulk jobs:
n_items × avg_tokens × price_per_token. Anything projected over $50 gets written down and approved before it runs. - Monitor cost per feature and per user; a single power user or runaway agent loop can dominate the bill. Set per-key spend limits (see
kubera). - Track cost-per-request alongside latency in dashboards (see
surya) — cost regressions are bugs.
Practical hooks
- Python: log
usage.input_tokens/usage.output_tokensfrom every LLM response into metrics; tag with feature name. - JS/TS: same — wrap the LLM client once so token accounting is automatic, not per-call-site discipline.
Before shipping anything that spends — checklist
- Resources tagged; billing alerts at 50/80/100%
- Idle and dev resources scheduled off outside working hours
- Smallest model that passes evals;
max_tokenscapped - Caching (response + prompt prefix) considered
- Bulk job cost estimated and approved if over threshold
- Token usage and cost-per-request flowing to dashboards