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=…).

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.2.0.tar.gz (11.2 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.2.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: annapurna_meter-0.2.0.tar.gz
  • Upload date:
  • Size: 11.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 6cdadbfb6dd5c438b98c829de76dc1cc0fdcc90407389bfbf4ef07abb858fc66
MD5 5f601cb05be42d0e168ab669b61d6829
BLAKE2b-256 f67acb6bbf3a6272b22582d7b19e5d3b8dc32e464026b711a56335cef24a2241

See more details on using hashes here.

Provenance

The following attestation bundles were made for annapurna_meter-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: annapurna_meter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d0eceb2996b9c44c61b4a84922efe7a4d331d212fc251d00e7b0df7e08058bd
MD5 78727825a87c7ff5991a75855615c4bb
BLAKE2b-256 e5968fbd3b08e6f5ddc465598849a8f8ade64ba87881421dbbb51d91dd0df637

See more details on using hashes here.

Provenance

The following attestation bundles were made for annapurna_meter-0.2.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