Skip to main content

Minimal client to record LLM/AI usage metrics to the Nivara Metrics API

Project description

Nivara — Python Metrics Client

Lightweight client to record LLM/AI usage metrics to the Nivara Metrics API. Defaults to background delivery with safe timeouts and optional retries; also supports a simple synchronous call for one‑off usage.

Environment

export NIVARA_API_KEY="ak_live_..."              # required
export NIVARA_BASE_URL="https://api.getnivara.com"   # optional (default)

Quickstart

Install locally (editable) once:

python3 -m pip install -e .

Configure (optional; sensible defaults are used):

import nivara

nivara.configure(
  timeout=2.0,
  retries=2,
  mode="background",   # or "sync"
  queue_size=10000,
  debug=False,
)

Emit a metric (background):

import nivara

nivara.emit(
  metric="llm.request",
  user_identifier="end_user_42",
  input_tokens=512,
  output_tokens=238,
  cached_tokens=64,
  reasoning_tokens=0,
)

Notes

  • Sends only the supported fields; unknown values are omitted.
  • Accepts ts as RFC3339 string or datetime (converted to Z).
  • Returns {"status":"ok","http_status":201} on success; error responses include error and http_status when available.

Synchronous one‑shot record

from datetime import datetime, timezone
import nivara

nivara.record(
  metric="llm.request",
  ts=datetime.now(timezone.utc),   # optional; server uses now() if omitted
  input_tokens=100,
  output_tokens=20,
)

Helpers

  • nivara.from_openai(response, user_identifier=None) — map OpenAI usage to emit kwargs:
resp = client.responses.create(model="gpt-4o-mini", input="hi")
nivara.emit(metric="llm.request", **nivara.from_openai(resp))

Lifecycle

  • nivara.flush(timeout=5.0) — wait for the background queue to drain.
  • nivara.close() — stop the worker.
  • nivara.stats() — returns { queued, sent, failed, last_error }.

Example script

Run a minimal OpenAI demo and record usage:

export OPENAI_API_KEY=sk-...
export NIVARA_API_KEY=ak_live_...
python3 -m pip install -e .
python3 examples/openai_demo.py --prompt "hello there"

More docs

  • docs/index.md — entry point
  • docs/getting-started.md — installation and quickstart
  • docs/concepts.md — background vs sync, retries, sampling
  • docs/api.md — full API reference
  • docs/examples.md — copy/paste snippets
  • docs/faq.md — common issues

License

Proprietary to Nivara Tech (adjust as needed).

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

nivara-0.2.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

nivara-0.2.4-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file nivara-0.2.4.tar.gz.

File metadata

  • Download URL: nivara-0.2.4.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nivara-0.2.4.tar.gz
Algorithm Hash digest
SHA256 d495a18b2c421fbab798724a16298b84a3fd4a854f2543e71e553cb8e34aabd6
MD5 2ee1c1f0300ad5b5281542b8c052bd1f
BLAKE2b-256 8fa01ea5460540323dbd544e371e9c9053b47840d69dbfd20dac0e5d7a7a20bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for nivara-0.2.4.tar.gz:

Publisher: publish.yml on nivara-tech/sdk

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

File details

Details for the file nivara-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: nivara-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nivara-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 50d208f1cce5fe9073baefc4aff6e0d94516c889eb5220f844c541d87ed6024e
MD5 fe45e04798f640eb32b9b51098de4020
BLAKE2b-256 1bc226196961a1f533747ed93eb7ecdba8cf62aef9a4a79098ac46f08ca04346

See more details on using hashes here.

Provenance

The following attestation bundles were made for nivara-0.2.4-py3-none-any.whl:

Publisher: publish.yml on nivara-tech/sdk

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