Overview
    Python SDK v0.5.8Integration guide

    Billing, metering, and observability for LLM, voice, and tool calls through the MetricAI proxy.

    MetricAI SDK

    Financial rails for your AI agents

    Route your LLM, voice, and tool calls through the MetricAI proxy. Meter token/usage/outcome cost in INR and emit telemetry — without changing your provider code.

    PyPI
    pip install metricai
    BYOK
    bring your own keys
    fail-open
    telemetry never blocks agents
    INR
    wallet-native billing

    Copy-paste quickstart

    Install: Installation. Full walkthrough: Quickstart.

    Python
    import os
    import metricai
    from openai import OpenAI
    from dotenv import load_dotenv
    
    load_dotenv()
    
    metricai.init(
        api_key=os.getenv("METRICAI_API_KEY"),
        auto_instrument=True,
        default_agent_id="weather-bot",
        default_user_id="user_123",
        llm_keys={"openai": os.getenv("OPENAI_API_KEY")},
    )
    
    client = OpenAI()
    resp = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "What is the current weather in Tokyo?"}],
    )
    print(resp.choices[0].message.content)

    Core concepts

    ConceptWhat it is
    Proxy routingCalls go to …/v1/proxy/{provider} for server-side metering.
    BYOKYou keep provider keys; MetricAI forwards via X-*-API-Key headers. Default (mode="byok").
    ManagedMetricAI-managed provider keys; opt in via mode="managed".
    Attributionagent_id, user_id, session_id, workflow ids for cost breakdowns.
    Telemetry / track()Events POST to /v1/sdk/events. Fail-open by default.
    Outcome billingCharge per business outcome (e.g. booking confirmed) alongside tokens.
    SessionsGroup turns under one session_id with aggregates and budget caps.
    Fail-open guarantee: telemetry and metering errors are logged and never raise unless raise_on_error=True.

    Supported providers