llm-cost-optimization

llm-cost-optimization is a skill for Claude Code, Codex from BagelHole/DevOps-Security-Agent-Skills. It costs 49 tokens per session (2,428 once invoked), scanned A, original, MIT.

A set of ways to reduce the cost of using large language models through APIs or your own servers. It covers choosing models, shortening prompts, caching repeated work, batching jobs, quantizing models, and tracking spending.

In plain words
What is it for?
Use it to measure AI spending, set budgets, choose lower-cost models, cache repeated requests, process offline work in batches, or assess self-hosting.
Why use it?
It helps identify which teams, products, or models are driving AI costs and reduces unnecessary model calls or oversized infrastructure.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it to measure AI spending, set budgets, choose lower-cost models, cache repeated requests, process offline work in batches, or assess self-hosting.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/bagelhole/devops-security-agent-skills/llm-cost-optimization
About the project

DevOps & Security Agent Skills is a knowledge base of agent-readable skills covering software delivery, cloud infrastructure, security, compliance, AI operations, and incident response. It is for SRE, platform, infrastructure, and security teams using agents to work with systems such as Kubernetes, Terraform, and major cloud platforms. The catalogue provides a selection of the project's skills for agents including Claude Code, Cursor, and Codex.

BagelHole/DevOps-Security-Agent-Skills · 1,229 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill llm-cost-optimization
Clone the repo
git clone --depth 1 https://github.com/BagelHole/DevOps-Security-Agent-Skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for llm-cost-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization/github.svg)](https://agentmods.dev/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization)
Your own site
<a href="https://agentmods.dev/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization"><img src="https://agentmods.dev/badge/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for llm-cost-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization"><img src="https://agentmods.dev/badge/skills/bagelhole/devops-security-agent-skills/llm-cost-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 49 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,428 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00049 $0.02428
Opus 5.5 $0.00020 $0.00971
Sonnet 5.5 $0.00010 $0.00486
Haiku 4.5 $0.00005 $0.00243

Measured 3mo ago against content hash 93152256a3f7, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

llm-cost-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

devops/ai/llm-cost-optimization/SKILL.md · 287 lines

How it starts

The opening of the file, as written. The whole thing — 287 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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 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

# Route by task complexity — don't use GPT-4o for everything
def get_model_for_task(task_type: str) -> str:
    routing = {
        "classification":     "gpt-4o-mini",      # ~30× cheaper than gpt-4o
        "summarization":      "gpt-4o-mini",
        "extraction":         "gpt-4o-mini",
        "simple_qa":          "gpt-4o-mini",
        "complex_reasoning":  "gpt-4o",
        "code_generation":    "claude-sonnet-4-6",
        "creative_writing":   "claude-opus-4-6",
    }
    return routing.get(task_type, "gpt-4o-mini")

# Cost comparison (per 1M tokens, 2025 approx.)
# gpt-4o-mini:          input $0.15 / output $0.60
# gpt-4o:               input $2.50 / output $10.00
# claude-sonnet-4-6:    input $3.00 / output $15.00
# llama-3.1-8b (self):  ~$0.05–0.10 all-in (GPU amortized)

Read the full file on GitHub · 287 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 287 lines · 49 tokens per session scan A 93152256a3f7

Subscribe to this mod's changes

llm-cost-optimization is a skill published in the GitHub repository BagelHole/DevOps-Security-Agent-Skills (1,229 stars, last pushed 6mo ago), licensed MIT. It adds 49 tokens to every session and 2,428 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

llm-cost-optimization compared with skills from other repositories

llm-cost-optimization next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
llm-cost-optimizationBagelHole/DevOps-Security-Agent-SkillsSkill1.2k6mo agoMITA49Claude Code, Codex
implementing-aws-macie-for-data-classificationxalgorix/xalgorixSkill1.5kyesterdayApache-2.0A46Claude Code, Codex
bedrockitsmostafa/aws-agent-skillsSkill1.2k6d agoMITA36Claude Code
agentic-eks-bootstrapaws-samples/sample-oh-my-aidlcopsSkill2228d agoMIT-0A91Claude Code
ai-gateway-guardrailsaws-samples/sample-oh-my-aidlcopsSkill2228d agoMIT-0A83Claude Code
gpu-resource-managementaws-samples/sample-oh-my-aidlcopsSkill2228d agoMIT-0A76Claude Code
inference-gateway-routingaws-samples/sample-oh-my-aidlcopsSkill2228d agoMIT-0A84Claude Code