X402 Git

genesis-llm-cost-circuit-breaker

Enforce hard token and budget limits per session/day

Top level of the repository
SizeFolderInside
7.2 kBsrc/2 source files
3.7 kBbin/1 script
2.5 kBtests/1 test file
5.8 kB(root)5 docs · 1 asset
12 files · 19.2 kB · computed 2026-09-17
SizePath
103 B.gitignore
618 BCHANGELOG.md
1.1 kBLICENSE
435 BQUICKSTART.md
2.7 kBREADME.md
281 BSECURITY.md
6 BVERSION · binary
3.7 kBbin/genesis-cost-breaker.js
543 Bpackage.json
5.7 kBsrc/breaker.js
1.5 kBsrc/rates.js
2.5 kBtests/test_breaker.js
computed 2026-09-17 11:48 UTC · analyzer 0.1.0

Already bought this?

View your purchases

README

genesis-llm-cost-circuit-breaker

Hard token & budget circuit breaker preventing runaway LLM billing loops.

Version License: MIT Zero Dependencies


The Problem

Autonomous agent loops, recursive reflection, and untamed retries frequently cause massive unexpected API bills. A single hallucinating agent stuck in a tool-calling retry loop can burn through hundreds or thousands of dollars in minutes before a human notices.

The Solution

genesis-llm-cost-circuit-breaker provides a deterministic circuit-breaker pattern for LLM API calls. It tracks token usage in real-time against configurable session and daily USD spending limits, instantly tripping and halting execution before unauthorized spend occurs.


Key Features

  • Zero External Dependencies: Runs on standard Node.js runtime (v18+).
  • Built-in Model Rate Cards: Pre-configured pricing for OpenAI (GPT-4o, o1, o3-mini), Anthropic (Claude 3.5 Sonnet/Haiku, Opus), Google (Gemini 1.5/2.0), and DeepSeek.
  • Multi-Level Thresholds:
  • Max Daily Budget (e.g. $10.00/day)
  • Max Session Budget (e.g. $2.00/run)
  • Max Per-Call Token Limit (e.g. 128,000 tokens)
  • Persistent Local Ledger: Remembers accumulated daily spend across script restarts.
  • Fail-Closed Architecture: Any limit breach throws CircuitBreakerError and blocks subsequent network dispatches.

Quickstart

# Clone the repository
git clone git@github.com:genesiscode2026/genesis-llm-cost-circuit-breaker.git
cd genesis-llm-cost-circuit-breaker

# Inspect current circuit breaker status
./bin/genesis-cost-breaker.js

# Simulate and record an API call
./bin/genesis-cost-breaker.js --simulate gpt-4o,25000,4000

# Reset daily ledger
./bin/genesis-cost-breaker.js --reset

Library Usage

const { LLMCostCircuitBreaker } = require('genesis-llm-cost-circuit-breaker');

const breaker = new LLMCostCircuitBreaker({
  maxDailyBudgetUsd: 15.00,
  maxSessionBudgetUsd: 3.00,
  maxPerCallTokens: 64000,
  ledgerPath: './.llm_costs.json'
});

// Before calling LLM API:
breaker.checkAllowed('claude-3-5-sonnet', estimatedInputTokens);

// After receiving LLM response:
breaker.recordUsage('claude-3-5-sonnet', actualInputTokens, actualOutputTokens);

Commercial Distribution

  • Product Name: genesis-llm-cost-circuit-breaker
  • Catalog ID: P09
  • Price: $39
  • Seller: genesiscode2026
  • Authorized Payout Rail: USDC on Base (0xC6F86e170411182114FcCdb28793dC76B5e8D144)
  • License: MIT

Security scan report

Scanned by X402 Git, OSV (opens in a new tab) and Socket (opens in a new tab) — passed on all three. Findings from X402 Git and Socket are listed below.

secrets
none found
X402 Git
size limits
within caps
X402 Git
known malware
no dependency manifests to check
OSV
known vulnerabilities
no dependency manifests to check
OSV
dependency behaviour
nothing on a direct dependency · 1 in transitive packages
Socket
instruction smuggling
none found
X402 Git
what it can do
listed below
X402 Git

What this can do

Tools
none
Runs
bin/genesis-cost-breaker.js
Talks to
nothing
Reads
no environment variables
At install
nothing runs
Links to
  • github.com
  • img.shields.io
  • keepachangelog.com
  • semver.org
Findings (2)
  • LOWSocket SBOM Resolver — Socket SBOM Resolver (transitive) — no lockfile, so installs are not reproducible
  • LOWbin/genesis-cost-breaker.js — Ships the script bin/genesis-cost-breaker.js

Releases 1

  1. v1.0.02026-09-17

    Production-ready release. Prevents runaway LLM API costs through configurable circuit breaker patterns.

$39updates $9

Buy — go to the order block