Overview
MetricAI is financial rails for your AI agents. Route your LLM, voice, and tool calls through the MetricAI proxy. Meter token, usage, and 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 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()
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
| Concept | What it is |
|---|---|
Proxy routing | Calls go to …/v1/proxy/{provider} for server-side metering. |
BYOK | You keep provider keys; MetricAI forwards via X-*-API-Key headers. Default (mode="byok"). |
Managed | MetricAI-managed provider keys; opt in via mode="managed". |
Attribution | agent_id, user_id, session_id, workflow ids for cost breakdowns. |
Telemetry / track() | Events POST to /v1/sdk/events. Fail-open by default. |
Outcome billing | Charge per business outcome (e.g. booking confirmed) alongside tokens. |
Sessions | Group 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
| Provider | Support |
|---|---|
OpenAI | Chat, Responses, web search |
Anthropic | Claude + web search tools |
Gemini | Native genai, Interactions, TTS |
Grok | xAI gRPC SDK |
Groq | LPU chat completions |
Perplexity | Sonar, Search, Responses |
Bedrock | converse + invoke_model |
Tavily | per-call search metering |
Voice | Deepgram, ElevenLabs, Sarvam |
MetricAI SDK · PythonView on PyPI
