Skip to main content

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",   # optional - auto-detected from ENVIRONMENT / APP_ENV /
                                # FLASK_ENV / DJANGO_ENV, falling back to "unknown".
                                # Set this only to override.
    ingest_base_url="https://tokensbill.aiappsjunction.com",  # override the endpoint
)

License

MIT

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.6.0.tar.gz (22.9 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.6.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tokensbill-0.6.0.tar.gz
Algorithm Hash digest
SHA256 af1c26f68cb94543c38759d7af1c7c35d4d86b79f27e47c49edd93af5f35592e
MD5 5c9989e71388131ca35afab6d206b177
BLAKE2b-256 82a80fdae85948ae703bd05db402a5bb71f1da5af7565f94765b5f05a3d1dd22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokensbill-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0045da71e7eae4eeda59c10f2e87b54ca3d01a7d40bb735997192351bd62ec9d
MD5 314f290fa1fc3fd0b1e13b3332d48945
BLAKE2b-256 8b12d7ba8d99f91b91fff6c1a126ba130f0541552e07960e91adc330e326588a

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 Sentry Error logging StatusPage Status page