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
| 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. |
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 | Streaming chat, Responses, web search |
Anthropic | Streaming Messages + web search |
Gemini | Streaming Interactions + generateContent |
Grok | Streaming xAI gRPC SDK |
Groq | Streaming LPU chat completions |
Perplexity | Streaming Sonar + Search API |
Vertex AI | Streaming google-genai with GCP SA |
Azure OpenAI / Foundry | Streaming OpenAI SDK + azure llm_keys |
Mistral | Streaming LangChain ChatMistralAI |
Bedrock | converse_stream + invoke_model |
Tavily | search, extract, crawl, map, qna, research |
Voice | Deepgram, ElevenLabs, Sarvam |
LangChain / LangGraph | Native chat models + stream() |
MetricAI SDK · PythonView on PyPI
