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

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

Built distribution (wheel)

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

Total release size: 45.6 kB

Release files / tokenrein-0.1.2.tar.gz

Download URL tokenrein-0.1.2.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7f9752b1d2efa774ddf2dcbedc4578fee922a99336d98d9c9d43357111c91263
BLAKE2b-256 checksum
How to use checksums
da432137d43360f8396e0aa545c30597f59469f90b7b3ab7ba3137052a00f489
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 Oct 31, 2026.

Transparency log

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

Download URL tokenrein-0.1.2-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc9d0d90e81f09cb6bf1755a3bfc632631fdc608c9a51eefcda82d9972d69b01
BLAKE2b-256 checksum
How to use checksums
bdcf726078f74c13b212ceed9e64f95c84077f399ed3dec53f236ef9283e5745
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 Oct 31, 2026.

Transparency log

Security for tokenrein 0.1.2

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.2.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 Oct 31, 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