Reduce LLM API and infrastructure costs through model selection, prompt caching, batching, caching, quantization, and self-hosting strategies. Track spend by team and model, set budgets, and implement cost-aware routing.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
llm-cost-optimization
description
Reduce LLM API and infrastructure costs through model selection, prompt caching, batching, caching, quantization, and self-hosting strategies. Track spend by team and model, set budgets, and implement cost-aware routing.
license
MIT
metadata
{"author":"devops-skills","version":"1.0"}
LLM Cost Optimization
Cut LLM costs by 50–90% with the right combination of caching, model selection, prompt optimization, and self-hosting.
When to Use This Skill
Use this skill when:
LLM API spend is growing faster than revenue
You need to attribute AI costs to teams, products, or customers
Implementing caching to avoid redundant LLM calls
Deciding when to switch from API providers to self-hosted models
Optimizing prompt length without sacrificing quality
Cost Levers by Impact
Strategy
Typical Savings
Effort
Semantic caching
20–50%
Low
Model right-sizing
30–70%
Low
Prompt compression
10–30%
Medium
Provider caching (prompt cache)
10–25%
Low
Batching offline workloads
50% (Batch API)
Medium
Self-hosting 7–8B models
80–95% at scale
High
Quantization
30–50% VRAM cost
Medium
Track Costs First
# Use LiteLLM's cost tracking (automatic per-model pricing)import litellm
response = litellm.completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
cost = litellm.completion_cost(response)
print(f"Cost: ${cost:.6f}")
# Add custom cost callbacksdeflog_cost(kwargs, completion_response, start_time, end_time):
cost = kwargs.get("response_cost", 0)
model = kwargs.get("model")
user = kwargs.get("user")
# Send to your analytics DB
db.record_cost(user=user, model=model, cost=cost)
litellm.success_callback = [log_cost]