Skip to main content

LLM Budget Guard

Tests

GitHub Repository: https://github.com/preettrank53/llm-circuit-breaker

A local circuit breaker to stop multi-agent workflows from bankrupting your OpenAI API limits.

LLM Budget Guard Demo

Architecture & Data Flow

Architecture Diagram

Flow Diagram

Installation & Quickstart

You can run the circuit breaker natively via Python or as an isolated Docker container.

Option 1: Native Python (CLI)

  1. Install the package:
    pip install llm-budget-proxy
    
  2. Set your credentials: Create a .env file in your working directory:
    UPSTREAM_BASE_URL=https://api.openai.com/v1
    UPSTREAM_API_KEY=your_actual_api_key_here
    
  3. Start the server:
    circuit-breaker
    

Option 2: Docker Compose

  1. Set your credentials: Create a .env file as shown above.
  2. Start the container:
    docker-compose up -d
    

Usage & Framework Integrations

Point your AI agent's base URL to the local proxy (http://localhost:8000/v1). It will automatically intercept requests, check your budget, and forward them safely.

We have included drop-in examples for popular frameworks in the examples/ directory:

Standard OpenAI SDK Example

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="dummy-key" # Proxy injects your real key automatically
)

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Say hello"}],
    stream=False # Streaming not supported yet
)
print(response.choices[0].message.content)

Management API

Control your budget programmatically via simple HTTP endpoints:

  • Check Budget Status: GET /v1/budget
  • Reset Token Counter: POST /v1/budget/reset

Performance Benchmark

The proxy uses an asynchronous connection pool via FastAPI's lifespan architecture, meaning it holds the SSL handshake open. In a small five-request smoke test, end-to-end latency was within normal network variance.

Starting benchmark...
Measuring DIRECT latency (5 requests)...
Average Direct Latency: 473.53 ms

Measuring PROXY latency (5 requests)...
Average Proxy Latency:  470.80 ms

Total Proxy Overhead: -2.73 ms

Metadata

Release files for llm-budget-proxy 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-budget-proxy 0.1.1
File Size Uploaded Provenance Actions
llm_budget_proxy-0.1.1.tar.gz 5.8 kB Without provenance Details for llm_budget_proxy-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-budget-proxy 0.1.1
File Interpreter ABI Platform Actions
llm_budget_proxy-0.1.1-py3-none-any.whl Python 3 none any Details for llm_budget_proxy-0.1.1-py3-none-any.whl

Total release size: 11.3 kB

Release files / llm_budget_proxy-0.1.1.tar.gz

Download URL llm_budget_proxy-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
77eca3fc876bda91824fd38165eb012ecb0dddf302f4105e4a81e13bb71843b5
BLAKE2b-256 checksum
How to use checksums
ee1d9f0eab9e38063c5689c2dd912ef1eda368cc6528689aeb88b25e8a3f8389
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / llm_budget_proxy-0.1.1-py3-none-any.whl

Download URL llm_budget_proxy-0.1.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
461fa933bfe0f4cc32eff66bfc5ac038675d09220fafe4bffcd6429828aa8a79
BLAKE2b-256 checksum
How to use checksums
2be72cc2e36772a1b5691898eef39012a023865510c6b79963b9d1abb2bd6edb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for llm-budget-proxy 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page