Chuyển đến nội dung
Skillpedia
Tự động hóa48k · #5651

runaway-guard

Skill này làm gì

Hướng dẫn này giúp ngăn chặn các chi phí bất ngờ khi dùng dịch vụ AI trả phí. Nó đảm bảo bạn đặt giới hạn chi tiêu trước khi chạy bất kỳ đoạn code nào gọi các API này.

Khi nào nên dùng

  • ✓Khi bạn dùng API AI tính phí theo mức sử dụng.
  • ✓Khi bạn viết hoặc rà soát code thực hiện nhiều lần gọi các API này.
  • ✓Khi bạn muốn tránh các hóa đơn bất ngờ vào cuối tháng.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/runaway-guard/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/runaway-guard/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để tôi chắc chắn không chi tiêu quá nhiều khi dùng OpenAI API?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Tool hoạt động bằng cách đặt giới hạn rõ ràng về số tiền có thể chi cho mỗi lần gọi, mỗi ngày và mỗi lần thực thi. Các giới hạn này được đặt cả trong code và trên nền tảng của nhà cung cấp AI.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

  1. 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.

  2. Every loop calling a paid API gets an explicit iteration bound, not just a termination argument. invariant-guard requires 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');
    
  3. 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.
  4. 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:

…

Câu hỏi thường gặp

Vì sao tôi cần đặt giới hạn?

API AI trả phí có thể tốn kém rất nhanh nếu code có lỗi, chẳng hạn một vòng lặp không dừng. Đặt giới hạn sẽ ngăn một lỗi nhỏ biến thành hóa đơn lớn.

“Chi phí mỗi lần chạy” là gì?

Đó là mức chi tiêu tối đa được phép trong một lần thực thi code. Ví dụ, nếu giới hạn là 10 lần gọi và mỗi lần tốn $0.01, thì chi phí mỗi lần chạy là $0.10.

Vì sao phải đặt giới hạn cả trong code và trên nền tảng của nhà cung cấp?

Đặt trong code là lớp phòng vệ đầu tiên. Đặt trên nền tảng của nhà cung cấp đảm bảo chi tiêu vẫn bị dừng từ bên ngoài ngay cả khi code bị lỗi, đóng vai trò như một tấm lưới an toàn.

Chi tiết

Mô tả gốc của tác giả

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.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5651
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự