Skip to main content

tokenrein (Python)

Budgets, run tracing and spend reports for AI agents, in one line around your existing OpenAI or Anthropic client. By default (direct mode) the client keeps calling its provider and only token usage goes to Tokenrein; mode="proxy" sends calls through the Tokenrein proxy instead. Errors: BudgetExceeded, RunPaused, RunKilled. Works with any OpenAI-compatible provider (Gemini, Groq, Mistral, DeepSeek, OpenRouter, Ollama, ...).

pip install "tokenrein[openai]"   # or tokenrein[anthropic]
from openai import OpenAI
from tokenrein import guard, BudgetExceeded

client = guard.openai(OpenAI(), agent="support-bot")   # TOKENREIN_API_KEY, TOKENREIN_BASE_URL
with guard.run("ticket-4812", budget_usd=5):
    with guard.run(budget_usd=1):                       # sub-agent: parent set automatically
        client.chat.completions.create(model="gpt-4o-mini", messages=[...])

See the SDK guide for the full API.

Develop

python3 -m venv .venv && .venv/bin/pip install -e ".[test]"
.venv/bin/pytest

License: Apache-2.0.

Metadata

Release files for tokenrein 0.2.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 tokenrein 0.2.0
File Size Uploaded Provenance Actions
tokenrein-0.2.0.tar.gz 26.5 kB With provenance Details for tokenrein-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenrein 0.2.0
File Interpreter ABI Platform Actions
tokenrein-0.2.0-py3-none-any.whl Python 3 none any Details for tokenrein-0.2.0-py3-none-any.whl

Total release size: 49.2 kB

Release files / tokenrein-0.2.0.tar.gz

Download URL tokenrein-0.2.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
24a255a76c34be02c703a468189b513bf2a9c1c970863c11c1ab9c42dec572c1
BLAKE2b-256 checksum
How to use checksums
0d355e9b8e9688fe655ce344cbba759b0326ecf20bf77a4a3fe836ebd588f737
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / tokenrein-0.2.0-py3-none-any.whl

Download URL tokenrein-0.2.0-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16a312ea7670aa2de53d148ba37ad85e6364cad738cef96a31872de1f54f5688
BLAKE2b-256 checksum
How to use checksums
e2457019ede792fab8a7b76e84be7b2efa81b632a78a023c5d6bd7dbb429129a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for tokenrein 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokenrein-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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.

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