Skills

LLM Cost Optimization

Reduce LLM API and infrastructure costs through model selection, prompt caching...

Install

npx skills add BagelHole/DevOps-Security-Agent-Skills --skill llm-cost-optimization -g -a claude-code -y
Category
AI and agents
Updated
6mo ago
License
MIT
Context cost
Mediumabout 2,157 tokens
Runs scripts
No, instructions only

What it does

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.

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

StrategyTypical SavingsEffort
Semantic caching20, 50%Low
Model right-sizing30, 70%Low
Prompt compression10, 30%Medium
Provider caching (prompt cache)10, 25%Low
Batching offline workloads50% (Batch API)Medium
Self-hosting 7, 8B models80, 95% at scaleHigh
Quantization30, 50% VRAM costMedium

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 callbacks
def log_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]

Model Right-Sizing

Read the whole SKILL.md on GitHub

More in AI and agents