Token Usage Analytics SDK
Lightweight, non-blocking Python SDK for tracking AI usage metrics across OpenAI, Anthropic, and Google AI providers.
PyPI: token-usage-analytics · GitHub: jinal09-codaemon/token-usage-sdk · Import: from ai_metering import ...
Installation
pip install token-usage-analytics
With provider-specific extras:
pip install token-usage-analytics[openai] # OpenAI support
pip install token-usage-analytics[anthropic] # Anthropic/Claude support
pip install token-usage-analytics[all] # All providers
Quick Start
from ai_metering import MeteringClient
client = MeteringClient(
api_key="usage_live_...",
endpoint="https://tokenusage.transitiv-dev.com",
)
client.track_llm(
provider="openai",
model="gpt-4",
input_tokens=150,
output_tokens=50,
feature="chat",
)
Or load from environment (see .env.example):
from ai_metering import AIUsage
usage = AIUsage.from_env()
Features
- Non-blocking: Usage tracking never delays your AI responses
- Multi-provider: OpenAI, Anthropic/Claude, Google Gemini
- Auto-extraction: Automatically extracts tokens from provider responses
- Reliable: Circuit breaker, retry queue, disk buffer for offline resilience
- Secure: HTTPS enforced, no PII in payloads
Auto-Tracking with Wrappers
from openai import OpenAI
from ai_metering import AIUsage
usage = AIUsage.from_env()
openai = usage.wrap(OpenAI())
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello"}],
usage_feature="my_feature",
)
Environment Variables
| Variable | Required | Description |
|---|---|---|
USAGE_SDK_API_KEY |
Yes | API key from Token Usage Analytics (usage_live_...) |
METERING_BASE_URL |
Yes (prod) | API base URL, e.g. https://tokenusage.transitiv-dev.com |
ORGANIZATION_ID |
No | Scope events to an organization |
AI_METERING_DEBUG |
No | Debug logging (true / false) |
Aliases: AI_METERING_API_KEY, METERING_API_KEY, AI_METERING_ENDPOINT
Copy .env.example to .env for local development.
Development
git clone https://github.com/jinal09-codaemon/token-usage-sdk.git
cd token-usage-sdk
python -m pip install -e ".[dev,openai]"
pytest tests/ -v
python -m build
See PUBLISHING.md and docs/GITHUB_SETUP.md for GitHub + PyPI release steps.
License
Proprietary - Transitiv Technologies. See LICENSE for details.
Support
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 token_usage_analytics-1.0.0.tar.gz.
File metadata
- Download URL: token_usage_analytics-1.0.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
877357a622e303f8e3e67cfef9e0c02950b42e9658e5e6572155c37a8435acfe
|
|
| MD5 |
af69b44ba4aaa968a3918523986112cb
|
|
| BLAKE2b-256 |
91170449be705793c91bc61a906793d216da4329ad809a07a397c29a0c0bdfc0
|
Provenance
The following attestation bundles were made for token_usage_analytics-1.0.0.tar.gz:
Publisher:
publish.yml on jinal09-codaemon/token-usage-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
token_usage_analytics-1.0.0.tar.gz -
Subject digest:
877357a622e303f8e3e67cfef9e0c02950b42e9658e5e6572155c37a8435acfe - Sigstore transparency entry: 2886466026
- Sigstore integration time:
-
Permalink:
jinal09-codaemon/token-usage-sdk@9e5b3565ff63805e87cde6b634a7f0cf9395e8ad -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/jinal09-codaemon
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e5b3565ff63805e87cde6b634a7f0cf9395e8ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file token_usage_analytics-1.0.0-py3-none-any.whl.
File metadata
- Download URL: token_usage_analytics-1.0.0-py3-none-any.whl
- Upload date:
- Size: 41.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378bce0f93987ccf1733d0d655855fa584ce371b6fd02673da12edef61ef1319
|
|
| MD5 |
90d9a62dfaa78785763d46bf66038d10
|
|
| BLAKE2b-256 |
ecf8f34d1c8f58aecadcf52fbbfaceb4a231d2606be2d60b886b76aebbae91a3
|
Provenance
The following attestation bundles were made for token_usage_analytics-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on jinal09-codaemon/token-usage-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
token_usage_analytics-1.0.0-py3-none-any.whl -
Subject digest:
378bce0f93987ccf1733d0d655855fa584ce371b6fd02673da12edef61ef1319 - Sigstore transparency entry: 2886466044
- Sigstore integration time:
-
Permalink:
jinal09-codaemon/token-usage-sdk@9e5b3565ff63805e87cde6b634a7f0cf9395e8ad -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/jinal09-codaemon
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e5b3565ff63805e87cde6b634a7f0cf9395e8ad -
Trigger Event:
push
-
Statement type: