llm-cost-optimizer
できること
有料のAIモデルを使うアプリを見直し、ルーティング、プロンプトのキャッシュ、トークンの上限、コストの追跡を設定します。AI機能を作っていて、請求を管理したいチーム向けです。
使う場面
- ✓AI機能を作っていて、公開前にコストの管理を整えたいとき。
- ✓AIの請求が増えていて、どの機能が原因か調べる必要があるとき。
- ✓単純なリクエストには、より安いモデルを使いたいとき。
スキルのリンク
https://github.com/alirezarezvani/claude-skills/blob/main/engineering/llm-cost-optimizer/skills/llm-cost-optimizer/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のAI機能のAPIの支出がどこに使われているかを見つけ、品質を下げずに削減する手伝いをしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントはまず支出が発生している場所を見つけ、モデルのルーティング、キャッシュ、トークンの上限などの的を絞った修正を適用し、結果を監視するためのログを設定します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
LLM Cost Optimizer
You are an expert in LLM cost engineering with deep experience reducing AI API spend at scale. Your goal is to cut LLM costs by 40–80% without degrading user-facing quality -- using model routing, caching, prompt compression, and observability to make every token count.
AI API costs are engineering costs. Treat them like database query costs: measure first, optimize second, monitor always.
Step 0: Classify Before You Ask
Before gathering context, classify which mode applies based on what the user has already said. Pull answers from the conversation first -- don't ask for what you already have.
| Mode | When to use |
|---|---|
| Cost Audit | Spend exists but no clear picture of where it goes |
| Optimize Existing System | Cost drivers are known; apply targeted fixes |
| Design Cost-Efficient Architecture | Building new AI features; wire in cost controls before launch |
If the mode is ambiguous, ask in one shot using the context questions below. Only ask what you don't already know.
Context You Need
Current State
- Which LLM providers and models are in use?
- Monthly spend? Which features/endpoints drive it?
- Token usage logging in place? Cost-per-request visibility?
Goals
- Target cost reduction? (e.g., "cut 50%", "stay under $X/month")
- Latency constraints? (affects caching and routing tradeoffs)
- Quality floor? (what degradation is acceptable?)
Workload Profile
- Request volume and distribution (p50, p95, p99 token counts)?
- Repeated or similar prompts? (caching potential)
- Mix of task types? (classification vs. generation vs. reasoning)
Mode 1: Cost Audit
Use when spend exists but the breakdown is unknown. Instrument first; optimize second.
Step 1 -- Instrument Every Request
Log per-request: model, input tokens, output tokens, latency, endpoint/feature, user segment, cost (calculated).
Step 2 -- Find the 20% Causing 80% of Spend
Sort by: feature × model × token count. Usually 2–3 endpoints drive the majority of cost. Target those first.
Step 3 -- Classify Requests by Complexity
| Complexity | Characteristics | Right Model Tier |
|---|---|---|
| Simple | Classification, extraction, yes/no, short output | Small (Haiku tier, or your provider's cheapest) |
| Medium | Summarization, structured output, moderate reasoning | Mid (Sonnet tier) |
| Complex | Multi-step reasoning, code gen, long context | Large (Opus tier, or your provider's frontier model) |
Tiers, not model names: the naming churns every few months, the three-tier shape does not. Check your provider's current lineup and price list when you apply this.
If token logging doesn't exist yet: That's the first deliverable -- not prompt compression, not routing. You cannot optimize what you cannot see. Provide a logging schema and move to optimization only once baseline data exists.
Mode 2: Optimize Existing System
Apply techniques in ROI order. Don't skip ahead -- measure impact at each step before moving to the next.
1. Model Routing (60–80% cost reduction on routed traffic)
Route by task complexity, not by default. Use a lightweight classifier or rule engine.
- Small models: classification, extraction, simple Q&A, formatting, short summaries
- Mid models: structured output, moderate summarization, code completion
- Large models: complex reasoning, long-context analysis, agentic tasks, code generation
Even routing 20% of traffic to a cheaper model produces meaningful savings. Start there.
2. Prompt Caching (40–90% reduction on cacheable traffic)
Supported by Anthropic (cache_control), OpenAI (automatic on some models), Google (context caching).
Cache-eligible content: system prompts, static context, document chunks, few-shot examples.
Target hit rates: >60% for document Q&A, >40% for chatbots with static system prompts.
Flag immediately if a system prompt exceeds ~2,000 tokens and is sent on every request -- this is a high-value caching target.
3. Output Length Control (20–40% reduction)
LLMs over-generate by default. Force conciseness:
- Explicit length instructions: "Respond in 3 sentences or fewer."
- Schema-constrained output: JSON with defined fields beats free-text
max_tokenshard caps: set per endpoint, not globally- Stop sequences: define terminators for list and structured outputs
Flag immediately if max_tokens is not set per endpoint -- every uncapped endpoint is a cost leak.
4
よくある質問
回答の品質が下がりますか?
ユーザーに見える品質を損なわずにコストを削ることを目指し、確認のための品質の下限を設定します。
最初にコスト監査が必要ですか?
必ずしもそうではありません。このスキルは、あなたがすでに話した内容を使い、不足している詳細だけを尋ねます。
最初に何をしますか?
依頼を、監査、既存システムの最適化、新規設計のいずれかに分類してから、何かを尋ねます。
詳細
作者による元の説明
Use whenever an LLM feature is being built or its costs come up (model choice, prompt caching, token limits, per-feature spend). Sets routing, caching, max_tokens and cost logging before launch rather than after the bill.
人気
- GitHubのスター
- 29k
- ランキング
- #9565
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
agent-launcher-orchestrator
29kひとつの明確な目標から始めて、自分のアカウントでClaudeのマネージドエージェントを計画し、作成し、テストし、スケジュールするまでを段階的に支援します。
grade-iterate
29kマネージドエージェントの作業をルーブリックに照らして採点し、固定された回数だけ改善させることで、終わりなく繰り返さないようにします。
interview
29kAIエージェントのアイデアについてインタビューし、回答をもとに、何かを起動する前の構築計画にまとめます。
run-without-you
29kマネージドエージェントを、スケジュールまたはイベントの発生によってあなたがいなくても動くように設定します。起動の前にcronの時刻を確認します。
似ているスキル
writing-skills
311k新しいスキルを書き、それぞれをまず試すようエージェントに教えます。そのスキルが実際にエージェントの動作を変えることを確認します。
writing-for-agents
310kスキル、AGENTS.md、CLAUDE.mdを含め、AIエージェントのための明確な指示の書き方を説明し、エージェントが予測可能に動くようにします。
bengali-nlp
280kエージェントがベンガル語のテキストを処理できるようにします。テキストの正規化など、ベンガル語特有の性質に対応しながら、言語を理解して扱えるようにします。