affaan-m avatar

Cost Aware Llm Pipeline

Cost-aware-llm-pipeline provides developers building LLM-powered applications with patterns to optimize API costs while maintaining output quality, using model routing by task complexity, immutable budget tracking, targeted retry logic, and prompt caching. It solves the problem of controlling expenses when processing variable-complexity workloads across multiple LLM API calls without sacrificing performance on demanding tasks. The skill is designed for teams processing batch items or high-volume API usage who need to stay within defined budgets.

skills.sh installs
5.4K
GitHub stars
229.1K
last updated
Jul 14, 2026

Install

$ npx -y skills add affaan-m/everything-claude-code --skill cost-aware-llm-pipeline --agent claude-code

Installs 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/everything-claude-code
Categories
DevOps & CI/CD, AI & Agent Building, Automation & Workflows, Sales & Marketing

More from affaan-m/everything-claude-code

All 256
1affaan-m avatarralphinho-rfc-pipelineaffaan-m/eccRFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.5.4Kskills.sh installs
2affaan-m avatarrecsys-pipeline-architectaffaan-m/eccDesign composable recommendation, ranking, and feed pipelines using the six-stage Source→Hydrator→Filter→Scorer→Selector→SideEffect framework popularized by xAI5.4Kskills.sh installs
3forcedotcom avatardx-devops-test-failures-analyzeforcedotcom/sf-skillsAnalyzes DevOps Center test failures and Code Analyzer violations in plain language — failure category, offending file/class/method/line, rule violated, fix dir5.1Kskills.sh installs
4hashicorp avatarterraform-search-importhashicorp/agent-skillsDiscover existing cloud resources using Terraform Search queries and bulk import them into Terraform management. Use when bringing unmanaged infrastructure unde5.1Kskills.sh installs
5recoupable avatarrecoup-platform-build-osrecoupable/skillsScaffold and run a label's self-managing "music-company OS" inside its own git repo — the full label-intelligence workspace (folders, a self-managing CLAUDE.md 5.1Kskills.sh installs
6boristane avatarlogging-best-practicesboristane/agent-skillslogging best practices5Kskills.sh installs