Metadata-Version: 2.5
Name: tokenrein
Version: 0.1.3
Summary: Budgets, run tracing and spend reports for AI agents: wrap your OpenAI or Anthropic client in one line
Project-URL: Homepage, https://tokenrein.com
Project-URL: Source, https://github.com/tokenrein/tokenrein
Project-URL: Issues, https://github.com/tokenrein/tokenrein/issues
Project-URL: Changelog, https://github.com/tokenrein/tokenrein/blob/main/CHANGELOG.md
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.9
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30; extra == 'anthropic'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Provides-Extra: test
Requires-Dist: anthropic>=0.30; extra == 'test'
Requires-Dist: openai>=1.0; extra == 'test'
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# 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](https://tokenrein.com); `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, ...).

```bash
pip install "tokenrein[openai]"   # or tokenrein[anthropic]
```

```python
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](https://github.com/tokenrein/tokenrein/blob/main/sdk/README.md) for the full API.

## Develop

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

License: Apache-2.0.
