Skip to main content

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

Project description

TokenWatch SDK

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

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

Install

pip install tokenwatch-sdk

Quick start

  1. Sign up at tokenwatch.ai and copy your API token from the dashboard.

  2. Wrap your client:

from tokenwatch import TokenWatch
import openai

tw = TokenWatch(token="your-token-here", base_url="https://your-server.com")

# One-line wrap — use the client exactly as before
client = tw.wrap(openai.OpenAI(api_key="sk-..."))

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
)
# Token usage now appears on your dashboard automatically

Anthropic

import anthropic

client = tw.wrap(anthropic.Anthropic(api_key="sk-ant-..."))

response = client.messages.create(
    model="claude-3-haiku-20240307",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello!"}],
)

Async clients

import openai, asyncio

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!"}],
    )

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 = TokenWatch.login(
    email="you@example.com",
    password="your-password",
    base_url="https://your-server.com",
)

Google Colab example

!pip install tokenwatch-sdk openai

from tokenwatch import TokenWatch
import openai

tw = TokenWatch(token="paste-your-token-here", base_url="https://your-server.com")
client = tw.wrap(openai.OpenAI(api_key="sk-..."))

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize the theory of relativity in one paragraph."}],
)
print(response.choices[0].message.content)

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.1.5.tar.gz (6.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.1.5-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tokengauge-0.1.5.tar.gz
  • Upload date:
  • Size: 6.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.1.5.tar.gz
Algorithm Hash digest
SHA256 0e23bfa0ecd80ca16012b5a2b9522d544bc26e2d0d555f7720698497141ad900
MD5 02d02960448701641282a99d7d55d1c4
BLAKE2b-256 0801752b84b3099f17c073b11f8767434f5edd8050bc3929a4282f006883afaa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokengauge-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.5 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.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 16251160027956424f2cecb3143c90172ef855a1da1880731b82d489a076113b
MD5 1c42bdf7829304c8736d7986bca2ac1a
BLAKE2b-256 0636804db22f053b8a56635028f25c9763066b12f79ea732eac8fd12c692f116

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