Skip to main content

Tokvera Python SDK for provider tracking, manual tracing, and runtime integrations

Project description

tokvera

Python SDK for Tokvera AI cost and trace telemetry.

Current version: 0.2.9

What It Tracks

  • OpenAI
  • Anthropic
  • Gemini
  • Mistral

Tracked calls emit normalized telemetry to Tokvera ingest (/v1/events) with:

  • latency, status, model, token usage
  • trace context (trace_id, run_id, span_id, parent_span_id, conversation_id)
  • evaluation signals (outcome, retry_reason, fallback_reason, quality_label, feedback_score)
  • optional v2 trace fields (span/tool metadata, payload refs/blocks, per-step metrics, routing decisions)

Install

pip install tokvera

For local development:

pip install -e .[dev]

Quick Start

from openai import OpenAI
from tokvera import track_openai

openai_client = OpenAI(api_key="sk-...")

tracked = track_openai(
    openai_client,
    api_key="tkv_project_key",
    feature="support_bot",
    tenant_id="acme",
    environment="production",
    step_name="draft_reply",
    emit_lifecycle_events=True,
)

tracked.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)

Enable emit_lifecycle_events=True when you want /dashboard/traces/live to show a run immediately at call start and keep it marked as processing until the terminal event lands.

Set ingest URL:

export TOKVERA_INGEST_URL="https://api.tokvera.org/v1/events"

Integration Helpers

  • Existing app / manual tracing:
    • create_tracer(...)
    • start_trace(...)
    • start_span(...)
    • finish_span(...)
    • fail_span(...)
    • attach_payload(...)
    • get_track_kwargs_from_trace_context(...)
  • Mistral:
    • track_mistral(...)
  • Claude Agent SDK:
    • configure_claude_agent_sdk(...)
  • Google ADK:
    • configure_google_adk(...)
  • LangGraph:
    • create_langgraph_tracer(...)
  • Instructor:
    • create_instructor_tracer(...)
  • PydanticAI:
    • create_pydanticai_tracer(...)
  • CrewAI:
    • create_crewai_tracer(...)
  • Wave 2 beta runtimes:
    • create_autogen_tracer(...)
    • create_mastra_tracer(...)
    • create_temporal_tracer(...)
    • create_pipecat_tracer(...)
    • create_livekit_tracer(...)
    • create_openai_compatible_gateway_tracer(...)
  • OpenTelemetry bridge:
    • TokveraOTelSpanExporter
  • FastAPI middleware:
    • create_fastapi_tracking_middleware(...)
    • get_fastapi_track_kwargs(...)
  • Django middleware:
    • create_django_tracking_middleware(...)
    • get_django_track_kwargs(...)
  • Background jobs:
    • create_background_job_context(...)
    • get_background_track_kwargs(...)
  • Celery:
    • create_celery_task_context(...)
    • get_celery_track_kwargs(...)
  • LangChain:
    • create_langchain_callback_handler(...)
  • LlamaIndex:
    • create_llamaindex_callback_handler(...)

Trace Schema Support

  • v1 schema version: 2026-02-16
  • v2 schema version: 2026-04-01

Contract references:

  • tokvera-api/docs/event-envelope-v1.contract.json
  • tokvera-api/docs/event-envelope-v2.contract.json
  • tokvera-api/docs/SCHEMA_COMPATIBILITY_POLICY.md

Privacy Behavior

  • Tracking is fire-and-forget and non-blocking
  • Prompt/output content is not required
  • If v2 content capture is enabled, payload hashes/blocks are included based on options

Examples

  • examples/manual_tracer.py
  • examples/agent_runtimes.py
  • examples/beta_runtime_helpers.py
  • examples/fastapi_middleware.py
  • examples/django_middleware.py
  • examples/background_jobs.py
  • examples/celery_task.py

Realtime Tracing

  • /dashboard/traces is the main engineering workspace for execution, payload, and optimization debugging.
  • /dashboard/traces/live is the realtime feed for active and recently completed runs.
  • Lifecycle start events are additive. They do not replace the normal terminal success/failure event.

Test

pytest

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

tokvera-0.2.9.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokvera-0.2.9-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file tokvera-0.2.9.tar.gz.

File metadata

  • Download URL: tokvera-0.2.9.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for tokvera-0.2.9.tar.gz
Algorithm Hash digest
SHA256 f0941871e6d3ca427881b7445cac62480ced067e8d6bef783d98f57392d16cf7
MD5 af53588cef3081c717a88fae69e8d359
BLAKE2b-256 4a41ea863afe267a0a240f87742d384430601e7e265acc07bb9ab7951bc89333

See more details on using hashes here.

File details

Details for the file tokvera-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: tokvera-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for tokvera-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6cea4beba84709a8e48c82f50c282c232efb63c888202a776394e89c2412544e
MD5 c24f3ecfb874f99122587d275047b551
BLAKE2b-256 6b5d6c92929f3014758527516bb62a393f72f32267dd70e134bc7a359e4925c6

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