Zero-config AI usage tracking — wrap any OpenAI/Anthropic client and log to your TokenWatch 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
-
Sign up at tokenwatch.ai and copy your API token from the dashboard.
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokenwatch_sdk-0.1.4.tar.gz.
File metadata
- Download URL: tokenwatch_sdk-0.1.4.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb40853ea5b7e99c765f5b9015366a24f8470dde457c6d7a040f1db81fa201d
|
|
| MD5 |
d48769a650741e188e181d6bb8dc5eb2
|
|
| BLAKE2b-256 |
a86e977115e73d19617c52fbd89e7b4eb63c61b53af3a9a079eb79f6478ab491
|
File details
Details for the file tokenwatch_sdk-0.1.4-py3-none-any.whl.
File metadata
- Download URL: tokenwatch_sdk-0.1.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1643c9f7fa967d20e15e563604e9cd4088aa53c9da5b099dd353957d7749e5b
|
|
| MD5 |
d3767beffb1688bb15940067e31f550e
|
|
| BLAKE2b-256 |
d9ee67e1d224e8763b0a5bcbaad5275558ef245294f20e8acb0cb327f647811a
|