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
tsas RFC3339 string ordatetime(converted toZ). - Returns
{"status":"ok","http_status":201}on success; error responses includeerrorandhttp_statuswhen 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d495a18b2c421fbab798724a16298b84a3fd4a854f2543e71e553cb8e34aabd6
|
|
| MD5 |
2ee1c1f0300ad5b5281542b8c052bd1f
|
|
| BLAKE2b-256 |
8fa01ea5460540323dbd544e371e9c9053b47840d69dbfd20dac0e5d7a7a20bd
|
Provenance
The following attestation bundles were made for nivara-0.2.4.tar.gz:
Publisher:
publish.yml on nivara-tech/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nivara-0.2.4.tar.gz -
Subject digest:
d495a18b2c421fbab798724a16298b84a3fd4a854f2543e71e553cb8e34aabd6 - Sigstore transparency entry: 660902178
- Sigstore integration time:
-
Permalink:
nivara-tech/sdk@e9a2d4a79642fc43fea20503e402d1caa24bf2d9 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/nivara-tech
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e9a2d4a79642fc43fea20503e402d1caa24bf2d9 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50d208f1cce5fe9073baefc4aff6e0d94516c889eb5220f844c541d87ed6024e
|
|
| MD5 |
fe45e04798f640eb32b9b51098de4020
|
|
| BLAKE2b-256 |
1bc226196961a1f533747ed93eb7ecdba8cf62aef9a4a79098ac46f08ca04346
|
Provenance
The following attestation bundles were made for nivara-0.2.4-py3-none-any.whl:
Publisher:
publish.yml on nivara-tech/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nivara-0.2.4-py3-none-any.whl -
Subject digest:
50d208f1cce5fe9073baefc4aff6e0d94516c889eb5220f844c541d87ed6024e - Sigstore transparency entry: 660902179
- Sigstore integration time:
-
Permalink:
nivara-tech/sdk@e9a2d4a79642fc43fea20503e402d1caa24bf2d9 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/nivara-tech
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e9a2d4a79642fc43fea20503e402d1caa24bf2d9 -
Trigger Event:
push
-
Statement type: