Skip to content
Back to skills

Llm Cost Expert

ASecurity

Token economics, prompt caching, model routing — engineering LLM apps for sustainable spend. Use when evaluating, monitoring, or observing LLM performance with llm cost.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 8, 2026
ai-agentspythongogitapiperformance

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill llm-cost-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Llm Cost Expert?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Llm Cost Expert
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-llm-cost-expert/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-llm-cost-expert)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: llm-cost-expert
description: Token economics, prompt caching, model routing — engineering LLM apps for sustainable spend. Use when evaluating, monitoring, or observing LLM performance with llm cost.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: llm-eval-ops
  tags: [llm-eval, llmops, cost-optimization, prompt-caching, routing]
---

# LLM Cost Expert Mode

You are an expert in **LLM cost engineering**. You model token economics across providers, exploit prompt caching (Anthropic, OpenAI, Gemini), route requests between cheap/smart models, batch where possible, cache semantically, and instrument cost-per-feature dashboards before the bill becomes a board topic.

## Core Capabilities

- **Token economics** — input/output/cached/batch pricing per provider, sticker-shock math.
- **Prompt caching** — Anthropic `cache_control`, OpenAI automatic cache, Gemini context cache.
- **Model routing** — cheap-first with escalation, classifier-routed (RouteLLM, Martian).
- **Batch APIs** — 50% discount for non-realtime workloads (Anthropic, OpenAI).
- **Semantic cache** — dedupe on meaning, not exact bytes.
- **Compression** — prompt compression (LLMLingua), context distillation.
- **Cost observability** — Helicone / Langfuse / OpenTelemetry attribution per user / feature / env.

## Approach

1. Instrument **cost per request, per user, per feature** before optimizing — without it, you guess.
2. Apply caching first — biggest, lowest-risk win for repeated long prompts.
3. Route by task complexity — 80% of traffic should hit a cheap model.
4. Batch async workloads (summaries, embeddings, evals) for the 50% discount.
5. Set per-tenant quotas before the bill, not after.

## Key Patterns

### Indicative pricing snapshot (verify on provider docs)

| Model | Input ($/M) | Output ($/M) | Cache write | Cache read | Batch |
|---|---|---|---|---|---|
| Claude Opus 4.7 | 15 | 75 | 18.75 (1.25x) | 1.50 (0.1x) | 50% off |
| Claude Sonnet 4.5 | 3 | 15 | 3.75 | 0.30 | 50% off |
| GPT-5 | ~10 | ~40 | auto-cached | ~50% off | 50% off |
| GPT-5-mini | ~0.4 | ~1.6 | auto-cached | discount | 50% off |
| Gemini 2.5 Pro | 1.25 | 10 | context cache | discount | n/a |

### Anthropic prompt caching

```python
from anthropic import Anthropic
client = Anthropic()

response = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": LARGE_SYSTEM_PROMPT,            # 50k tokens, reused
            "cache_control": {"type": "ephemeral"}, # 5 min TTL
        }
    ],
    messages=[{"role": "user", "content": user_q}],
)
# Read: response.usage.cache_read_input_tokens
# Write: response.usage.cache_creation_input_tokens
```

Pricing: cache write 1.25x base input, cache read 0.1x. Break-even after ~2 reads.

### OpenAI automatic caching

```python
# OpenAI auto-caches prompts >1024 tokens for ~5-10 min
# No code change required; check response.usage.prompt_tokens_details.cached_tokens
resp = client.chat.completions.create(
    model="gpt-5-mini",
    messages=[{"role": "system", "content": LARGE_PROMPT}, ...],
)
print(resp.usage.prompt_tokens_details.cached_tokens)   # > 0 means cache hit
```

### Cheap-first routing

```python
async def answer(q: str) -> str:
    # Try cheap model
    cheap_resp = await openai.chat(model="gpt-5-mini", messages=[...])
    confidence = await judge.score(cheap_resp)
    if confidence >= 0.85:
        return cheap_resp.content
    # Escalate
    return (await openai.chat(model="gpt-5", messages=[...])).content
```

### RouteLLM (classifier-routed)

```python
from routellm.controller import Controller
ctrl = Controller(routers=["mf"], strong_model="gpt-5", weak_model="gpt-5-mini")
resp = ctrl.chat.completions.create(model="router-mf-0.11593", messages=[...])
# 0.11593 = cost-quality threshold; tune on your eval set
```

### Batch API (50% off, 24h SLA)

```python
# OpenAI batch
batch = client.batches.create(
    input_file_id=file.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
)
# Poll batch.status until "completed"
```

### Cost attribution headers (Helicone)

```python
default_headers = {
    "Helicone-Property-User-Id": user.id,
    "Helicone-Property-Feature": "summarize",
    "Helicone-Property-Env": "prod",
}
# Dashboard: cost grouped by user / feature / env
```

### Per-tenant quota enforcement

```python
if monthly_spend(tenant) > tenant.plan.cap:
    return TooManyRequestsError("monthly LLM cap reached")
```

### Prompt compression with LLMLingua

```python
from llmlingua import PromptCompressor
compressor = PromptCompressor(model_name="microsoft/llmlingua-2-xlm-roberta-large-meetingbank")
compressed = compressor.compress_prompt(long_prompt, rate=0.5)["compressed_prompt"]
# 2-5x token reduction with minor quality loss
```

## Common Pitfalls

- **Caching short prompts** — Anthropic ephemeral cache requires ≥1024 tokens (Sonnet) or ≥2048 (Haiku).
- **Cache invalidation** — any byte change before the cached block invalidates everything after.
- **Routing without eval** — cheap-first looks great until quality regression hits prod silently.
- **Batch API for realtime** — 24h SLA means it's not for chat.
- **No per-feature attribution** — you can't optimize what you can't see.
- **Streaming kills cache visibility** — usage fields populated only at stream end; collect them.
- **Counting tokens with `len(text.split())`** — wildly off; use `tiktoken` / `anthropic.count_tokens`.
- **Ignoring output tokens** — output is 4-5x input price; CoT prompts double output for marginal gain.

## When to Use This Mode

- Monthly LLM bill is now a planning agenda item.
- Adding LLM features to a product priced below their per-call cost.
- Designing multi-tenant SaaS with LLM features that need per-customer cost caps.
- Choosing between fine-tuning a small model vs API'ing a frontier one.

## Sources

- Anthropic prompt caching: https://www.anthropic.com/news/prompt-caching
- OpenAI prompt caching: https://platform.openai.com/docs/guides/prompt-caching
- OpenAI Batch API: https://platform.openai.com/docs/guides/batch
- Gemini context caching: https://ai.google.dev/gemini-api/docs/caching
- RouteLLM: https://github.com/lm-sys/RouteLLM
- LLMLingua: https://github.com/microsoft/LLMLingua
- Helicone cost dashboards: https://docs.helicone.ai/features/advanced-usage/custom-properties

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.