
Cost Aware Llm Pipeline
This is a practical blueprint for keeping LLM API costs under control without tanking quality. It shows you how to route simple tasks to cheap models like Haiku and complex ones to Sonnet, track spend with immutable dataclasses, retry only transient errors, and cache long system prompts. The code examples are concrete and composable. Most useful if you're processing batches where costs add up fast or need hard budget limits before you burn through your API quota. The model selection thresholds are opinionated but tunable, which is the right approach.
- skills.sh installs
- 5.6K
- GitHub stars
- 300.3K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add affaan-m/ecc --skill cost-aware-llm-pipeline --agent claude-codeInstalls into .claude/skills of the current project.
Files
Cost-Aware LLM Pipeline
Patterns for controlling LLM API costs while maintaining quality. Combines model routing, budget tracking, retry logic, and prompt caching into a composable pipeline.
When to Activate
- Building applications that call LLM APIs (Claude, GPT, etc.)
- Processing batches of items with varying complexity
- Need to stay within a budget for API spend
- Optimizing cost without sacrificing quality on complex tasks
Core Concepts
1. Model Routing by Task Complexity
Automatically select cheaper models for simple tasks, reserving expensive models for complex ones.
MODEL_SONNET = "claude-sonnet-5"
MODEL_HAIKU = "claude-haiku-4-5-20251001"
_SONNET_TEXT_THRESHOLD = 10_000 # chars
_SONNET_ITEM_THRESHOLD = 30 # items
def select_model(
text_length: int,
item_count: int,
force_model: str | None = None,
) -> str:
"""Select model based on task complexity."""
if force_model is not None:
return force_model
if text_length >= _SONNET_TEXT_THRESHOLD or item_count >= _SONNET_ITEM_THRESHOLD:
return MODEL_SONNET # Complex task
return MODEL_HAIKU # Simple task (3-4x cheaper)
Sponsors
Details
- Repository
- github.com/affaan-m/ecc
- Categories
- Backend & APIs, DevOps & CI/CD, AI & Agent Building, Automation & Workflows, Sales & Marketing
- First seen
- Jul 14, 2026
More from affaan-m/ecc
All 263- Mcp Server Patterns5.6K
- Council5.6K
- Fal Ai Media5.6K
- Jpa Patterns5.6K
- Mle Workflow5.6K
- Compose Multiplatform Patterns5.6K
- Llm Trading Agent Security5.6K
- Swiftui Patterns5.6K
- Github Ops5.6K
- Autonomous Loops5.6K
- Data Scraper Agent5.6K
- Springboot Verification5.6K
- Django Verification5.6K
- Django Celery5.6K
- Dotnet Patterns5.6K
- Blueprint5.5K
- Ecc Guide5.5K
- Code Tour5.5K
- Nuxt4 Patterns5.5K
- Healthcare Phi Compliance5.5K
- Inventory Demand Planning5.5K
- Agentic Os5.5K
- Product Capability5.5K
- Security Bounty Hunter5.5K