LLM token observability SDK — wraps OpenAI and Anthropic clients to capture metadata
Project description
tokensor
LLM token observability for Python. Wraps your OpenAI or Anthropic client to capture call metadata (model, tokens, cost) and forward it to your Tokensor dashboard — one line of code, zero latency overhead.
Install
pip install tokensor
# With OpenAI support:
pip install "tokensor[openai]"
# With Anthropic support:
pip install "tokensor[anthropic]"
Quickstart
Get your API key from app.tokensor.com → Settings → API Keys.
OpenAI:
import os
import openai
import tokensor
client = tokensor.wrap(
openai.OpenAI(),
api_key=os.environ["TOKENSOR_API_KEY"],
)
# Use exactly like openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
Anthropic:
import os
import anthropic
import tokensor
client = tokensor.wrap(
anthropic.Anthropic(),
api_key=os.environ["TOKENSOR_API_KEY"],
)
message = client.messages.create(
model="claude-3-5-haiku-latest",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
Environment variables
| Variable | Required | Description |
|---|---|---|
TOKENSOR_API_KEY |
yes | Your Tokensor API key |
TOKENSOR_HOST |
no | Override API host (default: https://api.tokensor.com) |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokensor-0.1.0.tar.gz.
File metadata
- Download URL: tokensor-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8df03e7785675fad703ac46b4478d9ea59c202bc57da99447cd30f4cd0eccb62
|
|
| MD5 |
b190a930bfd29bcf770c68ff8ee01a08
|
|
| BLAKE2b-256 |
bbc6f8890b67c68eae77de3ac2d11fa3bd3b5ce14a3da8dea17044b691cc5804
|
Provenance
The following attestation bundles were made for tokensor-0.1.0.tar.gz:
Publisher:
publish-sdk.yml on motiisr/tokensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokensor-0.1.0.tar.gz -
Subject digest:
8df03e7785675fad703ac46b4478d9ea59c202bc57da99447cd30f4cd0eccb62 - Sigstore transparency entry: 1666247357
- Sigstore integration time:
-
Permalink:
motiisr/tokensor@5ffd027b71305c05d23ee53a174cce9a301685f3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/motiisr
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@5ffd027b71305c05d23ee53a174cce9a301685f3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tokensor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokensor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e70c571f9ad462ada460355300140715ad50ab55b9217a10fc82b2a9198e2cd
|
|
| MD5 |
0dad0beecb24cdb76c7a0219608aa23e
|
|
| BLAKE2b-256 |
9da9570b82ed93d3570ee09bc565e5951116613cc7c46dacd84de476e505169f
|
Provenance
The following attestation bundles were made for tokensor-0.1.0-py3-none-any.whl:
Publisher:
publish-sdk.yml on motiisr/tokensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokensor-0.1.0-py3-none-any.whl -
Subject digest:
5e70c571f9ad462ada460355300140715ad50ab55b9217a10fc82b2a9198e2cd - Sigstore transparency entry: 1666247422
- Sigstore integration time:
-
Permalink:
motiisr/tokensor@5ffd027b71305c05d23ee53a174cce9a301685f3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/motiisr
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@5ffd027b71305c05d23ee53a174cce9a301685f3 -
Trigger Event:
push
-
Statement type: