cost-aware-llm-pipeline
Skill0 starsChanged 5 months agoMITView on GitHub
Cost/latency optimization for apps that call LLM APIs — model routing by task complexity, budget guards, narrow retry, and prompt caching. Use when building or tuning LLM calls in any pipeline (signal generation, batch processing, or any multi-model workflow), or staying under a spend cap. Directly relevant to a shared LLM provider daily budget cap that can exhaust silently (429/403). Trigger on: "LLM cost", "model routing", "which model for this", "API budget", "rate limit / 403", "prompt caching", "batch LLM", "reduce token spend in <app>". Adapted from ECC (affaan-m/ECC, MIT).
21 other projects use a version of this.
Adopted by
Most recently taken up by
- Rojios/everything-claude-codetheir own version, first seen Nov 8, 2026
- pankaj-mahaur/Agent-Daemontheir own version, first seen Nov 6, 2026
- TsinHzl/claude-code-configtheir own version, first seen Nov 1, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
- gongyijie85/dsh-ecctheir own version, first seen Oct 13, 2026
Other versions21 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 21
- loulanyue/awesome-claude-notes★ 272same name
- Fmarzochi/EGC★ 61same name
- gongyijie85/dsh-ecc★ 8same name
- Puen2001/aether-os★ 2same name
- TsinHzl/claude-code-config★ 2same name
- get-proofpilot/claude-skills-catalog★ 1same name
- junimnjw/everything-claude-code★ 1same name
- NISTALTALSON/essential-claude-skills★ 1same name
- Rojios/everything-claude-code★ 1same name
- royaluniondesign-sys/claude-os★ 1same name
11 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- agent-architecture-auditSkill
- code-review-disciplineSkill
- dataviz-designSkill
- design-systemSkill
- docs-designSkill
- editorial-report-designSkill
- layout-interaction-designSkill
- llm-trading-agent-securitySkill
- marketing-microsite-designSkill
- tool-calculator-designSkill
- working-with-claudeSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 18 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
Start on the cheapest model.
“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cost-Aware LLM Pipeline
Control LLM spend without losing quality, by composing four independent levers. Build pipelines so they degrade gracefully and stay cheap. If multiple apps share a single provider key against a daily cap, exhaustion will silently 403/429 all of them — track per-app spend and stop the lower-priority app first.
1. Route model by task complexity ✅
Start on the cheapest model; escalate only when complexity crosses a threshold. Current tiers:
claude-haiku-4-5 (cheap/fast, ~1×) → claude-sonnet-4-6 (balanced, ~4×) → claude-opus-4-8 (reasoning,
~5×) → claude-fable-5 (frontier).
HAIKU, SONNET, OPUS = "claude-haiku-4-5", "claude-sonnet-4-6", "claude-opus-4-8"
def select_model(text_len: int, n_items: int, force: str | None = None) -> str:
if force: return force
if text_len >= 10_000 or n_items >= 30: return SONNET # complex
return HAIKU # simple → 3–4× cheaperReserve Opus/Fable for genuine reasoning (the decide step), not enrichment/formatting. Log every routing decision so thresholds can be tuned from real data (a central per-call cost log is the model).
2. Budget guard (fail early, not silently) ✅
Track cumulative spend with an immutable tracker; check before the call, raise before you blow the cap.
@dataclass(frozen=True, slots=True)
class CostTracker:
budget_usd: float = 1.00
spent: float = 0.0
def add(self, usd): return replace(self, spent=self.spent + usd)
@property
def over(self): return self.spent > self.budget_usdFor a shared provider key: track per-app daily spend and stop the lower-priority app first rather than letting both exhaust. Surface "budget exhausted" as a visible state, never a silent empty result.
3. Narrow retry ✅
Retry only transient errors (connection, rate-limit, 5xx) with exponential backoff; fail fast on auth/
bad-request (retrying those just burns budget). _RETRYABLE = (APIConnectionError, RateLimitError, InternalServerError).
4. Prompt caching ✅
Mark the stable prefix (system prompt, tool defs, long static context) with cache_control: ephemeral;
cache reads ≈ 0.1× input cost, 5-min TTL. Put stable content first, variable input last (see
working-with-claude §4). Worth it for any system prompt >1024 tokens — saves cost and latency.
Best practices / anti-patterns
- ✅ cheapest-first + threshold escalation · explicit budget before batches · log routing · cache long prefixes.
- ✅ concise output instructions ("answer in N lines") — output tokens are 4–5× input price.
- ✗ one expensive model for everything · retry on auth/validation errors · mutating cost state · hardcoded model strings scattered in code (use constants/config) · ignoring caching on repeated system prompts.
Sources
Adapted from ECC skills/cost-aware-llm-pipeline (MIT); model tiers/caching per the installed claude-api
working-with-claudeskills; budget framing from practical cost-telemetry experience with shared provider keys.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

