Loading page

Overview

MetricAI is financial rails for your AI agents. Route your LLM, voice, and tool calls through the MetricAI proxy. Meter usage 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 with the Installation guide. Full walkthrough in 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()
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What is the current weather in Tokyo?"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

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.
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

ProviderSupport
OpenAIStreaming chat, Responses, web search
AnthropicStreaming Messages + web search
GeminiStreaming Interactions + generateContent
GrokStreaming xAI gRPC SDK
GroqStreaming LPU chat completions
PerplexityStreaming Sonar + Search API
Vertex AIStreaming google-genai with GCP SA
Azure OpenAI / FoundryStreaming OpenAI SDK + azure llm_keys
MistralStreaming LangChain ChatMistralAI
Bedrockconverse_stream + invoke_model
Tavilysearch, extract, crawl, map, qna, research
VoiceDeepgram, ElevenLabs, Sarvam
LangChain / LangGraphNative chat models + stream()
MetricAI SDK · PythonView on PyPI