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 tokentracker.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.2.1.tar.gz (7.4 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.2.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for supertokentracker-0.2.1.tar.gz
Algorithm Hash digest
SHA256 720b19d1e5a613980374da9b33cb573332db7ecd012eb6a85fe90bd879444e17
MD5 e47b51386e8309648ed265ccfb18a691
BLAKE2b-256 860711083f21d53dd65a75a30792ab2ab8cda0128d1421621a8845be1ed74229

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for supertokentracker-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a14b022f3831bc4de0ce1efb493c9fdc891de66635168d66705cb220ee9bcdc7
MD5 bef5f7a8b3973ca3a0cb24f66d0de27b
BLAKE2b-256 43359e4f82854423187d80038de0c4489b2c41d62244af8ef9d060f37c6711ba

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