LLM Cost Guard & Model Router

    by finance_kim

    1

    What it adds to your project - Budgets that act before the call - per-call, per-session and per-day caps in money and/or tokens.

    Free

    Security scanned

    Works with the AI Agents you already use

    LLM Cost Guard & Model Router

    Example session with this skill installed

    Our support bot and coding agent run on OpenAI and Anthropic. Last month's bill doubled and one agent run looped for an hour. Add a per-conversation cap and a daily cap, stop agent loops, send simple requests to our small model, and tell me where the money goes from logs/llm_calls.jsonl.

    • Read your context and instructions
    • Compiled the llm cost guard

    Illustrative reply. Report figures are from the skill's bundled synthetic example (fictional models and prices).

    Changes: added myapp/cost_guard.py (vendored, standard library only) and config/llm_prices.json - please fill in prices for 2 models. Wrapped 4 call sites with guard.wrap(); caps: $0.50 per call, $2 per conversation, $50 per day. LoopGuard added to the agent loop; router on the support endpoint. 6 new offline tests pass with a fake client.

    Cost report, 7 days: 490 calls, $18.21 known cost (+3 calls on an unpriced model).

    1. Add prices for demo-experimental: 3 calls are excluded from cost figures.
    2. Route easy calls from demo-strong to demo-light: 88 eligible calls cost $1.24; at light prices $0.11 (save up to $1.13, 90.8%). Upper bound - check quality on a sample first.
    3. 1 runaway session cost $1.60 (8.8% of spend): LoopGuard fired after 9 identical requests.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Stop LLM cost blowups before they happen. This skill has your coding agent add hard budget caps, agent-loop protection, light/strong model routing and per-call cost logging to your own Python LLM app - then turns the logs into a cost report with concrete savings.

    What it adds to your project

    • Budgets that act before the call - per-call, per-session and per-day caps in money and/or tokens. The worst case of each call (estimated input + max_tokens) is checked first, so a call that would cross a cap is never sent. Thread-safe, so parallel workers cannot jointly overshoot.
    • Runaway-agent protection - max iterations, the same tool call repeated, A-B-A-B cycles, "no progress" detection and a wall-clock limit.
    • Light vs. strong model routing - transparent rule scoring (input length, code, hard/easy keywords, tool count, output size) with a capped escalation when the light model's answer fails your check. Every decision lists its reasons.
    • Per-call log - JSONL with model, input/output/cache-read/cache-write tokens, cost, latency, route reason and session. No prompt or completion text is stored. Size-based rotation.
    • Cost report - totals per model, day and session, top expensive sessions, loop suspects, "what if these calls ran on the light model" savings, and recommendations (missing prices, caching, output-heavy models, error rates, budget hits). Markdown or JSON.

    How it works The agent finds your LLM call sites, vendors one standard-library Python file into your project, wires it into your Anthropic, OpenAI or other provider calls (sync, streaming or async), configures caps and routing, adds tests with a fake client (no real API spend), and reports what changed.

    Honest numbers No vendor prices or model IDs are built in. You fill a price template from your own pricing page or invoice; any model without a price is reported as "cost unknown", never guessed. Savings estimates are labelled as upper bounds.

    Requirements Python 3.9+, standard library only. No API keys, no network access, no telemetry.

    Includes: SKILL.md workflow, the vendorable module and report CLI, price and router templates, integration recipes, budget-sizing and routing guides, troubleshooting, and four worked examples produced by running the code on clearly labelled synthetic data.

    Budgets are enforced per process; multi-process deployments split the cap or add a shared counter. The pre-call input estimate is offline and approximate (deliberately high) unless you plug in an exact token counter. Routing is a rule-based heuristic and needs a quality check on your own traffic before switching. Reports only see calls that went through the logger, and invoice totals can differ (discounts, server-side tool fees, failed calls). The bundled module is Python; other stacks can use the report via the documented log format but need their own port of the guard.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 8 days ago

    • Free with an Agensi account

    Software
    Python 3.9+Python app calling an LLM APIYour own model prices

    Permissions

    Terminal / Shell
    Read Files
    Write Files

    File Scopes

    Project
    source
    files
    that
    call
    LLM
    APIs
    (read
    and
    edit)
    A
    new
    vendored
    module
    e.g.
    package
    /cost_guard.py
    Your
    price/router
    config
    log
    folder
    (read;
    written
    by
    your
    app)

    Bash is used to run the bundled Python scripts and your test suite. The skill makes no network requests and needs no API keys. It does not make real LLM calls unless you explicitly ask for a live check.

    Listed8 days ago

    What's inside

    Creator

    finance_kim

    finance_kim

    11 skills on Agensi

    Frequently Asked Questions

    No, on purpose. Prices change and differ by platform and contract. You copy the included template and fill in your own prices; a model without a price is reported as cost unknown instead of being guessed.

    Anthropic and OpenAI Python SDKs out of the box (including cache read/write tokens, reasoning tokens and streaming). Any other provider works with a three-line usage extractor; recipes are included.

    No. It runs inside your code, wraps the calls you already make, has no network access of its own, and the logger stores token counts and a short hash, never prompt text.

    Before each call it prices the worst case: estimated input tokens plus your max_tokens at your prices. If that would push the call, session or day over its cap, it raises BudgetExceeded and the request is never sent. The actual usage replaces the estimate afterwards.

    No. It is a transparent rule score (length, code, keywords, tools, output size) with configurable thresholds and capped escalation. The skill tells the agent to validate quality on a sample of your traffic before switching.

    The cost report works on any app that writes the documented JSONL log format. The guard itself is a single Python file; for other languages the agent can port the parts you need, with its own tests.

    New in LLM Ops

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.

    Free