Skip to main content

AI GuardRail 🚨

A lightweight Python utility designed to prevent cloud cost landmines. It monitors HTTP requests and automatically intercepts and blocks sudden spikes or infinite loop request patterns (e.g., more than 50 calls to the same endpoint in 10 seconds), saving you from unexpected API bills.

Features

  • In-Process Monkey Patching: Zero-config protection for your existing Python applications. Instantly intercepts and blocks excessive requests using standard libraries (urllib, urllib3, requests).
  • Standalone Proxy Server: Can run as a local proxy on any port, letting any application/environment route requests through it using HTTP_PROXY.
  • Dynamic Sliding Window: Tracks request history using a thread-safe sliding window.
  • Customizable Thresholds: Easily customize request rate limits and window sizes.

Installation

pip install ai-cost-guardrail

Usage

1. In-Process Monkey-Patcher (Python Apps)

Import ai_guardrail at the very beginning of your application entry point to intercept cost landmines:

import ai_guardrail

# Block requests if an endpoint is called more than 30 times in 10 seconds
ai_guardrail.enable(max_calls=30, window_seconds=10)

import requests
# Any HTTP requests made via urllib, urllib3, requests, etc., are now automatically protected!

If a loop triggers, a RuntimeError is raised, blocking the request from hitting the cloud API and saving your budget.

2. Standalone Proxy Server

You can run the GuardRail proxy server locally and route any external application traffic through it.

Run via CLI:

ai-cost-guardrail-proxy --port 8090 --max-calls 50 --window 10

Or via Python:

import ai_guardrail
ai_guardrail.run_proxy_server(port=8090)

Then configure your environment variables to use the proxy:

export HTTP_PROXY="http://127.0.0.1:8090"
export HTTPS_PROXY="http://127.0.0.1:8090"

Running Tests

To run unit tests:

python -m unittest discover -s tests

License

MIT

Metadata

Release files for ai-cost-guardrail 0.1.0

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

Source distribution (sdist)

Source distribution for ai-cost-guardrail 0.1.0
File Size Uploaded Provenance
ai_cost_guardrail-0.1.0.tar.gz 6.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-cost-guardrail 0.1.0
File Interpreter ABI Platform
ai_cost_guardrail-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / ai_cost_guardrail-0.1.0.tar.gz

Download URL ai_cost_guardrail-0.1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
024fc685a30c899c489dca67515b64cd5d855ddcd34a8be9021d82501b1e8af0
BLAKE2b-256 checksum
How to use checksums
1df3354fec3ef6aace16a0392b00c4721ffd2d06442994b5c480a0ce3916223d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / ai_cost_guardrail-0.1.0-py3-none-any.whl

Download URL ai_cost_guardrail-0.1.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94bb8bdadd4f0d62cea5ee56df7f4eb5906b574407760c09a773a5f76403b171
BLAKE2b-256 checksum
How to use checksums
f9440e79277a218bb44b1d7ff04ec9b63abf460ce82166826d60f1333039d231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for ai-cost-guardrail 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.

Release history Release notifications | RSS feed

This release

0.1.0 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