Skip to main content

Anthropic API wrapper with per-call token usage logging and ₹-cost intelligence. Drop-in replacement for client.messages.create().

Project description

botzy-tokenizer

Per-call token usage logging and ₹-cost intelligence for the Anthropic API.

The moat is observed per-key data — not a counter, but a full audit trail: which source called which model, how many tokens were spent, what those tokens cost in ₹, and exactly how much you saved (or left on the table) through prompt caching.

BOTZIFY™ / botzy_tokenizer™ — trademark of Tanya Bansal (BOTZIFY). Source-available under the PolyForm Noncommercial License 1.0.0.


Install

pip install botzy-tokenizer

Requires Python ≥ 3.9.


Quickstart

Replace client.messages.create(...) with botzy_tokenizer.create(...):

from botzy_tokenizer import create

response = create(
    model="claude-haiku-4-5-20251001",
    max_tokens=256,
    source="mymod:my_function",   # optional — tags the usage row
    messages=[{"role": "user", "content": "Hello, Claude!"}],
)
print(response.content[0].text)

Async:

from botzy_tokenizer import async_create

response = await async_create(
    model="claude-sonnet-4-5-20251001",
    max_tokens=512,
    messages=[{"role": "user", "content": "Summarise this for me..."}],
)

Every successful call writes one row to a local SQLite database. Usage logging is best-effort — it never raises into your code.


Configuration

Environment variables (recommended)

Variable Purpose Default
BOTZY_TOKENIZER_HOME Home directory ~/.botzy_tokenizer/
BOTZY_TOKENIZER_DB Path to usage.db $HOME/usage.db
BOTZY_TOKENIZER_RATES Path to usage_rates.yaml $HOME/usage_rates.yaml
BOTZY_TOKENIZER_LOCKFILE Path to model_locks.json (opt-in) (disabled)

Programmatic override (call before the first create())

from botzy_tokenizer import configure

configure(
    db="/data/my_project/usage.db",
    rates="/etc/myapp/rates.yaml",
    lock_file="/etc/myapp/model_locks.json",  # omit to disable lock enforcement
)

Rates file

On first use, ~/.botzy_tokenizer/usage_rates.yaml is auto-seeded from the bundled defaults (Anthropic published pricing as of 2026-05). Edit that file to update the USD→INR rate or model prices without touching code (R13).


Model-lock gate (opt-in)

Lock enforcement is disabled by default — every model is allowed. To enable it, set BOTZY_TOKENIZER_LOCKFILE (or call configure(lock_file=...)) to a JSON file:

{
  "haiku":  {"locked": false, "calls_since_unlock": 42},
  "sonnet": {"locked": true,  "calls_since_unlock": 0},
  "opus":   {"locked": true,  "calls_since_unlock": 0}
}

When the file exists and a family is locked, create() raises ValueError before making any API call.


Cost-report CLI

# Initialise home dir, db, and rates file
botzy-tokenizer init

# Show last 24 hours (default)
botzy-tokenizer report

# Show last hour / week / 30 days
botzy-tokenizer report 1h
botzy-tokenizer report 1w
botzy-tokenizer report 1m

Report sections:

  1. PER-MODEL — calls, in/out tokens, cache r/w tokens, ₹ cost
  2. SAVED BY CACHE — ₹ actually saved through cache reads and % of full cost
  3. MISSED SAVINGS — ₹ left on the table by source (uncached vs eligible-but-missed)
  4. TOTAL — window cost + per-date breakdown for windows ≥ 1 day

Use BOTZY_TOKENIZER_HOME=/tmp/test botzy-tokenizer report to point at a non-default database.


License

PolyForm Noncommercial License 1.0.0 — see LICENSE. Commercial use requires a separate agreement with BOTZIFY.

BOTZIFY™ and botzy_tokenizer™ are trademarks of Tanya Bansal (BOTZIFY). Trademark rights are not licensed under the PolyForm Noncommercial License.

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

botzy_tokenizer-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

botzy_tokenizer-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for botzy_tokenizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1ddee67a23fa05d85010e5b2afeaca91e2b5e18aa922dab417ddd9ad7d68f2b5
MD5 8bef0015e46806e963b40be3b3d14711
BLAKE2b-256 adb276f7c96555259950b13c1c8aefe8c6454692d67aca5670e3da2dedc47ae0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for botzy_tokenizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2384514007aafac9cb9f49166d39143d915b7f3bc375acef36dd73e125b2513
MD5 c18f7503ab7e25678f083a224576cb94
BLAKE2b-256 79d7e29cdb413d0a07b9deb47707489a4dfd4d7dc404d32c37ad94d7aca30745

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