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.

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 usage

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

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

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

Example usage object

print(cost.last_hour().model_dump_json(indent=4))
{
    "total_cost": 0.0004,
    "total_tokens": 79,
    "prompt_tokens": 52,
    "completion_tokens": 27,
    "providers": [
        {
            "total_cost": 0.0004,
            "total_tokens": 79,
            "prompt_tokens": 52,
            "completion_tokens": 27,
            "provider": "openai",
            "models": [
                {
                    "total_cost": 0.0004,
                    "total_tokens": 79,
                    "prompt_tokens": 52,
                    "completion_tokens": 27,
                    "model": "gpt-4o-2024-08-06"
                }
            ]
        }
    ]
}

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.10.tar.gz (14.0 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.10-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tokenator-0.1.10.tar.gz
  • Upload date:
  • Size: 14.0 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.10.tar.gz
Algorithm Hash digest
SHA256 8e38a546d4cfc222bb4076f70d9f5ad5c1ca63f1f6c8102dfdddbdcd491c652a
MD5 5744cc59dbeda2a09714d839833fb428
BLAKE2b-256 ec9a35976d074842f06188edfe81a2a5a9030d25a2cd9fe2fd7235870c86aae2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokenator-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 17.8 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 86e15de40670f52fc83192180b463aa9fdb3254e9d9244a06564f399379009d1
MD5 323fb94e149d295cc0557bfc53c1e123
BLAKE2b-256 a4d3d0938dd015a41faaeca2d9dbeb08db4b26b46a1bf49366cb13d35137992d

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