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 ../README.md 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.1

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

Built distribution (wheel)

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

Total release size: 45.6 kB

Release files / tokenrein-0.1.1.tar.gz

Download URL tokenrein-0.1.1.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8ad9028a848b2d4064ddb99d40059b060107a58328207afb38be8b2ac0a06fb3
BLAKE2b-256 checksum
How to use checksums
0850de822b165cc5547668bfc7f75cdecd5bee48b9b3b9777f8059e5f72ef22c
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.1-py3-none-any.whl

Download URL tokenrein-0.1.1-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dc3ee956a64a43265c49c8a25396418bb5a186e7263cf35d89a9b4e61a82019
BLAKE2b-256 checksum
How to use checksums
22dd096424544814a5795484e0a78e99d742e420714399ea2d6f9c7b5e7c94ea
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.1

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