cost-aware-llm-pipeline

Implements model routing, budget tracking, retry logic, and prompt caching for LLM API pipelines.

2|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/adamreger/ecc-antigravity --skill cost-aware-llm-pipeline-adamreger
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cost-aware-llm-pipeline
Source: https://github.com/adamreger/ecc-antigravity/tree/main/skills/cost-aware-llm-pipeline
Command: npx skills add https://github.com/adamreger/ecc-antigravity --skill cost-aware-llm-pipeline-adamreger

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires anthropic.

What problem does it solve? LLM API costs grow quickly in production applications, especially when every request uses the most expensive model, retries fire on permanent errors, and long system prompts are resent on every call. This Skill provides composable patterns for controlling spend without sacrificing quality on complex tasks. ## Core Features & Use Cases - Model Routing by Complexity: Automatically select cheaper models (e.g., Haiku) for simple tasks and reserve expensive models (e.g., Sonnet) for large inputs using configurable thresholds. - Immutable Budget Tracking: Track cumulative spend with frozen dataclasses and enforce budget limits before each API call, failing early instead of overspending. - Narrow Retry Logic: Retry only transient errors (rate limits, connection failures, server errors) with exponential backoff while failing fast on authentication or bad request errors. - Prompt Caching: Cache long system prompts with ephemeral cache control to reduce both cost and latency on repeated requests. - Use Case: When processing a batch of 500 documents through the Claude API, route small documents to Haiku, enforce a $1.00 budget cap, retry only on rate limits, and cache the shared system prompt to cut total spend by 3-4x. ## Quick Start Ask the AI to build a cost-aware LLM pipeline that routes requests between Haiku and Sonnet based on input size, tracks spend against a budget, and retries only transient API errors.

Frequently Asked Questions about cost-aware-llm-pipeline

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce LLM API costs in Python applications?▼

Route requests to cheaper models like Haiku for simple tasks and reserve expensive models like Sonnet for complex ones based on input size thresholds. Combine this with prompt caching for long system prompts and budget limits that fail early before overspending.

How to route requests between Claude Haiku and Sonnet models?▼

Define thresholds on text length and item count, then select the model programmatically. For example, inputs over 10,000 characters or 30 items route to Sonnet, while smaller inputs use Haiku at roughly one quarter of the cost.

Which API errors should be retried when calling Claude?▼

Retry only transient errors: APIConnectionError, RateLimitError, and InternalServerError, using exponential backoff. Authentication and bad request errors are permanent and should raise immediately to avoid wasting budget on doomed retries.

Does prompt caching reduce Claude API costs?▼

Yes, marking long system prompts with ephemeral cache_control avoids resending them on every request, reducing both cost and latency. It is most effective for system prompts over 1024 tokens reused across many calls.

Why use immutable dataclasses for API cost tracking?▼

Frozen dataclasses ensure each API call returns a new tracker rather than mutating shared state, making spend auditing and debugging straightforward. The tracker exposes total_cost and over_budget properties for enforcing budget limits before each call.