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.2.tar.gz (7.5 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.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: supertokentracker-0.2.2.tar.gz
  • Upload date:
  • Size: 7.5 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.2.tar.gz
Algorithm Hash digest
SHA256 71c25102e5e793637dbc4ea407256194f005c5e95e4eb8662aed4f2c518ce4a9
MD5 2645433eae9330a0b1d0bef7eb901c62
BLAKE2b-256 a7ea76e93eae0815df44f169d21b5b0587329edd51112ab42f13fed115f9e37f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for supertokentracker-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 babf0e2fc432d94bca46f1792b4c1ff4ad03b390feba11e9eb5b2ecaf76ac343
MD5 11b93937b3eff0284a38f07c3b6ea85f
BLAKE2b-256 aec7663b9b9966018b073c9574cbe6832825b727a4846f1d902e999b364d3009

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