Skip to main content

LLM token observability SDK — wraps OpenAI and Anthropic clients to capture metadata

Project description

tokensor

LLM token observability for Python. Wraps your OpenAI or Anthropic client to capture call metadata (model, tokens, cost) and forward it to your Tokensor dashboard — one line of code, zero latency overhead.

Install

pip install tokensor
# With OpenAI support:
pip install "tokensor[openai]"
# With Anthropic support:
pip install "tokensor[anthropic]"

Quickstart

Get your API key from app.tokensor.com → Settings → API Keys.

OpenAI:

import os
import openai
import tokensor

client = tokensor.wrap(
    openai.OpenAI(),
    api_key=os.environ["TOKENSOR_API_KEY"],
)

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

Anthropic:

import os
import anthropic
import tokensor

client = tokensor.wrap(
    anthropic.Anthropic(),
    api_key=os.environ["TOKENSOR_API_KEY"],
)

message = client.messages.create(
    model="claude-3-5-haiku-latest",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

Environment variables

Variable Required Description
TOKENSOR_API_KEY yes Your Tokensor API key
TOKENSOR_HOST no Override API host (default: https://api.tokensor.com)

License

MIT

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

tokensor-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

tokensor-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tokensor-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tokensor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8df03e7785675fad703ac46b4478d9ea59c202bc57da99447cd30f4cd0eccb62
MD5 b190a930bfd29bcf770c68ff8ee01a08
BLAKE2b-256 bbc6f8890b67c68eae77de3ac2d11fa3bd3b5ce14a3da8dea17044b691cc5804

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokensor-0.1.0.tar.gz:

Publisher: publish-sdk.yml on motiisr/tokensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: tokensor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tokensor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e70c571f9ad462ada460355300140715ad50ab55b9217a10fc82b2a9198e2cd
MD5 0dad0beecb24cdb76c7a0219608aa23e
BLAKE2b-256 9da9570b82ed93d3570ee09bc565e5951116613cc7c46dacd84de476e505169f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokensor-0.1.0-py3-none-any.whl:

Publisher: publish-sdk.yml on motiisr/tokensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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