Skip to main content

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.

PyPI version PyPI downloads License: MIT Python 3.8+

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+
  • requests library (installed automatically)

License

MIT


Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokoscope-0.7.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokoscope-0.7.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file tokoscope-0.7.0.tar.gz.

File metadata

  • Download URL: tokoscope-0.7.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tokoscope-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e2fd367ca104d92e5a8e70cc18479a5fb08cb731e48cec351f57f1b894d31831
MD5 dd8e2b2740b0e3381633bb2eace94677
BLAKE2b-256 193baf4ea70f6780f6d2d80ef9d8d6c69fa65353f6c1e1125d67451f4a5f8bcd

See more details on using hashes here.

File details

Details for the file tokoscope-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: tokoscope-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tokoscope-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06b043388c6d391f76e15a723d413fd4d349bd06707452dc6a53ae5b9156367d
MD5 a169373dd573ba41dd57842772a751de
BLAKE2b-256 26e90faa3da1f65b7b2921cc484cbfbd2e1a06e3b87284fd03c90744a2a6e151

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page