LLM Cost Optimizer
Skill9 starsChanged 8 months agoMITView on GitHub
Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs.
In this repository61 other files it gives its agents.
- Accessibility Audit HelperSkill
- Agent Context File WriterSkill
- Agent Evaluation Framework BuilderSkill
- AI Feature Spec WriterSkill
- API Documentation GeneratorSkill
- REST API Endpoint DesignerSkill
- Architecture ExplainerSkill
- Article RepurposerSkill
- Auth Flow PlannerSkill
- Blog Outline GeneratorSkill
- Breaking Change DetectorSkill
- Bug Root Cause AnalyzerSkill
- Caching Strategy AdvisorSkill
- Changelog CuratorSkill
- Code Review ChecklistSkill
- Database Schema ReviewerSkill
- Docker Compose GeneratorSkill
- Documentation Gap FinderSkill
- Edge Case DiscoverySkill
- Error Log SummarizerSkill
- FAQ GeneratorSkill
- Flaky Test AnalyzerSkill
- Form UX OptimizerSkill
- Git Commit WriterSkill
- Hallucination Risk ReviewerSkill
- Hybrid Search ArchitectSkill
- Incident Postmortem WriterSkill
- Issue to PR PlannerSkill
- Landing Page Copy ImproverSkill
- LangGraph State Machine DesignerSkill
- LLM Tracing and Observability SetupSkill
- MCP Integration AssistantSkill
- MCP Server BuilderSkill
- Migration Guide WriterSkill
- Newsletter Summary WriterSkill
- Observability ChecklistSkill
- Playwright Test BuilderSkill
- PR Description WriterSkill
- Prompt Injection Defense AuditorSkill
- Prompt RefinerSkill
- Prompt Version Control WorkflowSkill
- RAG Chunking Strategy AdvisorSkill
- RAG Workflow PlannerSkill
- React Component ReviewerSkill
- README WriterSkill
- Refactor PlannerSkill
- Release Notes GeneratorSkill
- Responsive Layout ReviewerSkill
- SDK Quickstart WriterSkill
- SEO Content OptimizerSkill
- SEO Metadata GeneratorSkill
- Social Post Thread WriterSkill
- Sprint Summary GeneratorSkill
- SQL Query OptimizerSkill
- Stack Trace AnalyzerSkill
- Technical Blog Post WriterSkill
- Tech Debt AuditorSkill
- Troubleshooting Guide BuilderSkill
- Unit Test ImproverSkill
- Unit Test WriterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 43
When asked to optimize LLM costs, audit the following areas in order of typical savings impact:
- Distinctive: line 49
If yes, enable prompt caching.
- Distinctive: line 69
Savings estimate: If system prompt = 2000 tokens, 10,000 calls/day → saves ~20M tokens/day in input costs.
- Distinctive: line 115
Check: Do users ask similar questions repeatedly?
- Distinctive: line 133
Use semantic similarity for fuzzy cache hits if exact-match cache rate is low.
- Distinctive: line 152
Use when: processing 100+ documents, nightly summarization jobs, bulk classification.
- Distinctive: line 158
If you don't need to stream to the user, disable streaming — it has slightly higher overhead for short responses.
- Distinctive: line 162
After auditing, produce a cost breakdown:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
LLM Cost Optimizer
What this skill does
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.
How to use
Claude Code / Cline
Copy this file to .agents/skills/llm-cost-optimizer/SKILL.md in your project root.
Then ask:
- "Use the LLM Cost Optimizer to audit our AI application."
- "How can I reduce our OpenAI API costs? Here are our prompts..."
Provide:
- Your system prompt(s)
- Approximate daily call volume
- Which model(s) you're using
- Typical input/output token counts if known
- Whether calls are real-time (low latency required) or batch (latency tolerant)
Cursor / Codex
Paste your prompts, call patterns, and current monthly spend alongside these instructions.
The Prompt / Instructions for the Agent
When asked to optimize LLM costs, audit the following areas in order of typical savings impact:
Audit 1 — Prompt Caching (savings: 50–90% on repeated prefixes)
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_tokensWhen 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.
Audit 2 — Model Right-Sizing (savings: 60–90% on over-specified models)
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 cheapAudit 3 — Token Reduction (savings: 20–40% on bloated prompts)
Check: Is the system prompt longer than it needs to be?
Common bloat patterns:
- Repeating the same instruction multiple ways ("Be concise. Keep answers short. Don't ramble.")
- Long examples when one would do
- Full document context when only a section is needed
- Verbose role descriptions
Token reduction techniques:
- Compress examples — use 1 example instead of 3 if the task is clear
- Use structured format — bullet points use fewer tokens than prose instructions
- Trim RAG context — retrieve top-3 chunks, not top-10; rerank before sending
- Limit output length — set
max_tokensto the minimum needed:
# If you only need a one-sentence answer, cap it
response = client.messages.create(max_tokens=100, ...)Audit 4 — Response Caching (savings: 30–70% for repetitive queries)
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 responseUse semantic similarity for fuzzy cache hits if exact-match cache rate is low.
Audit 5 — Batching (savings: 50% cost + latency for async workloads)
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 priceUse when: processing 100+ documents, nightly summarization jobs, bulk classification.
Audit 6 — Streaming Efficiency
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.
Cost Estimate Template
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 |
Example
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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

