llm-cost-optimizer
Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Runs a systematic checklist review on any code diff or file, covering correctness, security, performance, and readability.
Writes a high-quality CLAUDE.md, .cursorrules, or .windsurfrules file that gives a coding agent the right project context, conventions, and constraints to work effectively.
Designs an eval suite for an LLM agent or pipeline including success metrics, trajectory scoring, LLM-as-judge setup, and regression test cases.
Designs a hybrid retrieval pipeline combining dense vector search and BM25 sparse search with reciprocal rank fusion, and explains when to use each configuration.
Converts a workflow description into a LangGraph node/edge graph with typed state, conditional routing, and human-in-the-loop checkpoints.
Configures end-to-end tracing for an LLM application using OpenTelemetry with LangSmith, Langfuse, or Helicone — span naming, metadata tagging, latency thresholds, and cost tracking.
| name | LLM Cost Optimizer |
| description | Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs. |
| category | devops |
| tags | ["llm-ops","cost-optimization","prompt-caching","model-routing","tokens"] |
| author | simplyutils |
This skill audits an LLM application's prompts, call patterns, and model selection to identify cost reduction opportunities. It covers prompt caching, model routing (right-sizing), token reduction, batching, and output length control — the techniques that typically cut LLM costs by 40–80% without sacrificing quality.
Copy this file to .agents/skills/llm-cost-optimizer/SKILL.md in your project root.
Then ask:
Provide:
Paste your prompts, call patterns, and current monthly spend alongside these instructions.
When asked to optimize LLM costs, audit the following areas in order of typical savings impact:
Check: Does the system prompt stay the same across calls?
If yes, enable prompt caching. The system prompt is sent once and cached — subsequent calls only pay for the new user tokens.
# Anthropic Claude — cache_control on system prompt
response = client.messages.create(
model="claude-opus-4-6",
system=[{
"type": "text",
"text": your_system_prompt,
"cache_control": {"type": "ephemeral"} # cached for 5 minutes
}],
messages=[{"role": "user", "content": user_message}]
)
# OpenAI — automatic prompt caching for prompts > 1024 tokens
# No code change needed — cached automatically, check usage.prompt_tokens_details.cached_tokens
When it applies: Any app where the system prompt is > 1024 tokens and reused across calls. Support bots, coding assistants, document analyzers.
Savings estimate: If system prompt = 2000 tokens, 10,000 calls/day → saves ~20M tokens/day in input costs.
Check: Are you using a frontier model (GPT-4o, Claude Opus) for tasks that a smaller model handles just as well?
| Task | Recommended Model |
|---|---|
| Classification, routing, yes/no decisions | GPT-4o-mini, Claude Haiku |
| Summarization, extraction, translation | GPT-4o-mini, Claude Sonnet |
| Complex reasoning, code generation | GPT-4o, Claude Sonnet |
| Novel research, multi-step agent planning | Claude Opus, o1 |
Implement a model router:
def route_model(task_type: str, complexity: str) -> str:
if task_type in ("classify", "extract", "translate"):
return "claude-haiku-4-5-20251001"
if complexity == "high" or task_type == "code_generation":
return "claude-sonnet-4-6"
return "claude-haiku-4-5-20251001" # default to cheap
Check: Is the system prompt longer than it needs to be?
Common bloat patterns:
Token reduction techniques:
max_tokens to the minimum needed:# If you only need a one-sentence answer, cap it
response = client.messages.create(max_tokens=100, ...)
Check: Do users ask similar questions repeatedly?
Cache model responses by a hash of the (system_prompt + user_input) pair:
import hashlib, json
def get_cached_or_call(system: str, user: str) -> str:
key = hashlib.sha256(f"{system}:{user}".encode()).hexdigest()
cached = redis_client.get(key)
if cached:
return json.loads(cached)
response = call_llm(system, user)
redis_client.setex(key, 3600, json.dumps(response)) # cache 1hr
return response
Use semantic similarity for fuzzy cache hits if exact-match cache rate is low.
Check: Are you running background jobs (document processing, bulk analysis) one-at-a-time?
Both OpenAI and Anthropic offer Batch APIs at 50% discount for async workloads:
# Anthropic Batch API
batch = client.messages.batches.create(
requests=[
{"custom_id": f"doc_{i}", "params": {"model": "...", "messages": [...]}}
for i, doc in enumerate(documents)
]
)
# Results available within 24hrs at 50% of standard price
Use when: processing 100+ documents, nightly summarization jobs, bulk classification.
Check: Are you streaming responses but storing the full output anyway?
If you don't need to stream to the user, disable streaming — it has slightly higher overhead for short responses. Only stream when showing real-time output to users.
After auditing, produce a cost breakdown:
| Optimization | Monthly Savings Estimate | Effort |
|---|---|---|
| Prompt caching | $X | Low |
| Switch summarization to Haiku | $X | Low |
| Cap max_tokens on short-answer routes | $X | Low |
| Response caching (top 20% queries) | $X | Medium |
| Batch API for nightly jobs | $X | Medium |
| Total | $X |
Input:
"We use Claude Opus for everything. System prompt is 3000 tokens. We do 5000 calls/day for customer support — mostly classifying intent and drafting short replies."
Output:
Critical finding: Wrong model for workload. Intent classification and short reply drafting = Haiku-level tasks. Switching to claude-haiku-4-5-20251001 saves ~85% per token.
Prompt caching: 3000-token system prompt × 5000 calls = 15M cached tokens/day. Enable
cache_controlon your system prompt.Combined monthly savings estimate: ~$2,800/month based on Anthropic pricing, down from ~$3,400 to ~$600.