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

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

Built distribution (wheel)

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

Total release size: 45.6 kB

Release files / tokenrein-0.1.4.tar.gz

Download URL tokenrein-0.1.4.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c7e55561c510eaf6392aab888aa5a293a171d5fdc8cda6908d0a1ace9b67dd3f
BLAKE2b-256 checksum
How to use checksums
627cb116fc25c13fd94a93f9f6291556c8c7f452bb0982266eb23a1c86e3b1a0
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.4-py3-none-any.whl

Download URL tokenrein-0.1.4-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03ea8b9e3c7c5901eedf7963e8cede22d146f493d7d98fbd22b7c239b2f4fcac
BLAKE2b-256 checksum
How to use checksums
f04ac56964537302c18315a5de651a9a8304004313d61df1d35874974c420163
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.4

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