Per-run dollar budgets for AI agents and jobs: an OpenAI- and Anthropic-compatible gateway, in-process or self-hosted, that refuses over-budget calls before the provider and keeps a payload-free cost record per run.
pip install inferrail==0.4.16 Copy PIP instructions
Inferrail is a gateway you run yourself, between your app and OpenAI or Anthropic. It shows what each AI job costs, blocks calls that would push a job past its spending limit, and doesn't copy prompts or responses into its records.
Quickstart · Where your data goes · How it works · Docs · tryinferrail.com
A real run of the Inferrail gateway and dashboard, with a local stand-in model: no API key, no provider charges. How it was recorded
Developer preview. Everything below is implemented and tested. CLI flags, config, and receipt fields may still change before 1.0.
Protect one run, inside your Python app. No config file and no second terminal:
pip install inferrail export OPENAI_API_KEY=sk-... import inferrail from openai import OpenAI base_url = inferrail.start() # the gateway, on a background thread in this process client = OpenAI(base_url=base_url, api_key="unused") client.chat.completions.create( model="gpt-4o-mini", # example: any model your account can use (`inferrail models` lists them) max_tokens=200, messages=[{"role": "user", "content": "Summarize this contract."}], extra_headers={ "X-Inferrail-Attribute-Work-Id": "contract-review-42", # the run "X-Inferrail-Budget-Usd": "0.50", # its dollar ceiling }, ) Every call that carries the same run id shares that budget, including parallel calls. A call that would push the run past it gets HTTP 402 before it reaches OpenAI. Then:
inferrail work contract-review-42 shows what the run cost.
Inferrail doesn't choose a model: whatever model id you send is passed to the provider. A dollar budget needs a price for that model; inferrail models shows which models have one, and inferrail.start(pricing=...) adds a price for a new model. Framework snippets (LangChain, LangGraph, OpenAI Agents SDK, CrewAI, Haystack, LlamaIndex, Microsoft Agent Framework): recipe.
Try it offline. No API key, no network calls, no provider charges:
pip install inferrail inferrail demo inferrail report --by customer --receipts ./inferrail-demo-receipts.jsonl The demo sends scripted requests through the real engine to a fake provider with made-up prices labeled DEMO, and prints what they cost by customer (recording).
Run it as its own process, with the local dashboard. For a gateway shared by several apps, or to watch calls live, set your key in the gateway's terminal:
export OPENAI_API_KEY=sk-... # and/or ANTHROPIC_API_KEY inferrail serve --quickstart --app-mode Open the Dashboard: URL it prints, then point your app at the gateway and tag the work:
from openai import OpenAI # api_key is a placeholder: your provider key stays in the gateway client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="unused") client.chat.completions.create( model="gpt-4o-mini", # example model id; Inferrail passes yours through messages=[{"role": "user", "content": "Summarize this contract."}], extra_headers={ "X-Inferrail-Attribute-Customer": "acme", "X-Inferrail-Attribute-Work-Id": "contract-review-42", "X-Inferrail-Budget-Usd": "0.50", # optional: a dollar ceiling for this work }, ) The call appears in the Live Feed, and the Work screen totals what contract-review-42 cost. The Anthropic SDK works the same way with base_url="http://127.0.0.1:8000" (no /v1). More clients and frameworks: docs/integrations.md.
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate python -m pip install inferrail If inferrail is still not found, the environment isn't active or pip installed into a different Python. More in docs/self-hosting.md.
Attribution tags are stored exactly as sent, so use identifiers and keep secrets and message content out of them. inferrail verify-payload-free prints the live receipt schema, and canary tests check that message bodies never reach receipts. Neither is a security audit. The optional usage beacon sends nothing unless an endpoint is configured (details). How to check all of this yourself: docs/PRODUCT.md.
The gateway routes each request by model to a configured provider, checks any budget in scope, forwards the call, and writes one receipt per request, including requests a budget refused. Reports, the dashboard, and MCP tools all read those receipts. Details: docs/ARCHITECTURE.md.
inferrail mcp is a stdio MCP server with two read-only tools over your local receipts: get_spend (known cost and tokens grouped by provider, model, route, or any tag such as work_id) and get_health. They don't run inference or write files.
claude mcp add inferrail \ -e INFERRAIL_RECEIPTS_PATH=/absolute/path/to/inferrail-receipts.jsonl \ -- uvx --with "mcp>=2.0" inferrail mcp Other clients, and where --app-mode keeps its receipts: docs/integrations.md.
Exact contract and non-goals: docs/PRODUCT.md.
These are separate from the gateway above and not needed to use it.
Questions and bugs: GitHub issues. Security or privacy vulnerabilities: report privately, as described in SECURITY.md. Contributing: CONTRIBUTING.md (pytest needs no API key or network). License: Apache-2.0.
agent-budget ai-agents anthropic cost-attribution cost-control cost-tracking crewai developer-tools inference-gateway langgraph llm llm-budget llm-gateway openai openai-compatible per-run-budget self-hosted spend-limit
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.




