SDK & Integration · 6 min · Updated 2026-06-14

Python SDK reference

Complete API reference for the Tokeven Python wrapper

TokivenWrapper

The main class that wraps your AI provider client.

from tokeven import TokivenWrapper

tracked = TokivenWrapper(
    client,                    # Your Anthropic/OpenAI/Google client
    token="tkv_ing_...",      # Ingest token (or set TOKEVEN_INGEST_TOKEN env)
    session_id="my-session",  # Optional: group calls into sessions
    batch_size=10,            # Optional: events per batch (default 10)
    flush_interval=5,         # Optional: seconds between flushes (default 5)
)

Configuration options

OptionDefaultDescription
tokenenv varYour write-only ingest token
session_idautoGroups related calls together
batch_size10Events batched before sending
flush_interval5Seconds between batch flushes
enabledtrueToggle tracking on/off

Event schema

Each tracked call generates an event with:

  • event_id — client-generated UUID for idempotency
  • model — model ID used
  • input_tokens — prompt token count
  • output_tokens — completion token count
  • cache_read_tokens — tokens served from cache
  • cache_write_tokens — tokens written to cache
  • latency_ms — request duration
  • occurred_at — ISO 8601 timestamp

Track your real costs

Calculators estimate. The dashboard shows what you actually spend and where you can save.