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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_budget_proxy-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_budget_proxy-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file llm_budget_proxy-0.1.1.tar.gz.

File metadata

  • Download URL: llm_budget_proxy-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.2

File hashes

Hashes for llm_budget_proxy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77eca3fc876bda91824fd38165eb012ecb0dddf302f4105e4a81e13bb71843b5
MD5 083cb7a9562b7562ac92a6b93e83391b
BLAKE2b-256 ee1d9f0eab9e38063c5689c2dd912ef1eda368cc6528689aeb88b25e8a3f8389

See more details on using hashes here.

File details

Details for the file llm_budget_proxy-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_budget_proxy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 461fa933bfe0f4cc32eff66bfc5ac038675d09220fafe4bffcd6429828aa8a79
MD5 fe75cc81610e851c1a2dae4e4623d1c6
BLAKE2b-256 2be72cc2e36772a1b5691898eef39012a023865510c6b79963b9d1abb2bd6edb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

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