mesh-cost-firewall
Real-time AI agent cost gating system that prevents budget overruns before they happen.
What is this?
mesh-cost-firewall is a cost control middleware that sits between your agent mesh and LLM APIs, automatically rejecting or rate-limiting requests that would breach per-agent, per-user, or global budget limits. Instead of discovering runaway costs in your billing dashboard, agents hit configurable spending ceilings and fail gracefully. Built for autonomous multi-agent systems where financial guardrails are essential.
Features
- Multi-level budget enforcement — Global, per-user, and per-agent cost caps
- Real-time cost estimation — Pre-request cost prediction before API calls
- Graceful rate limiting — Circuit breaker pattern for budget exhaustion
- LLM model awareness — Built-in pricing for GPT-4, Claude, and other major models
- Request interception — Transparent proxy layer between agents and APIs
- Configuration as code — YAML/env-based budget definitions
- Docker-native — Ships with Dockerfile and docker-compose for instant deployment
- Production-ready — Handles concurrent requests, persistent state, and monitoring hooks
Quick Start
Installation
# Clone and install
git clone <repo>
cd mesh-cost-firewall
pip install -e .
# Or with Docker
docker-compose up -d
Configuration
Create a .env file (see .env.example):
GLOBAL_BUDGET_CENTS=100000
DEFAULT_USER_BUDGET_CENTS=10000
DEFAULT_AGENT_BUDGET_CENTS=1000
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
Basic Usage
from mesh_cost_firewall import CostFirewall
firewall = CostFirewall(config_path="config.yaml")
# Wrap your LLM call
result = firewall.request(
agent_id="researcher_1",
user_id="user_42",
model="gpt-4",
tokens=2000,
endpoint="https://api.openai.com/v1/chat/completions"
)
if result.allowed:
# Safe to proceed
response = call_llm_api(...)
else:
# Budget exhausted
logger.warning(f"Request rejected: {result.reason}")
Or use as an HTTP proxy:
export FIREWALL_PORT=8000
python -m mesh_cost_firewall.main
curl -X POST http://localhost:8000/v1/chat/completions \
-H "X-Agent-Id: researcher_1" \
-H "X-User-Id: user_42" \
-d '{"model": "gpt-4", ...}'
Tech Stack
- Python 3.9+ — Core runtime
- FastAPI — HTTP proxy and API
- Pydantic — Configuration validation
- APScheduler — Budget reset scheduling
- Docker — Containerization
- SQLite — Persistent state (upgradeable to Postgres)
License
MIT
Metadata
Release files for mesh-cost-firewall 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mesh_cost_firewall-0.1.0.tar.gz | 13.2 kB | Without provenance | Details for mesh_cost_firewall-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mesh_cost_firewall-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mesh_cost_firewall-0.1.0-py3-none-any.whl |
Total release size: 28.0 kB
Release files / mesh_cost_firewall-0.1.0.tar.gz
| Download URL | mesh_cost_firewall-0.1.0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d978195c7a88bf32baa83b6c595c9ef3bbc3f5f99b3ea12d3291c223726a1de
|
|
BLAKE2b-256 checksum How to use checksums |
aeecb0e4eb59192d094bcb87b8788048b31f15cbc955e47f17dec54c01abb47e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / mesh_cost_firewall-0.1.0-py3-none-any.whl
| Download URL | mesh_cost_firewall-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9919049140a52e98e639db447cf01c68366f9eb9571f99d8213f1383afd6ab27
|
|
BLAKE2b-256 checksum How to use checksums |
1fa69e77a2ef901b1d9cc621ae65cd7672d378b791e1635e66a408cdca0d5abb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for mesh-cost-firewall 0.1.0
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.