Tokoscope Python SDK
Audit, compress, and monitor your LLM token usage in 2 lines of code.
Tokoscope sits between your app and any LLM API. It tracks every call, scores your prompts for waste, compresses bloated inputs automatically, and shows you exactly where your token budget is going.
Works with OpenAI and Anthropic out of the box.
Installation
pip install tokoscope
Quick start
OpenAI
from openai import OpenAI
from tokoscope import wrap
client = wrap(OpenAI(), api_key="ts_live_...") # get your key at app.tokoscope.com
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
Anthropic
from anthropic import Anthropic
from tokoscope import wrap
client = wrap(Anthropic(), api_key="ts_live_...")
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
)
print(response.content[0].text)
That's it. Every API call is now tracked automatically.
Real example
Original prompt: 113 tokens
Please note that it is very important that you make sure to respond
to my question. As an AI, I want you to please make sure that you
understand that I need you to help me...
What is the capital of France?
Tokoscope compressed: 8 tokens
What is the capital of France? Answer concisely.
Result: 90% token reduction. Same answer.
What you get
Once integrated, your Tokoscope dashboard shows:
- Token usage broken down by model, endpoint, and provider
- Cost per request calculated automatically using current pricing
- Waste score for every prompt
- Auto-compression — prompts with high waste scores are automatically rewritten
- Budget alerts — get notified before costs spike
Supported providers
| Provider | Status |
|---|---|
| OpenAI | ✅ Supported |
| Anthropic | ✅ Supported |
| Gemini | 🔜 Coming soon |
| Mistral | 🔜 Coming soon |
Requirements
- Python 3.8+
requestslibrary (installed automatically)
License
MIT
Links
Metadata
Release files for tokoscope 0.9.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 | Provenance | |
|---|---|---|---|---|
| tokoscope-0.9.0.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tokoscope-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / tokoscope-0.9.0.tar.gz
| Download URL | tokoscope-0.9.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e00285ffa99bf06c418fb4168ea1af2ef91dcba9e1fd2c59bbb7d4bce9138ad
|
|
BLAKE2b-256 checksum How to use checksums |
ebead9aa7d42f6e94d3dcf194a3951c15644b646ceabcf207f8e812faab0158e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / tokoscope-0.9.0-py3-none-any.whl
| Download URL | tokoscope-0.9.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28eafcc11041e684a332f1fb8ffa9e0ba6bb0409e9020dc4c2828e39787b5e6a
|
|
BLAKE2b-256 checksum How to use checksums |
182f216a3afde632b6a9e843eca72ec3f7399aa22743efa544ba6bcc092dfaef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for tokoscope 0.9.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.