Skip to main content

Zero-config AI usage tracking — wrap any OpenAI/Anthropic/Gemini client and log to your TokenGauge dashboard

Project description

TokenGauge SDK

Zero-config AI usage tracking. Wrap your existing OpenAI, Anthropic, or Google Gemini client with one line — every call is automatically logged to your TokenGauge dashboard.

Your API keys stay with you. The SDK only reads token counts from API responses and sends them to TokenGauge. Nothing is proxied.

Install

pip install tokengauge

Quick start

  1. Sign up at tokengauge.onrender.com and copy your SDK token from Settings.

  2. Wrap your client:

from tokengauge import TokenGauge
import openai

tw = TokenGauge(token="your-sdk-token")
client = tw.wrap(openai.OpenAI(api_key="sk-..."))

# Use exactly as before — usage appears on your dashboard automatically
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Anthropic

from tokengauge import TokenGauge
import anthropic

tw = TokenGauge(token="your-sdk-token")
client = tw.wrap(anthropic.Anthropic(api_key="sk-ant-..."))

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.content[0].text)

Google Gemini

from tokengauge import TokenGauge
from google import genai

tw = TokenGauge(token="your-sdk-token")
client = tw.wrap(genai.Client(api_key="your-gemini-key"))

response = client.models.generate_content(
    model="gemini-1.5-flash",
    contents="Hello!",
)
print(response.text)

Async clients

from tokengauge import TokenGauge
import openai, asyncio

tw = TokenGauge(token="your-sdk-token")
client = tw.wrap(openai.AsyncOpenAI(api_key="sk-..."))

async def main():
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Tag calls by feature

summarizer = tw.wrap(openai.OpenAI(api_key="sk-..."), app_tag="summarizer")
chatbot    = tw.wrap(openai.OpenAI(api_key="sk-..."), app_tag="chatbot")

Login instead of pasting a token

tw = TokenGauge.login(email="you@example.com", password="your-password")

What gets tracked

Field Description
Provider openai / anthropic / google
Model e.g. gpt-4o-mini, claude-3-5-sonnet
Tokens in Prompt token count
Tokens out Completion token count
Cost (USD) Calculated from current model pricing
Latency End-to-end request time in ms
App tag Optional label you set per-client

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

tokengauge-0.2.4.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

tokengauge-0.2.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file tokengauge-0.2.4.tar.gz.

File metadata

  • Download URL: tokengauge-0.2.4.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for tokengauge-0.2.4.tar.gz
Algorithm Hash digest
SHA256 6082e462673d33639ce295f6f0ef6eacee8a268c7aeedbca6b494caa83119014
MD5 ecbc3ab0f08e32d6d95d7ffc24cd7d5b
BLAKE2b-256 8b1f3a32bc4a6d2bb9274ee8ad64b583e1f88bef1022f99b56fadb17aa370203

See more details on using hashes here.

File details

Details for the file tokengauge-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: tokengauge-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for tokengauge-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 23592f6089ee9c505980d71c20558536f56604100719ec1755ec05e5171f420f
MD5 2d6ccce4cca95c4a42eb582047636b86
BLAKE2b-256 9ad62022e18aba0dd3dbbfde90f41335217e11efbc3531033ee21597bc81e011

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