runaway-guard
Controls the costs of using AI APIs by setting clear limits. It ensures the agent doesn't spend more than planned on its tasks.
What it does
This guide helps prevent unexpected expenses when using paid AI services. It ensures you set spending limits before running any code that calls these APIs.
When to use it
- ✓When using AI APIs that charge per usage.
- ✓When writing or reviewing code that makes many calls to these APIs.
- ✓To avoid surprise bills at the end of the month.
Example of what to ask your AI
“How can I make sure I don't spend too much money using the OpenAI API?”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It works by setting clear limits on how much you can spend per call, per day, and per execution. These limits are set both in your code and on the AI service provider's platform.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill runaway-guardOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/runaway-guard/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
runaway-guard — $-Cost is the Third Complexity Dimension
Every loop has time complexity and space complexity. A loop that calls a paid API has a third: dollars per execution. The model tracks the first two automatically. It does not track the third, so it ships code where a single bug — a retry without bound, a stream reconnect storm, an agent that re-queues itself, a webhook that fires the same job twice — silently spends real money.
The canonical incident: developer writes a Fal.ai image-generation loop. Loop "obviously terminates" because it iterates over a fixed list. The list comes from a callback that fires on every Inngest retry. Each retry doubles the list. By morning, the bill is $200. Tests pass. Code review passed. The bug is not in the loop body. The bug is that no one stated the wallet invariant.
runaway-guard fixes this. State the max calls. State the max dollars per run. State the max dollars per day. Set the same caps in the provider dashboard so a code bug cannot bypass them. Then write the code.
Violating the letter of these rules is violating the spirit of the skill. "I'm only testing locally" is the exact rationalization that ships the $200 bill — local code hits the same paid API as production.
When to Use This Skill
Use runaway-guard when:
- Writing or reviewing code that calls a paid AI / inference API in a loop, queue, retry path, agent step, webhook handler, or background job.
- Importing or wrapping any paid-inference SDK:
@fal-ai/*,fal-client,@anthropic-ai/sdk,anthropic,openai,replicate,elevenlabs,together-ai,groq-sdk,cohere-ai,@mistralai/*. - Designing an agent loop, fan-out pipeline, retry wrapper, polling job, stream reconnect, or self-rescheduling job that may call a billed endpoint.
- Auditing a codebase / PR for unbounded fan-out, unbounded retries, missing idempotency keys, or missing provider-side spend caps.
- Diagnosing an unexpected bill, runaway loop incident, or surprise overage.
The Iron Law
NO CALL TO A PAID API WITHOUT A WRITTEN $-CAP AT BOTH THE CODE AND PROVIDER LEVEL
A cap only in code can be bypassed by a bug in that code. A cap only at the provider can be hit during normal usage and degrade the product. You need both. If you cannot state both in one sentence each, you have not designed the call site — you have written a wish.
Non-negotiable rules
Every call site gets a one-line cost contract. Before writing any paid-API call, state in one sentence:
- Max calls per run: the strict upper bound on invocations in a single execution of this code path.
- Max $ per run:
max_calls × unit_cost— compute it, don't estimate. - Max $ per day: the provider-side hard cap that backstops the code-side bound.
Examples:
- "Fal flux-pro at $0.05/image; max 20 images per job; max $1 per job; provider Spend Limit $50/day."
- "Anthropic Sonnet at ~$0.015 per request (cached); max 50 requests per agent run; max $0.75 per run; Workspace Budget hard cap $30/day."
If you cannot fill in all three numbers, you have not designed the call site.
Every loop calling a paid API gets an explicit iteration bound, not just a termination argument.
invariant-guardrequires a termination measure. runaway-guard requires the bound to be a concrete integer in code, not just "eventually terminates":// ❌ Terminates in theory. Bills $200 in practice. while (job.status !== 'done') { await fal.run(...); } // ✅ Concrete bound — wallet invariant explicit. const MAX_CALLS = 20; for (let i = 0; i < MAX_CALLS && job.status !== 'done'; i++) { await fal.run(...); } if (job.status !== 'done') throw new Error('exceeded MAX_CALLS budget');Every retry path is bounded by attempts AND total elapsed cost, not by time alone. Exponential backoff with no attempt cap is a wallet attack on yourself.
- Max attempts: a small integer (3–5 for transient errors, 1 for 4xx).
- Cap counts across the whole pipeline, not just one library — Inngest retries × SDK retries × your own retry wrapper multiply.
- 4xx errors do not retry. Period. They will not become 2xx; they will just bill again.
Every fan-out path declares a concurrency limit. Parallel calls multiply cost per wall-clock second. State the limit in code, at the queue (Inngest
concurrency), and at the provider where supported:
…
FAQ
Why do I need to set limits?
Paid AI APIs can become expensive quickly if there's a bug in the code, like a loop that doesn't stop. Setting limits prevents a small error from becoming a large bill.
What is a 'cost per run'?
It's the maximum spending allowed in a single execution of your code. For example, if you have a limit of 10 calls and each costs $0.01, the cost per run is $0.10.
Why do I need to set the limit in the code AND on the provider's platform?
Setting it in the code is a first line of defense. Setting it on the provider's platform ensures that even if the code fails, spending will be stopped externally, acting as a safety net.
Details
Original description by the author
Cost-safety discipline for paid AI / inference APIs: treat $-cost as a third complexity dimension alongside time and space. Forces a written per-run $-cap, per-day $-cap, max-iterations bound, concurrency limit, and a matching provider-dashboard hard cap BEFORE any call site is written.
Popularity
- GitHub stars
- 48k
- Ranking position
- #4037
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
benchmark
Helps your agent measure code speed and performance. It's useful for ensuring things are fast and finding slowness issues.
affaan-m/ECC
content-hash-cache-pattern
Lets your agent use content hashes to cache file processing results. This avoids repeated processing and auto-invalidates the cache when content changes. Useful for speeding up slow tasks.
affaan-m/ECC
parallel-execution-optimizer
Makes your agent speed up complex tasks by breaking them into smaller parts and running them in parallel. It ensures everything is verified at the end.
affaan-m/ECC