Skip to main content

One line. Every AI token tracked. Captures Anthropic/OpenAI/Gemini token usage from outgoing httpx/requests calls and streams it to TokensBill. Silent-fail by design.

Project description

tokensbill

One line. Every AI token tracked. Automatically captures Anthropic / OpenAI / Gemini token usage from your app's outgoing AI calls and streams it to your TokensBill dashboard — so you can see exactly where your AI spend goes.

Install

pip install tokensbill

Use — one line at startup

import tokensbill; tokensbill.init("tl_live_your_project_key")

Put it at the top of your entry file (e.g. main.py), before your app starts. That's it — every AI API call your app makes is now tracked automatically.

Get your project key from TokensBill → your project → Integration.

What it does

  • Patches httpx and requests (used by the Anthropic/OpenAI Python SDKs).
  • Reads token counts and cost from the AI provider's response without altering your call.
  • Sends the numbers to TokensBill in a background thread.
  • Silent-fail by design — it never raises into, blocks, or slows your application. If TokensBill is unreachable, your app is completely unaffected.

Is the key safe to commit?

The tracking key is a label, not a password. It cannot access your AI provider account, read your prompts, or spend money — it only lets your app report usage numbers to your dashboard. You can regenerate it any time from the dashboard.

Options

import tokensbill
tokensbill.init(
    "tl_live_...",
    environment="production",   # production | staging | development
    ingest_base_url="https://tokensbill.aiappsjunction.com",  # override the endpoint
)

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

tokensbill-0.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

tokensbill-0.2.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file tokensbill-0.2.0.tar.gz.

File metadata

  • Download URL: tokensbill-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tokensbill-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c31358c87ad80b8b7efd3bf574a8e04198d91dd4b9668268d606c4820392285
MD5 b32bd2f1fb78e8921572208b173a5cc5
BLAKE2b-256 4d7bd7ee73bd136073f2f22845bb197f5ae974bb272a5777fc1ad27a0925517d

See more details on using hashes here.

File details

Details for the file tokensbill-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tokensbill-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tokensbill-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b4e6b354cea8ee15e490350df40299a1e415d917113188cd6b73bbe12423541
MD5 27b08391771c640756aff5e73be14c90
BLAKE2b-256 cf2b9275347b376a3b18b9cc6c8ad1da1b5541705761316e73c7c19cf58cfb95

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