Audit, compress and monitor your LLM token usage in 2 lines of code
Project description
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
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 tokoscope-0.2.0.tar.gz.
File metadata
- Download URL: tokoscope-0.2.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f25daafc9414e363059c5af4c0d9a42a61cdca8ae23333815677205c5a99004
|
|
| MD5 |
cc545b6bfdfb61cb359638508d983c81
|
|
| BLAKE2b-256 |
45cb160ec899669e16983f8b1283e17fce53f88f5665d91b29b42449dae78af8
|
File details
Details for the file tokoscope-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tokoscope-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5754c404bb2fabc66bc3195d229b27a2ac114b54866f681a63a8b5dec33085ca
|
|
| MD5 |
6b2dd86808e88d3eed128fc559136767
|
|
| BLAKE2b-256 |
92086affa0822213f701c7d1b16ced79921cc845a0d354c777faae4cfbc542dc
|