affaan-m avatar

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-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/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
1mongodb avatarmongodb-connectionmongodb/agent-skillsOptimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language. Use this skill when working/updating/reviewing o5.6Kskills.sh installs
2jeffallan avatarplaywright-expertjeffallan/claude-skillsUse when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects,5.6Kskills.sh installs
3affaan-m avatardata-scraper-agentaffaan-m/eccBuild a fully automated AI-powered data collection agent for any public source — job boards, prices, news, GitHub, sports, anything. Runs on a schedule, enriche5.6Kskills.sh installs
4github avatarweb-codergithub/awesome-copilotExpert 10x engineer with comprehensive knowledge of web development, internet protocols, and web standards. Use when working with HTML, CSS, JavaScript, web API5.5Kskills.sh installs
5ghostsecurity avatarghost-scan-codeghostsecurity/skillsGhost Security - SAST code scanner. Finds security vulnerabilities in source code by planning and executing targeted scans for issues like SQL injection, XSS, B5.5Kskills.sh installs
6forcedotcom avatarintegration-connectivity-connected-app-configureforcedotcom/sf-skillsSalesforce Connected Apps and External Client Apps OAuth configuration with 120-point scoring. Use this skill to configure OAuth flows, JWT bearer auth, Connect5.5Kskills.sh installs