cost-aware-llm-pipeline

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

Updated Jul 16, 2026
One-click install
npx skills add https://github.com/pjherron/hypoc --skill cost-aware-llm-pipeline-pjherron
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cost-aware-llm-pipeline
Source: https://github.com/pjherron/hypoc/tree/main/hypoc/skills/cost-aware-llm-pipeline
Command: npx skills add https://github.com/pjherron/hypoc --skill cost-aware-llm-pipeline-pjherron

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires anthropic.

What problem does it solve? LLM API costs grow quickly 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 while preserving output 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 text-length and item-count thresholds. - Immutable Budget Tracking: Track cumulative spend with frozen dataclasses and enforce hard budget limits that fail early before overspending. - Narrow Retry Logic: Retry only transient failures (rate limits, connection errors, server errors) with exponential backoff, failing fast on authentication or validation errors. - Prompt Caching: Cache long system prompts with ephemeral cache control to cut both cost and latency. - Use Case: When processing a batch of 500 documents through the Claude API, route small documents to Haiku, enforce a $1.00 budget cap, and cache the shared system prompt to reduce total spend by a large margin. ## Quick Start Use the cost-aware-llm-pipeline skill to add model routing, budget limits, retry handling, and prompt caching to my Claude API batch processing script.

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 a Python application?▼

Route requests by task complexity so simple tasks use cheaper models like Haiku and only complex tasks use Sonnet or Opus. Combine this with prompt caching for long system prompts and hard budget limits to prevent overspending.

How to choose between Claude Haiku, Sonnet, and Opus for a task?▼

Select the model based on input size and item count thresholds: Haiku for simple tasks, Sonnet when text exceeds roughly 10,000 characters or 30 items. Haiku costs about 4x less than Sonnet and 19x less than Opus per token.

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 fail immediately to avoid wasting budget.

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 recommended for system prompts over 1024 tokens.

Why use immutable dataclasses for cost tracking?▼

Frozen dataclasses ensure each API call returns a new tracker instead of mutating shared state, which makes debugging and auditing spend straightforward. The tracker exposes total cost and an over-budget check for enforcing limits.