runaway-guard
Fungsinya
Panduan ini membantu mencegah pengeluaran tak terduga saat menggunakan layanan AI berbayar. Panduan ini memastikan Anda menetapkan batas pengeluaran sebelum menjalankan kode apa pun yang memanggil API tersebut.
Kapan dipakai
- βSaat menggunakan AI API yang dikenakan biaya per penggunaan.
- βSaat menulis atau meninjau kode yang melakukan banyak panggilan ke API tersebut.
- βUntuk menghindari tagihan mengejutkan di akhir bulan.
Link skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/runaway-guard/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βBagaimana cara memastikan saya tidak menghabiskan terlalu banyak uang saat menggunakan OpenAI API?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Caranya adalah dengan menetapkan batas yang jelas untuk pengeluaran per panggilan, per hari, dan per eksekusi. Batas ini diatur baik di dalam kode Anda maupun di platform penyedia layanan AI.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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:
β¦
Pertanyaan umum
Mengapa saya perlu menetapkan batas?
API AI berbayar bisa cepat menjadi mahal jika ada bug di kode, misalnya loop yang tidak berhenti. Dengan batas, kesalahan kecil tidak berubah menjadi tagihan besar.
Apa itu 'biaya per run'?
Itu adalah pengeluaran maksimum yang diizinkan dalam satu kali eksekusi kode Anda. Misalnya, jika batasnya 10 panggilan dan setiap panggilan berbiaya $0.01, maka biaya per run adalah $0.10.
Mengapa saya perlu mengatur batas di kode DAN di platform penyedia?
Mengatur di kode adalah lini pertama pertahanan. Mengatur di platform penyedia memastikan pengeluaran tetap dihentikan dari luar meskipun kode gagal, sehingga berfungsi sebagai jaring pengaman.
Detail
Deskripsi asli dari pembuat
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.
Popularitas
- Bintang GitHub
- 48k
- Peringkat
- #5651
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- β¦
Skill lain dari repositori ini
00-andruia-consultant
48kMembantu agent Anda memulai atau meningkatkan proyek AI. Agent menganalisis kode, menyarankan tools, dan membuat rencana aksi dalam bahasa Spanyol.
007
48kMemungkinkan agent Anda melakukan audit keamanan dan threat modeling. Berguna untuk melindungi proyek dari serangan dan celah keamanan.
10-andruia-skill-smith
48kMembantu agent Anda membuat atau meningkatkan tools AI. Agent mendefinisikan cara kerja tools, menulis dokumentasi, dan memvalidasi strukturnya.
20-andruia-niche-intelligence
48kMemungkinkan agent Anda membuat ringkasan industri tertentu. Berguna untuk memahami konteks, aturan, pola penggunaan, dan risiko proyek dengan sumber terpercaya.
Skill serupa
knowledge-automation
394kMembantu agent Anda mengatur tugas terjadwal yang memasukkan konten baru ke Knowledge vault Anda secara rutin, lalu memastikan tugas itu berjalan.
knowledge-source-ingest
394kMembantu agent Anda menjaga Knowledge vault tetap mutakhir dengan item baru dari chat, feed, atau kotak surat, tanpa menambahkan ulang yang sudah ada.
benchmark
280kMembantu agent Anda mengukur kecepatan dan performa kode. Berguna untuk memastikan semuanya cepat dan menemukan penyebab kelambatan.