Skip to main content

Lightweight OpenAI analytics tracking wrapper

Project description

tokvera

tokvera is a lightweight Python SDK that wraps the official OpenAI client and emits usage analytics in a fire-and-forget way.

Installation

pip install tokvera

For development:

pip install -e .[dev]

Environment Variable Setup

Set your ingestion endpoint:

# Linux/macOS
export TOKVERA_INGEST_URL="https://your-ingest-endpoint/v1/events"

# Windows PowerShell
$env:TOKVERA_INGEST_URL = "https://your-ingest-endpoint/v1/events"

If TOKVERA_INGEST_URL is not set, analytics are skipped automatically.

Quick Start

from openai import OpenAI
from tokvera import track_openai

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

client = track_openai(
    openai_client,
    api_key="tokvera_project_key",
    feature="support_bot",
    tenant_id="acme",
    plan="pro",
    environment="production",
    template_id="support_v3",
    capture_content=False,
)

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

Event Schema

Events include:

  • schema_version: 2026-02-16
  • event_type: openai.request
  • provider: openai
  • endpoint: chat.completions.create or responses.create
  • status: success or failure
  • latency_ms
  • model
  • usage: prompt_tokens, completion_tokens, total_tokens
  • tags: feature, tenant_id, customer_id, plan, environment, template_id
  • error on failure events

Privacy

By default, prompt/response content is not sent.

If capture_content=True, content is hashed (SHA-256) before ingestion. Raw content is never sent by this SDK.

Disable Tracking

You can disable tracking by either:

  1. Using the original OpenAI client directly (do not wrap it), or
  2. Unsetting TOKVERA_INGEST_URL so no events are emitted.

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.1.0.tar.gz (6.9 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.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tokvera-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bafd8ec0954044e64677e6322bd75b81183d077a884683a65aee756bd194145e
MD5 714ee4b279d371c6394d903be630357e
BLAKE2b-256 794d87f8fa4147903dc912baebcb249d5832c7b4d9823ee667aaff776606b249

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokvera-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60a654451d8c50120b00ba6b41c2f4bf97dbf167136223b832bbf2ed98b9f05d
MD5 6497ba7eb1cebc0855c18a2d882abd9e
BLAKE2b-256 5d1a141c2aec3e581e8edc6d4747f7b905a269b881f16168663fd796a4fd0e12

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