cost-aware-llm-pipeline
Use when building an LLM-powered app that needs cost control via model routing, budget tracking, retry, and prompt caching.
npx skills add majiayu000/claude-skill-registry --skill cost-aware-llm-pipeline --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Cost-Aware LLM Pipeline # コスト最適化LLMパイプライン **Extracted / 抽出日:** 2026-02-08 **Context / コンテキスト:** LLMを使うアプリで、コスト制御しながら品質を維持するパターン --- ## Problem / 課題 LLM APIは高コスト。全リクエストに最高性能モデルを使うと予算超過する。 リトライやキャッシュの仕組みがないと無駄なコストが発生する。 - 単純なタスクにも高価なモデルを使ってしまう - 一時的なエラーでリトライせず失敗する - 同じシステムプロンプトを毎回送信しトークンを浪費する - 予算超過に気づかない --- ## Solution / 解決策 4つの要素を組み合わせる: ### 1. Model Routing(モデル自動選択) タスクの複雑度に基づいてモデルを自動選択する。 ```python MODEL_SONNET = "claude-sonnet-4-5-20250929" MODEL_HAIKU = "claude-haiku-4-5-20251001" _SONNET_TEXT_THRESHOLD = 10_000 # chars _SONNET_CARD_THRESHOLD = 30 # items def select_model( text_length: int, item_count: int, force_model: str | None = None, ) -> str: """Automatically 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_CARD_THRESHOLD: return MODEL_SONNET # Complex task return MODEL_HAIKU # Simple task (3-4x cheaper) ``` ### 2. Immutable Cost Tracking(不変コスト追跡) ```python from dataclasses import dataclass @dataclass(frozen=True, slots=True) class CostRecord: model: str input_tokens: int output_tokens: int cost_usd: float @dataclass(frozen=True, slots=True) class CostTracker: budg
- Problem / 課題
- Solution / 解決策
- 1. Model Routing(モデル自動選択)
- 2. Immutable Cost Tracking(不変コスト追跡)
- 3. Narrow Retry Logic(限定的リトライ)
- 4. Prompt Caching(プロンプトキャッシュ)
- Composition / 組み合わせ方
- Pricing Reference (2025-2026) / 価格参考
- When to Use / 使用すべき場面
- Related Patterns / 関連パターン
What does the cost-aware-llm-pipeline skill do?
Use when building an LLM-powered app that needs cost control via model routing, budget tracking, retry, and prompt caching.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill cost-aware-llm-pipeline --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
