# Cost aware LLM pipeline

> Cost aware LLM pipeline is an open-source agent skill for developer tools. Patterns for routing LLM calls across model tiers while tracking spend and budgets. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/smartworldarafath/REA_Skill/tree/main/.agents/skills/cost-aware-llm-pipeline
- **Repository:** https://github.com/smartworldarafath/rea_skill
- **GitHub stars:** 66
- **License:** MIT
- **Skill name:** cost-aware-llm-pipeline
- **Collection:** https://github.com/smartworldarafath/REA_Skill
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-01

## About

This skill gives an agent a set of Python patterns for keeping LLM API bills under control without dropping quality on hard tasks. It covers picking a cheaper model for simple inputs and a stronger one for complex inputs based on text length and item count, with an option to force a specific model. It also shows how to record per-call token usage and cost in an immutable tracker that checks a spending limit before each request.

The guidance adds retry logic that only repeats calls on transient network, rate limit and server errors, using exponential backoff and failing immediately on authentication or bad request errors. It also explains marking long, repeated system prompts for caching so they are not resent in full on every request. A reference table lists per-million-token input and output prices for several Claude models, and the skill combines these pieces into a single pipeline function.

The examples use the Anthropic Python SDK and expect Python with dataclasses. The skill ships only a SKILL.md with no scripts, so the agent writes the code into the user's project itself.

## When your agent uses it

> Cost optimization patterns for LLM API usage — model routing by task complexity, budget tracking, retry logic, and prompt caching. Use when LLM spend needs to come down, or when routing tasks across model tiers and budgets.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/smartworldarafath/REA_Skill/tree/HEAD/.agents/skills/cost-aware-llm-pipeline)
- [License: MIT](https://github.com/smartworldarafath/REA_Skill/tree/HEAD/.agents/skills/cost-aware-llm-pipeline)

## Features

- **Complexity-based model routing:** Chooses a cheaper or more capable model based on input size and item count, with an override option.
- **Immutable budget tracking:** Records each call's tokens and cost in a frozen tracker that reports when spend exceeds a limit.
- **Narrow retry handling:** Retries only transient API errors with exponential backoff and fails fast on other errors.
- **Prompt caching setup:** Shows how to mark a long system prompt for caching so repeated requests reuse it.
- **Model pricing reference:** Provides a table of input and output token prices for several Claude model tiers.
- **Composable pipeline pattern:** Combines routing, budget checks, retries, caching and cost tracking into one processing function.

## Good for

- Reduce the monthly bill of an app that calls Claude on every request
- Route short and simple items to a cheaper model and long ones to a stronger model
- Add a spending cap that stops batch processing before it overspends
- Make an LLM client retry only on rate limits and network errors
- Add prompt caching to a repetitive system prompt in an existing integration

## Install

### Claude Code

This skill ships in the `rea-skills` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add smartworldarafath/REA_Skill
/plugin install rea-skills@smartworldarafath
```

Or copy only this skill to `~/.claude/skills/cost-aware-llm-pipeline`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/smartworldarafath/REA_Skill.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/cost-aware-llm-pipeline &&
cp -R "$tmp/.agents/skills/cost-aware-llm-pipeline" ~/.claude/skills/cost-aware-llm-pipeline &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/cost-aware-llm-pipeline` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/cost-aware-llm-pipeline` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/smartworldarafath/REA_Skill.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/cost-aware-llm-pipeline &&
cp -R "$tmp/.agents/skills/cost-aware-llm-pipeline" ~/.agents/skills/cost-aware-llm-pipeline &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/cost-aware-llm-pipeline` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/cost-aware-llm-pipeline` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/smartworldarafath/REA_Skill.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/cost-aware-llm-pipeline &&
cp -R "$tmp/.agents/skills/cost-aware-llm-pipeline" ~/.cursor/skills/cost-aware-llm-pipeline &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/cost-aware-llm-pipeline` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/smartworldarafath/REA_Skill.git --path .agents/skills/cost-aware-llm-pipeline
```

Or copy the folder to `~/.gemini/skills/cost-aware-llm-pipeline` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/cost-aware-llm-pipeline`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/smartworldarafath/REA_Skill.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/cost-aware-llm-pipeline &&
cp -R "$tmp/.agents/skills/cost-aware-llm-pipeline" ~/.copilot/skills/cost-aware-llm-pipeline &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/cost-aware-llm-pipeline` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/smartworldarafath/REA_Skill.git
```

Then copy `REA_Skill/.agents/skills/cost-aware-llm-pipeline` into your agent's skills folder as `cost-aware-llm-pipeline`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does the skill need to run?

It uses Python with dataclasses and the Anthropic SDK in its examples, and it bundles no scripts. The agent writes the pipeline code into your project.

### When does Cost aware LLM pipeline trigger?

It loads when LLM spend needs to come down or when tasks are being routed across model tiers and budgets.

### Which errors does the retry logic repeat?

It retries connection errors, rate limit errors and internal server errors, up to three attempts. Authentication and bad request errors are raised immediately.

### How is the budget tracked?

Each call adds a cost record to an immutable tracker, which reports over budget when total cost exceeds a set limit, default one dollar.

### How do I install Cost aware LLM pipeline in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/cost-aware-llm-pipeline to use it in all your projects, or to .claude/skills/cost-aware-llm-pipeline in one project. Or install the rea-skills plugin, which includes it: /plugin marketplace add smartworldarafath/REA_Skill, then /plugin install rea-skills@smartworldarafath.

### Does Cost aware LLM pipeline run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Cost aware LLM pipeline?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Cost aware LLM pipeline?

The closest alternatives to Cost aware LLM pipeline are Claude API, API rate limiting helper, Orchestration, Agentic eval and Patterns.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Claude API](https://ai-powered.com/skills/claude-api): Claude API is a free agent skill for ai models and llm tooling.
- [API rate limiting helper](https://ai-powered.com/skills/api-rate-limiting-helper): API rate limiting helper is an open-source agent skill for developer tools.
- [Orchestration](https://ai-powered.com/skills/orchestration-xiaolai): Orchestration is an open-source agent skill for developer tools.
- [Agentic eval](https://ai-powered.com/skills/agentic-eval): Agentic eval is an open-source agent skill for ai models and llm tooling.
- [Patterns](https://ai-powered.com/skills/patterns-xiaolai): Patterns is an open-source agent skill for developer tools.
- [Autonomous loops](https://ai-powered.com/skills/autonomous-loops): Autonomous loops is an open-source agent skill for developer tools.
- [API AI augmented](https://ai-powered.com/skills/api-ai-augmented): API AI augmented is an open-source agent skill for ai models and llm tooling.
- [Ecc tools cost audit](https://ai-powered.com/skills/ecc-tools-cost-audit): Ecc tools cost audit is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/cost-aware-llm-pipeline
