Python SDK
Drop-in wrappers for Anthropic, OpenAI, xAI, Google, AWS Bedrock, Cohere, and Mistral that capture every call to your TokenID dashboard.
Installation
pip install --extra-index-url https://tokenid:@pypi.token.audit.id/simple/ tokenid
What gets captured
| Field | Description |
|---|---|
provider |
anthropic, openai, xai, google, aws_bedrock, azure_openai, cohere, mistral |
model |
Exact model string from the response |
input_tokens |
Prompt tokens |
output_tokens |
Completion tokens |
cache_read |
Anthropic prompt cache read tokens |
cache_creation |
Anthropic prompt cache creation tokens |
reasoning_tok |
OpenAI reasoning tokens (o-series), Gemini thoughtsTokenCount |
cached_tok |
OpenAI cached prompt token count |
is_batch / batch_id |
Set automatically when the wrapper detects a Batch API response — cost is computed at 50% rate |
team_id / feature |
Optional kwargs for sub-organization attribution (see below) |
cost_usd |
Computed from live rate card at call time |
session_id |
Your identifier — groups calls into sessions |
tool_name / tool_input / tool_output |
Per tool_use and tool_result block |
duration_ms |
Wall-clock latency |
stop_reason |
end_turn, max_tokens, etc. |
Wrappers
Anthropic JournaledAnthropic JournaledOpenAI JournaledGrok JournaledBedrock JournaledCohere JournaledMistral
Team and feature labels
Pass optional team_id / feature kwargs to the wrapper constructor (applies to every call) or
per-call (overrides the constructor value):
client = JournaledAnthropic(
api_key="sk-ant-…",
team_id="platform-ai",
feature="rag-rerank",
)
Both columns are indexed and queryable on dashboard breakdown endpoints. Use them for internal chargeback or product-level cost attribution.
Streaming
All wrappers support streaming responses. Usage is captured from the final message_delta event.
with client.messages.stream(
model="claude-opus-4-7",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Error handling
If the ingest call to TokenID fails, the original API call still succeeds and your code runs normally. TokenID never blocks your critical path.