Skip to main content

Google Gemini token tracker that automatically logs prompts, responses, and token usage

Project description

SuperTokenTracker (Python)

Google Gemini token tracker that automatically logs prompts, responses, and token usage.

Drop-in replacement for google-genai - just change your import!

Installation

pip install supertokentracker

Quick Start

from supertokentracker import genai

client = genai.Client(api_key="YOUR_API_KEY")

response = client.models.generate_content(
    model="gemini-2.0-flash-exp",
    contents="Why is the sky blue?"
)

print(response.text)

requests = client.get_tracked_requests()
print(f"Total tokens used: {requests[0]['usage']['totalTokens']}")

Migration from google-genai

Simply replace:

from google import genai  # Before

With:

from supertokentracker import genai  # After

Everything else stays the same!

Features

  • Drop-in replacement for google-genai package
  • Automatic token tracking for all Gemini API calls
  • Local JSON file storage or remote tracking
  • Tracks errors, metadata, and response times
  • Zero-config setup

Configuration

Local Storage (default)

from supertokentracker import genai

client = genai.Client(
    api_key="YOUR_API_KEY",
    local_storage={
        "file_path": "./custom-logs.json",
        "auto_save": True
    }
)

Remote Storage

from supertokentracker import genai

client = genai.Client(
    api_key="YOUR_GEMINI_API_KEY",
    storage="remote",
    remote_storage={
        "api_key": "YOUR_AITRACKER_API_KEY",
        "project_name": "my-project"
    }
)

View tracked requests at aitracker.dev

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

supertokentracker-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

supertokentracker-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file supertokentracker-0.1.0.tar.gz.

File metadata

  • Download URL: supertokentracker-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for supertokentracker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be3cb8e10e74194d4d7930de4a148e158c0ce950e7520ac99460c980b51b88a9
MD5 e525b17cb5a609c6dfae0b126c1b592d
BLAKE2b-256 8d17722768ee984eeede44b4d5d2bacfa879aa6127e172d521a9650fe534b7d9

See more details on using hashes here.

File details

Details for the file supertokentracker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for supertokentracker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3242a3da89aadb8fafe7969763440dd7931842a5bf4614a0bd7080b495708c37
MD5 1643ac78286b9b006303639d102b9c18
BLAKE2b-256 658adb6379217b0e36a698dd7de62073ae2f1decba6148899c841942e72c8f7d

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