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.1.3

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.1.3
File Size Uploaded Provenance Actions
tokenrein-0.1.3.tar.gz 24.6 kB With provenance Details for tokenrein-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 45.6 kB

Release files / tokenrein-0.1.3.tar.gz

Download URL tokenrein-0.1.3.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6e12df8b7380c15e999038cc9b8ee7725e2aa506073113e3d22910425e7d77a8
BLAKE2b-256 checksum
How to use checksums
352b0ce5c7e0250e44c43eab555a8498209054f8a760f4497e2161a817702910
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 1, 2026.

Transparency log

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

Download URL tokenrein-0.1.3-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
645301bb9652b97f3aa73f4ed0ddc120e320a831f8af3fda4a712526ba0d657c
BLAKE2b-256 checksum
How to use checksums
346a41ecf919066cd708d006b0696a55e9106f53225218092c0e41a1ad7aa4b0
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 1, 2026.

Transparency log

Security for tokenrein 0.1.3

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokenrein-0.1.3.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 1, 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