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.0.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.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_budget_proxy-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 aa4b1804810c4adf080f298776ac3c7816a371bfc91845cec30a0e18dbfd41ab
MD5 8e3d9afae3e6ee17da6cffdfb80805bf
BLAKE2b-256 29227dc1e697e4277fda7785d3d7620cce24151abe5720d5bc4a010f6f72c913

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_budget_proxy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f23c12ebc906e5c8ea275d9e7af0be74970b10006dc79a6ddd7de67d37665a68
MD5 95afda44be0448ad604a7131d95a43a6
BLAKE2b-256 f637c1c224493559753138878f65a258c6eebd0750fd495fafa1b6752ecbac77

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

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