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
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.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.svg" alt="Measured on agentmods" 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 $0.00024 $0.01214
Sonnet 5 $0.00010 $0.00486
Haiku 4.5 $0.00005 $0.00243

Measured 8d ago against content hash 93152256a3f7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-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 8d 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. 8d 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,058 stars, last pushed 3mo ago), licensed MIT. It adds 49 tokens to every session and 2,428 once invoked, about $0.0002 per session on Opus 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

Other skills, from other repositories

bedrock

AWS Bedrock foundation models for generative AI. Use when invoking foundation models, building AI applications, creating embeddings, configuring model access, or implementing RAG patterns.

itsmostafa/aws-agent-skills · 36 tokens

implementing-aws-macie-for-data-classification

Implement Amazon Macie to automatically discover, classify, and protect sensitive data in S3 buckets using machine learning and pattern matching for PII, financial data, and credentials detection.

xalgorix/xalgorix · 46 tokens

agentic-eks-bootstrap

Bootstrap an AWS EKS cluster optimized for Agentic AI workloads — Karpenter v1.2+ GPU node pools, EKS Auto Mode, Kubernetes 1.32+ with DRA 1.35 GA, VPC CNI, GPU Operator, and baseline observability. Use when starting a new EKS cluster that will host vLLM, Inference Gateway, Langfuse, or Kagent.

aws-samples/sample-oh-my-aidlcops · 91 tokens

ai-gateway-guardrails

Enforce Input/Output Guardrails at the LLM Gateway layer — PII redaction, Prompt Injection defense, Jailbreak detection, Toxicity filter, and Tool Allow-list. Integrates Bedrock Guardrails, NeMo Guardrails, Llama Guard 3, and regex/regex-ML policies on Bifrost/LiteLLM with Langfuse audit trail.

aws-samples/sample-oh-my-aidlcops · 83 tokens

gpu-resource-management

Design GPU orchestration on EKS using Karpenter v1.2+ NodePools, KEDA scale-to-zero, and DRA 1.35 GA for multi-instance GPU (MIG) partitioning. Right-size NodePool for p5/g6e/trn2 instance mix, spot/on-demand split, consolidation, and topology-aware scheduling.

aws-samples/sample-oh-my-aidlcops · 76 tokens

inference-gateway-routing

Configure kgateway v2.0+ as L1 and Bifrost v1.x or LiteLLM v1.60+ as L2 for a 2-Tier Inference Gateway on EKS. Apply Cascade Routing (Haiku→Sonnet→Opus fallback), Semantic Router (intent-based model pick), and HTTPRoute with OTel trace propagation to Langfuse.

aws-samples/sample-oh-my-aidlcops · 84 tokens