Report-only usage tracking for OpenAI, Anthropic, Gemini, DeepSeek, xAI, Mistral, Qwen, GLM, Kimi and OpenRouter — wrap your client, we read the tokens.
Project description
tokli
Report-only usage tracking for tokli — a cost & usage dashboard for AI APIs. Wrap your existing provider client, keep calling it exactly as before, and tokli reports the token usage in the background. We never see your provider API key and we never sit in your request's critical path.
Supports OpenAI, Anthropic, Gemini, DeepSeek, xAI, Mistral, Qwen, GLM, Kimi and OpenRouter.
0.0.0is a placeholder release reserving the name. The wrappers land in0.1.0.
Install
pip install tokli
openai, anthropic and google-genai are optional extras — tokli has zero runtime
dependencies and never pulls a provider SDK into your app.
Quickstart
from openai import OpenAI
from tokli import wrap_openai
client = wrap_openai(OpenAI()) # ingest key from TOKLI_INGEST_KEY
client.chat.completions.create(model="gpt-5.4", messages=messages)
The returned client behaves exactly like the original: every attribute we don't instrument
passes straight through, and isinstance(client, OpenAI) still holds. AsyncOpenAI works
through the same wrap_openai — there is no separate async wrapper.
Without an ingest key (neither the ingest_key argument nor TOKLI_INGEST_KEY), the wrapper
is a silent no-op: your app keeps working exactly as before, nothing is reported.
Config
| Argument | Env var | Default | Notes |
|---|---|---|---|
ingest_key |
TOKLI_INGEST_KEY |
— | Required. Without it, the wrapper is a no-op. |
endpoint |
TOKLI_ENDPOINT |
https://api.tokli.dev |
Ingest API base URL. |
timeout_ms |
TOKLI_TIMEOUT_MS |
2000 |
Timeout for the fire-and-forget report request. |
flush_ms |
TOKLI_FLUSH_MS |
2000 |
How long to wait at exit for pending reports; 0 disables. |
on_error |
— | no-op | Called if reporting fails; never raises into your code. |
How it works
Your code keeps calling the provider with your own key. After the response comes back, the SDK
reads the usage object already present in it and sends those raw numbers to tokli,
fire-and-forget — it never blocks your request, your event loop, or your key. Cost is computed
server-side against a versioned price table, not by the SDK.
Reporting can never break your app: if anything in our own path raises — including your
on_error handler — you still get the provider's response untouched.
Links
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 tokli-0.0.0.tar.gz.
File metadata
- Download URL: tokli-0.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2849b17f7eb002da70589fa3b21a9d6f133d24053f70663629f38b589ff5136d
|
|
| MD5 |
d9c85909486414f12483c55c51cacffa
|
|
| BLAKE2b-256 |
fed850ba3258482185fb79662c119cdb59ccbbcbbbba28451589e5bd11d8c889
|
File details
Details for the file tokli-0.0.0-py3-none-any.whl.
File metadata
- Download URL: tokli-0.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f156e4c21aedb1ef0c73b914b07f1102c2a440fc226aed80da2158b4fec48654
|
|
| MD5 |
bf81b2c44a5311c1083aaba34e2bbd28
|
|
| BLAKE2b-256 |
0bd51c6d3a6f1e91c50ca50b0d9e6e9a3c893aeff728a8115e9b4b8c7700baa2
|