tokenfuse (Python SDK)
Thin, dependency-free helpers to route an agent's LLM calls through the
TokenFuse gateway and turn its 402
blocks into typed exceptions.
TokenFuse is a drop-in proxy — you don't rewrite your agent, you point your provider client at the gateway and attach a few headers.
Install
pip install tokenfuse # (planned; for now: pip install -e sdk/python)
Use
import anthropic, tokenfuse
client = anthropic.Anthropic(
base_url=tokenfuse.gateway_url(), # http://127.0.0.1:4100
default_headers=tokenfuse.run_headers("run-42", budget_usd=5.0, task_type="code-review"),
)
try:
msg = client.messages.create(model="claude-sonnet", max_tokens=1024, messages=[...])
except tokenfuse.BudgetExceeded as e:
print(f"run {e.run_id}: spent ${e.spent_usd} of ${e.budget_usd}")
except tokenfuse.LoopDetected as e:
print(f"runaway loop on {e.run_id}: {e.reason}")
For raw HTTP clients (requests / httpx), call tokenfuse.check_response(resp)
after the request, or tokenfuse.raise_for_fuse(status_code, body).
Exceptions
All inherit tokenfuse.FuseError (fields: run_id, budget_usd, spent_usd,
policy_id, reason):
BudgetExceeded— the run's budget would be exceededLoopDetected— a runaway loop was detectedPolicyViolation— a policy limit was hitKilled— an operator killed the run
Metadata
Release files for tokenfuse-sdk 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tokenfuse_sdk-0.3.0.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tokenfuse_sdk-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / tokenfuse_sdk-0.3.0.tar.gz
| Download URL | tokenfuse_sdk-0.3.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea76c4ca7a85932f9d44995998801f0c5885aec727e92cb63ca37b029ace4089
|
|
BLAKE2b-256 checksum How to use checksums |
b3ac1ca1a7d2fd6def99ac67abaee97e606609086cb91103ce77b6ee37b2ec58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / tokenfuse_sdk-0.3.0-py3-none-any.whl
| Download URL | tokenfuse_sdk-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
629cf79dbaa6901a4f00907ba85ca26ca99c37a468fb723955109cbb87ea37e9
|
|
BLAKE2b-256 checksum How to use checksums |
f2fb0ec8f9ef8f6d8af22a515d88c84b46df36fc43c02891d8eb90e5b5d109d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|