Catalog PyPI
PACKAGE EXPLORERView in registry

ai-cost-guardrail

PyPI

A lightweight Python utility to prevent cloud cost landmines by monitoring and intercepting sudden HTTP request spikes.

Versions collected1
Direct dependencies0From release 0.1.0
Last observed21 Oct, 10:19 UTC

README

Version 0.1.0 documentation

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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.029 Jun 20260

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
infinityempire/ai-guardrail

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:19 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:0738ebadcfde53343ad02dc17fdf6ca5d24ed5bca750331e6e67187f912c8fb2