Skip to main content

Token usage tracking wrapper for LLMs

Project description

Tokenator : Easiest way to track and analyze LLM token usage and cost

Have you ever wondered about :

  • How many tokens does your AI agent consume?
  • How much does it cost to do run a complex AI workflow with multiple LLM providers?
  • How much money did I spent today on development?

Afraid not, tokenator is here! With tokenator's easy to use API, you can start tracking LLM usage in a matter of minutes and track your LLM usage.

Get started with just 3 lines of code!

Installation

pip install tokenator

Usage

OpenAI

from openai import OpenAI
from tokenator import tokenator_openai

openai_client = OpenAI(api_key="your-api-key")

# Wrap it with Tokenator
client = tokenator_openai(openai_client)

# Use it exactly like the OpenAI client
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Cost Analysis

from tokenator import cost

# Get usage for different time periods
cost.last_hour()
cost.last_day()
cost.last_week()
cost.last_month()

# Custom date range
cost.between("2024-03-01", "2024-03-15")

# Get usage for different LLM providers
cost.last_day("openai")
cost.last_day("anthropic")
cost.last_day("google")

Example cost object


Features

  • Drop-in replacement for OpenAI, Anthropic client
  • Automatic token usage tracking
  • Cost analysis for different time periods
  • SQLite storage with zero configuration
  • Thread-safe operations
  • Minimal memory footprint
  • Minimal latency footprint

Most importantly, none of your data is ever sent to any server.

License

MIT

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

tokenator-0.1.6.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

tokenator-0.1.6-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file tokenator-0.1.6.tar.gz.

File metadata

  • Download URL: tokenator-0.1.6.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.0 Darwin/24.1.0

File hashes

Hashes for tokenator-0.1.6.tar.gz
Algorithm Hash digest
SHA256 72b8118a0c5602daf23fb04ea65f2dc6ca292c2c322dfc364b265a275b83525b
MD5 0de152a222b7d703976131c0c6ddc40e
BLAKE2b-256 d9f6c2c07f7df019ac47c68f12265bb6280caeea8de2dfa458f5b49bcb8f22d5

See more details on using hashes here.

File details

Details for the file tokenator-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: tokenator-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.0 Darwin/24.1.0

File hashes

Hashes for tokenator-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4df9dc777fe4b6719a3a1a0f47537b18822d110c6827d307df20286a1022aa07
MD5 d5408461ebf8ef320c0dba19eaec3952
BLAKE2b-256 bcaf6eff82cdd5b803b5fcf1f0d2fd3d9808f00c4c43f21d419736465e90c33f

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