runaway-guard
하는 일
이 가이드는 유료 AI 서비스를 사용할 때 예상치 못한 비용을 막도록 돕습니다. API를 호출하는 코드를 실행하기 전에 지출 한도를 설정하도록 합니다.
사용하는 경우
- ✓사용량에 따라 요금을 내는 AI API를 사용할 때.
- ✓이 API를 많이 호출하는 코드를 작성하거나 검토할 때.
- ✓월말에 예상치 못한 청구서를 받지 않으려고 할 때.
스킬 링크
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/runaway-guard/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“OpenAI API를 사용하면서 돈을 너무 많이 쓰지 않도록 어떻게 확실히 할 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
호출 한 번당, 하루에, 그리고 실행 한 번당 사용할 수 있는 금액에 명확한 한도를 정하는 방식으로 작동합니다. 이 한도는 코드 안에서도, AI 서비스 제공업체의 플랫폼에서도 설정합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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:
…
자주 묻는 질문
왜 한도를 정해야 하나요?
유료 AI API는 코드에 버그가 있으면, 예를 들어 멈추지 않는 반복문이 있으면 금방 비싸질 수 있습니다. 한도를 정하면 작은 오류가 큰 청구서로 이어지는 것을 막을 수 있습니다.
‘실행당 비용(cost per run)’이란 무엇인가요?
코드를 한 번 실행할 때 쓸 수 있는 최대 금액입니다. 예를 들어 호출 10회 한도이고 호출 한 번에 0.01달러라면, 실행당 비용은 0.10달러입니다.
코드에서도, 제공업체 플랫폼에서도 한도를 설정해야 하는 이유는 무엇인가요?
코드에서 설정하는 것이 첫 번째 방어선입니다. 제공업체 플랫폼에서도 설정하면, 코드가 실패하더라도 외부에서 지출을 멈출 수 있어 안전망이 됩니다.
상세 정보
작성자의 원본 설명
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.
인기도
- GitHub 스타
- 48k
- 순위
- #5651
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
00-andruia-consultant
48k에이전트가 AI 프로젝트를 시작하거나 개선할 수 있도록 코드를 분석하고 스페인어로 실행 계획을 세워 줍니다.
007
48k에이전트가 보안 감사와 위협 모델링을 수행해 공격과 취약점으로부터 프로젝트를 보호하도록 돕습니다.
10-andruia-skill-smith
48k에이전트가 AI 도구의 작동 방식을 정의하고 문서를 쓰며 구조를 검증하도록 돕습니다.
20-andruia-niche-intelligence
48k에이전트가 신뢰할 수 있는 자료를 바탕으로 특정 산업의 맥락, 규칙, 사용 패턴, 위험을 정리한 요약을 만들도록 돕습니다.