Agent skill · marketing growth · affaan-m
cost-aware-llm-pipeline
Cost optimization patterns for LLM API usage — model routing by task complexity, budget tracking, retry logic, and prompt caching. Use when LLM spend needs to come down, or when routing tasks across model tiers and budgets.
Why this skill is useful
Provides specific cost optimization patterns and executable code for managing LLM API usage that the AI wouldn't generate on its own.
What it needs
About 3k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
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. 2. Immutable Cost Tracking Track cumulative spend with frozen dataclasses. Each API call returns a new tracker — never mutates state. 3. Narrow Retry Logic Retry only on transient errors. Fail fast on authentication or bad request errors. 4. Prompt Caching Cache long system prompts to avoid resending them on every request. Composition Combine all four techniques in a single pipeline function: Pricing Reference (2026) Model Input ($/1M tokens) Output ($/1M tokens) Relative Cost ------- --------------------- ---------------------- --------------- Haiku 3.5 (legacy) $0.80 $4.00 0.8x Haiku 4.5 $1.00 $5.00 1x Sonnet 5 $2.00 $10.00 2x Sonnet 4.6 $3.00 $15.00 3x Opus 4.8 $5.00 $25.00 5x Fable 5 / Mythos 5 $10.00 $50.00 10x Opus 4.0 / 4.1 (legacy) $15.00 $75.00 15x Best Practices Start with the cheapest model and only route to expensive models when complexity thresholds are met Set explicit budget limits before processing batches — fail early rather than overspend Log model selection decisions so you can tune thresholds based on real data Use prompt caching for system prompts over 1024 tokens — saves both cost and latency Never retry on authentication or validation errors — only transient failures (network, rate limit, server error) Anti-Patterns to Avoid Using the most expensive model for all requests regardless of complexity Retrying on all errors (wastes budget on permanent failures) Mutating cost tracking s …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/cost-aware-llm-pipeline--a20193