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.3.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.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for supertokentracker-0.2.3.tar.gz
Algorithm Hash digest
SHA256 7ace464340ddd075cea9880d7f232500c358f77819c68786873532497be86cb8
MD5 51952b87eda574ec1678ff6a38b0d099
BLAKE2b-256 e16b15c68446d9e0ddb1b4f1aade6cb8d374d334f51e1783b7c771cb1dd4530c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for supertokentracker-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4c76af15c1015b5a76a1c89409cee6df24c4052b088c63c2bd2e1f6203ee68af
MD5 f8ad87cb254e96646646d443c11fd319
BLAKE2b-256 ff445a9dfa91eb8da92ac37e4c4f68e5b0305ea4cc0a06a104da28b38a2e907e

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