Skip to main content

Annapurna metering hook — emit per-call LLM usage events for per-feature cost attribution.

Project description

annapurna-meter

The optional metering hook for Annapurna — a thin, fail-safe wrapper that reports per-call LLM usage so spend can be attributed per feature. Stdlib-only, no dependencies. Cost is computed server-side from Annapurna's pricing tables — the SDK never sees prices, and it never sends prompt or response content, only token counts and a feature_id.

It is fail-safe: reporting is fire-and-forget on a background thread and can never raise into your request path. With no ingest URL/token configured, every call is a no-op.

Install

pip install annapurna-meter

Use

Recommended — wrap the client once (no per-call code):

from annapurna_meter import wrap

client = wrap(anthropic_client, feature_id="feature-threat-triage")  # reads ENV

resp = client.messages.create(model="claude-sonnet-4-6", ...)   # metered automatically

Provider is auto-detected; each call is recorded with its latency. Pass an optional metadata={…} (e.g. environment, customer_id) for extra attribution. Streaming/async calls use the explicit form below.

Explicit — one line per call:

from annapurna_meter import Meter

meter = Meter(feature_id="feature-threat-triage")
resp = anthropic_client.messages.create(model="claude-sonnet-4-6", ...)
meter.record_anthropic(resp)   # <- the whole hook

Helpers: record_anthropic, record_openai, record_gemini, record_openai_compatible, or the generic record(provider=…, model=…, tokens_in=…, tokens_out=…, feature_id=…).

Optimize mode (opt-in)

Meter(..., optimize=True) additionally emits privacy-safe signals — salted hashes and counts, never prompt text — so Annapurna can surface measured optimization opportunities (duplicate calls, uncached repeated prefixes). Off by default; all work is off the call path, memory-bounded, and fail-safe. The SDK fetches a per-tenant salt once (GET /api/hook/salt, same ingest token).

Config

Env var What it is
ANNAPURNA_INGEST_URL e.g. https://app.example.com/api/hook/events
ANNAPURNA_INGEST_TOKEN the per-workspace ingest token from the dashboard

License

Apache-2.0. (The Annapurna server is AGPL-3.0; this client SDK is permissive so you can embed it in a proprietary app.)

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

annapurna_meter-0.3.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

annapurna_meter-0.3.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file annapurna_meter-0.3.0.tar.gz.

File metadata

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

File hashes

Hashes for annapurna_meter-0.3.0.tar.gz
Algorithm Hash digest
SHA256 52554d467719f4ea1c11b6a5799331d0df6c8bec5c81c8d5bab7eeaf966249fe
MD5 8a2224c821c8081dff846b149e339e51
BLAKE2b-256 30fc1d4c291f289670238af3a08601a6c6ef0136b876108754cbf5690821e60d

See more details on using hashes here.

Provenance

The following attestation bundles were made for annapurna_meter-0.3.0.tar.gz:

Publisher: release-sdk.yml on costlyinfra-admin/Annapurna

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

File details

Details for the file annapurna_meter-0.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for annapurna_meter-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a94cbe13177c5e25251d830e0bae2f219eb16a50fe7c63381647305f3cd55b73
MD5 7c6cb846864c01123d7000fff976e4a1
BLAKE2b-256 220fa967327e0cc71d25715b995893a9a92723f6e217fc463918dba0b92c0835

See more details on using hashes here.

Provenance

The following attestation bundles were made for annapurna_meter-0.3.0-py3-none-any.whl:

Publisher: release-sdk.yml on costlyinfra-admin/Annapurna

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