Skip to main content

Ganivra Python SDK

Ganivra measures the cost and unit economics of AI executions without proxying model traffic or storing prompts and responses.

Install

python -m pip install ganivra

Ganivra requires Python 3.10 or newer and currently instruments synchronous OpenAI Responses API calls.

Initialize before creating the OpenAI client

import ganivra
from openai import OpenAI

ganivra.init(api_key="gv_live_your_workspace_key")
client = OpenAI()

response = client.responses.create(
    model="gpt-5",
    input="Explain our refund policy simply.",
)

Initialization automatically captures model, input/output/cached token counts, latency, status, error type, and environment. Ganivra creates execution and step IDs and exports the metadata on a bounded background queue.

Add business context for unit economics

with ganivra.trace(
    workflow="support_answer",
    feature="support_chatbot",
    customer_id="acme",
    prompt_id="support_answer",
    prompt_version="v1",
    revenue_usd=0.10,
):
    response = client.responses.create(
        model="gpt-5",
        input="Explain our refund policy simply.",
    )

Trace metadata is optional. It enables customer, feature, workflow, prompt, and margin reporting. Use pseudonymous identifiers where appropriate.

Configuration

ganivra.init(
    api_key="gv_live_your_workspace_key",
    endpoint="https://api.ganivra.com",
    environment="production",
    queue_size=1000,
    batch_size=20,
    timeout_seconds=2.0,
    max_retries=2,
)

For local Ganivra development, set endpoint="http://127.0.0.1:8000". Call ganivra.flush() in short-lived scripts when you want to wait briefly for queued telemetry.

Privacy and failure behavior

  • OpenAI requests continue going directly from your application to OpenAI.
  • Prompt and response bodies are never collected.
  • OpenAI API keys are never collected.
  • Telemetry failures never change the OpenAI result or exception your code sees.
  • A full queue or unavailable Ganivra endpoint drops telemetry instead of blocking the application.

Prefer the language-independent REST API when automatic Python instrumentation is not appropriate. The canonical API contract is documented at docs/API.md in the Ganivra project.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ganivra-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

ganivra-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ganivra-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ganivra-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a39febe0e51668f236eeb586b6a5b566d18e225fff785d23d45a8ecc5fa3c2e4
MD5 3d227e1850c0ba19529e03adb27d1a69
BLAKE2b-256 40dfa84274615b94774f2a5ac9709d8edb130492a0cf591c3246f82a0040b939

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ganivra-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ganivra-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0156a321940b0411aa37c1e1438e636a15b1720ea2923c009538870f64a05f0
MD5 34fefca5b90bf677bbd3c2c9c4ddd6e0
BLAKE2b-256 2eb09cb5451abce086117f1a5fc09301560ddff68e32bdd225a36e4f11d64f0e

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