LLM Budget Guard
GitHub Repository: https://github.com/preettrank53/llm-circuit-breaker
A local circuit breaker to stop multi-agent workflows from bankrupting your OpenAI API limits.
Architecture & Data Flow
Installation & Quickstart
You can run the circuit breaker natively via Python or as an isolated Docker container.
Option 1: Native Python (CLI)
- Install the package:
pip install llm-budget-proxy
- Set your credentials:
Create a
.envfile in your working directory:UPSTREAM_BASE_URL=https://api.openai.com/v1 UPSTREAM_API_KEY=your_actual_api_key_here
- Start the server:
circuit-breaker
Option 2: Docker Compose
- Set your credentials: Create a
.envfile as shown above. - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77eca3fc876bda91824fd38165eb012ecb0dddf302f4105e4a81e13bb71843b5
|
|
| MD5 |
083cb7a9562b7562ac92a6b93e83391b
|
|
| BLAKE2b-256 |
ee1d9f0eab9e38063c5689c2dd912ef1eda368cc6528689aeb88b25e8a3f8389
|
File details
Details for the file llm_budget_proxy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_budget_proxy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
461fa933bfe0f4cc32eff66bfc5ac038675d09220fafe4bffcd6429828aa8a79
|
|
| MD5 |
fe75cc81610e851c1a2dae4e4623d1c6
|
|
| BLAKE2b-256 |
2be72cc2e36772a1b5691898eef39012a023865510c6b79963b9d1abb2bd6edb
|