Cost Management¶
The pipeline enforces token budgets at two levels to prevent runaway LLM costs.
Cost Ceilings¶
- Per-article ceiling — each
produce_articlerun has a maximum token budget. If exceeded, the pipeline stops and alerts - Monthly budget — aggregate monthly token spend is tracked across all flows. Alerts fire at configurable thresholds
Model Selection Strategy¶
Costs are managed by choosing the right model for each task:
- Sonnet (more expensive) — creative writing, research synthesis, complex reasoning
- Haiku (cheaper) — classification, scoring, structured evaluation
Image Generation Costs¶
DALL-E 3 image generation is tracked separately from token costs:
| Size | Cost per Image |
|---|---|
| 1024×1024 | $0.04 |
| 1024×1792 | $0.08 |
| 1792×1024 | $0.08 |
Image generation is optional — set OPENAI_API_KEY to enable. Articles without featured images proceed normally.
Tracking¶
Token usage is logged per agent call via the cost tracker. The dashboard Analytics page shows cost trends over time.
The current_flow_name ContextVar threads the active flow name to call_agent() for per-flow cost ceiling enforcement without modifying agent signatures.