# AI Cost Optimization Playbook

> [View this product on lib-pro](https://lib-pro-3f8437.gitlab.io/libs/cost-optimization) · Cut your LLM costs by 60-90%. Without sacrificing quality.

**Outcome:** Cut LLM costs by 60-90% without sacrificing quality.

5 skills for cutting LLM API costs without sacrificing quality: the optimization funnel (cache → token → model → batch → fine-tune), token economics, model selection, caching strategies, and FinOps for LLMs. The methodology behind the Buzzfeed 80% cost reduction, packaged as a SKILL.md bundle.

**Price:** £35 — lifetime · **Category:** Production AI Skills · **Tech:** pi-agent, Claude Code, Cursor, Cline, Markdown, OpenAI, Anthropic, Google (vendor-agnostic)

| Metric | Value |
|--------|-------|
| Skills | 5 |
| Layers | 5 |
| Typical savings | 60-90% |

## Quick start

```bash
tar -xzf cost-optimization-0.1.0.tgz && cd cost-optimization-0.1.0
```

- # Pick your agent host
- ls adapters/
- # pi-agent: cp -r skills/* ~/.pi/agent/skills/

## Code preview

```
# cost-optimization — The Optimization Funnel

The cheapest LLM call is the one you don't make. The second cheapest is the one that's 100x smaller.

## The 5-Layer Funnel

Apply in order — each layer saves 30-60% when applied.

1. **Stop unnecessary calls** (caching, deduplication) — biggest win, 50-90% reduction
2. **Reduce call size** (token optimization) — second biggest, 20-50% reduction
3. **Use cheaper models** (model selection) — quality-dependent, 50-80% reduction
4. **Batch where possible** (batch API) — 50% off list price
5. **Fine-tune** (only after the above) — capital-intensive, justified by high volume

## The Numbers (Real)

A typical LLM app without optimization:
- 1M API calls/month × $0.02/call = $20,000/month
- After caching: $4,000-10,000/month
- After token optimization: $2,000-5,000/month
- After model selection: $500-2,000/month
- Total reduction: 75-90%

Most teams find 80% waste on their first audit.
```

## Use cases

### 1. Your LLM bill is growing faster than usage

Last month $2k, this month $8k, next month projected $30k. You don't know where the money is going. Finance is asking questions.

**Outcome:** Run the cost audit. Find the waste. Apply the funnel. Cut the bill by 60-90% without losing quality.

### 2. You're using the most expensive model for everything

Sonnet for every call, including simple classification. Haiku would work for 80% of your calls at 1/30 the cost.

**Outcome:** Audit by task type. Route simple tasks to Haiku, complex tasks to Sonnet. Save 60-70% with no quality loss.

### 3. You're building for scale

1k users today, 100k next quarter. At current cost, 100k users = $50k/month. You need a cost-aware architecture from day 1.

**Outcome:** Apply the funnel. Build cost attribution. Set budgets per feature. Scale without the bill scaling linearly.

## Built for

- AI engineers whose LLM bill is growing too fast
- AI engineering managers who need cost attribution across teams
- CTOs who need to defend LLM costs to the board
- Indie hackers who need LLM features to be profitable

## Highlights

### The 5-layer funnel

Cache first (50-90% reduction). Token optimization second (20-50%). Model selection third (50-80%). Batch API fourth (50% off). Fine-tune last. Apply in order.

### Most teams find 80% waste

The first audit almost always reveals 80% waste. Unnecessary calls, oversized prompts, expensive models for simple tasks. The pack teaches you to find it.

### Quality preservation

Cost optimization doesn't mean quality loss. The pack teaches you to measure quality (via evals) and optimize cost with the constraint that quality doesn't drop.

## What's in the box

- `5 skills` — funnel + 4 layer skills
- `5 tool adapters` — pi-agent, Claude Code, Cursor, Cline, generic
- `2 worked examples` — token reduction + budget alerts
- `Cost math per layer` — know the savings
- `Vendor-agnostic` — works with any LLM provider

## Adapters included

These skills were authored for pi-agent, but we include drop-in adapters for the major AI coding tools.

| Tool | Adapter location | What you get |
|------|------------------|--------------|
| pi-agent | `adapters/pi-agent/` | SKILL.md drop-in |
| Claude Code | `adapters/claude-code/` | .claude/commands/*.md + CLAUDE.md |
| Cursor | `adapters/cursor/` | .cursorrules rule sets |
| Cline / Continue | `adapters/cline/` | System-prompt rules |
| Aider / generic | `adapters/generic/` | INSTRUCTIONS.md snippets |

**Same playbook, different packaging.** The adapters translate the methodology into the format each tool expects. Install once, swap agents without re-learning the method.

## Features

- cost-optimization skill — master orchestrator + 5-layer optimization funnel
- token-economics skill — input vs output, prompt caching, batch API, context window math
- model-selection skill — cost/quality tradeoff, distillation, fine-tuning economics
- caching-strategies skill — prompt caching, semantic caching, response caching
- finops-for-llms skill — cost attribution, budgets, alerts, vendor management
- 5 tool adapters — pi-agent, Claude Code, Cursor, Cline, generic
- 2 worked examples — token cost reduction + budget alert setup

## FAQ

### Does this work with my LLM provider?

Yes. The methodology is vendor-agnostic. Apply the same funnel to OpenAI, Anthropic, Google, open-weight, or any combination. The specific tactics differ (Anthropic has prompt caching, OpenAI has batch API); the layers are the same.

### Will cutting costs hurt quality?

Not if you measure quality via evals. The pack teaches you to optimize cost with the constraint that eval scores don't drop. Most teams find 60-90% cost reduction with no measurable quality change.

### How long does the first audit take?

A focused first-pass audit (find the biggest waste) takes a day. Applying the fixes takes 1-2 weeks. The pay-back is usually within the first month of cost savings.
