# MetricAI > Precision AI usage metering, LLM cost attribution, agent billing, budget enforcement, and BYOK AI gateway infrastructure. MetricAI sits in the request path between your application and AI providers. It meters usage in real time, attributes cost to customers and agents, enforces spend controls, and powers usage-based billing for AI SaaS - including OpenAI, Anthropic, Gemini, Deepgram, ElevenLabs, and LiveKit. ## Product pages - [Home - AI usage metering & billing](https://staging-app.metricai.live/): Meter AI calls, attribute LLM cost, enforce budgets, bill customers - [Use cases](https://staging-app.metricai.live/use-cases): AI SaaS billing, agent cost controls, voice AI billing, multi-provider attribution - [Integrations](https://staging-app.metricai.live/integrations): OpenAI, Anthropic, Gemini, voice, and agent framework metering - [Compare](https://staging-app.metricai.live/compare): MetricAI vs DIY metering, gateways, and observability tools - [Pricing](https://staging-app.metricai.live/pricing): Usage-based pricing for AI infrastructure - [Security](https://staging-app.metricai.live/security): BYOK key handling and data controls - [Documentation](https://staging-app.metricai.live/docs): SDK install, providers, streaming, budgets, API reference - [Contact](https://staging-app.metricai.live/contact): Talk to an AI billing architect ## Search intents we answer - AI usage metering - LLM cost attribution - AI agent billing - OpenAI / Anthropic / Gemini metering - Voice AI billing with Deepgram, ElevenLabs, LiveKit - BYOK AI gateway - AI spend controls and budget enforcement - Usage-based billing for AI SaaS ## Docs - [Overview](https://staging-app.metricai.live/docs#intro): 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. - [Quickstart](https://staging-app.metricai.live/docs#quickstart): The fastest path - init(..., auto_instrument=True) monkey-patches official provider SDKs so your existing OpenAI(), Anthropic(), etc. calls route through MetricAI automatically. MetricAI meters the full stream including first-token latency. - [Installation](https://staging-app.metricai.live/docs#install): Provider SDKs and framework adapters ship as extras. The base install already bundles common provider SDKs and framework integrations - for most setups pip install metricai is enough. - [Configuration](https://staging-app.metricai.live/docs#configuration): Call metricai.init(...) once at process startup. Retrieve the global client with metricai.get_metricai(). - [Auto-instrument](https://staging-app.metricai.live/docs#pattern-instrument): Auto-instrument patches constructors of openai.OpenAI, anthropic.Anthropic, google.genai.Client, groq.Groq, xai_sdk.Client, perplexity.Perplexity, LangChain chat models, Strands Agent / model.stream, Tavily, and voice SDKs. Idempotent - patches each provider once. - [Client factory](https://staging-app.metricai.live/docs#pattern-factory): Build a provider SDK client pointed at the proxy with attribution pre-set - no global patching. - [First 10 minutes](https://staging-app.metricai.live/docs#setup-guide): This mirrors the in-app Setup guide in the user menu. Six steps, and the dashboard ticks each one off as it detects it - there is nothing to mark complete by hand. - [Node.js SDK](https://staging-app.metricai.live/docs#node-sdk): The Node SDK returns real openai, @anthropic-ai/sdk and @google/genai clients pre-routed through the MetricAI proxy, so every API those SDKs expose is metered - not just chat. - [Home metrics](https://staging-app.metricai.live/docs#home-metrics): Home is the financial health of the selected workspace over the selected time range. Every card is derived from metered calls - nothing is estimated from sampling. Amounts are stored in USD and converted for display by the currency switcher; see Currency and FX. - [Outcomes](https://staging-app.metricai.live/docs#outcomes): An outcome is one unit of work your agent completed for a customer - a booking made, a ticket resolved, a report delivered. MetricAI models an outcome as a session: every call that shares a session_id is one outcome. Successful Outcomes and Cost per Outcome on Home, and the per-customer unit costs on Unit Economics, all count sessions. - [Runs](https://staging-app.metricai.live/docs#runs): A run is one session: every call sharing a session_id, rolled up with its turns, tokens and cost. Runs is the same data as the classic Sessions view, served by /v1/sessions. - [Trace Explorer](https://staging-app.metricai.live/docs#trace-explorer): Trace Explorer is the request-level log: one row per metered call, in time order, for the selected range. It is the same source as the classic Logs view (/transactions/logs), with latency context from /v1/analytics/latency and /v1/analytics/slow-requests. - [Agents & Workflows](https://staging-app.metricai.live/docs#agents-dashboard): Everything you tag with an agent_id becomes a row here: spend, runs and health per agent for the selected range. Backed by /v1/analytics/margin/by-agent, with known ids from /v1/routing/agents and caps from /v1/budgets. - [Models & Tools](https://staging-app.metricai.live/docs#models-tools): One page for every model, provider and tool your agents actually used: cost, reliability and token mix for the selected range. It replaces the old separate LLM, Models, Tools, Audio and Latency views. - [Voice and audio analytics](https://staging-app.metricai.live/docs#voice-analytics): Voice usage is metered per provider in its own units, then rolled into the Audio analytics cards on Home and the STT / TTS detail on Models & Tools. Providers covered: Deepgram, ElevenLabs and Sarvam. - [Spend & Forecast](https://staging-app.metricai.live/docs#spend-forecast): Spend & Forecast answers three questions for the selected range: what did we spend, where is the month going to land, and are we on pace against the budget. Actuals come from /transactions/logs, the projection from /v1/forecasting/forecast, the cap from /v1/budgets. - [Unit Economics](https://staging-app.metricai.live/docs#unit-economics): Unit Economics turns total spend into per-unit numbers: what one call costs, what one outcome costs, what you earn on each, and the margin that leaves. All four are for the selected range and the active workspace. - [Cost Allocation](https://staging-app.metricai.live/docs#cost-allocation): Cost Allocation splits the same window's spend across the dimensions that matter financially, each as a share of the total. It is the page to open when a number on Home moved and you need to know what moved it. - [Optimisation](https://staging-app.metricai.live/docs#optimisation): Optimisation reports savings MetricAI can measure: tokens served from prompt cache, and model-routing decisions that chose a cheaper model. It is a record of what was saved, not a list of generated advice. - [OpenAI](https://staging-app.metricai.live/docs#openai): Supports Chat Completions, the Responses API, web search tools, and streaming. Call import metricai and metricai.init(...) before creating the OpenAI client. - [Anthropic](https://staging-app.metricai.live/docs#anthropic): Claude Messages API with optional web search tools. Import metricai and init before Anthropic(). - [Gemini](https://staging-app.metricai.live/docs#gemini): Native google.genai.Client - generateContent, Interactions API (text, streaming, multi-turn, tools). - [Grok](https://staging-app.metricai.live/docs#grok): Grok uses xAI's gRPC SDK. By default routes through the MetricAI proxy. Set METRICAI_GROK_DIRECT=1 to call xAI gRPC directly. - [Groq](https://staging-app.metricai.live/docs#groq): OpenAI-compatible chat completions (no native web search). - [Mistral](https://staging-app.metricai.live/docs#mistral): Use LangChain ChatMistralAI with metricai.init(auto_instrument=True). - [Perplexity](https://staging-app.metricai.live/docs#perplexity): Sonar chat (built-in web search) and the Search API. - [Vertex AI](https://staging-app.metricai.live/docs#vertex): Vertex AI is separate from Gemini AI Studio. Pass service-account JSON plus GCP project and location via llm_keys, then use google.genai.Client. - [Azure Foundry](https://staging-app.metricai.live/docs#azure): Pass Azure credentials in llm_keys, then use the OpenAI SDK as usual. - [AWS Bedrock](https://staging-app.metricai.live/docs#bedrock): Route Bedrock through MetricAI with the OpenAI SDK (chat.completions), native boto3 Converse APIs, LangChain ChatBedrock / ChatBedrockConverse, or AWS Strands Agents (BedrockModel). Pass AWS credentials via llm_keys for BYOK. Strands can also use the boto3 default chain (~/.aws/credentials). - [vLLM (self-hosted)](https://staging-app.metricai.live/docs#vllm): vLLM runs on your own GPUs, so MetricAI never proxies it and has no published price for it. Usage is reported from your process with Tracker, and you set the price per model yourself under Settings then Model pricing with provider vLLM. - [LangChain & LangGraph](https://staging-app.metricai.live/docs#langchain): Call import metricai and metricai.init(auto_instrument=True) first. Native LangChain chat models are instrumented automatically. MetricAI meters llm.stream(...) the same as invoke. - [AWS Strands Agents](https://staging-app.metricai.live/docs#strands): Same metricai.init pattern as LangChain. MetricAI patches strands.Agent (__call__, invoke_async, stream_async, structured_output), Graph/Swarm, and every model.stream (including AnthropicModel and other subclasses) so calls go to POST /v1/proxy/strands. Dashboard rows are provider=strands with the underlying model price. - [CrewAI](https://staging-app.metricai.live/docs#crewai) - [LlamaIndex](https://staging-app.metricai.live/docs#llamaindex): Install metricai[llamaindex]. Use alongside metricai.init(auto_instrument=True) so the underlying provider client routes through the proxy. - [Tavily](https://staging-app.metricai.live/docs#tavily): Tavily is metered per call (tool provider, not tokens). Auto-wrapped when llm_keys includes tavily. Supports search, extract, crawl, map, qna_search, and research. - [Web middleware](https://staging-app.metricai.live/docs#web-middleware) - [AutoGen](https://staging-app.metricai.live/docs#autogen): There are two ways in. The simplest is to hand AutoGen a MetricAI-routed OpenAI client; the middleware is for when you need to wrap an existing OpenAIWrapper in place. - [Claude Code](https://staging-app.metricai.live/docs#claude-code): Meter your team's Claude Code usage in MetricAI: every model call, attributed to a session, a developer, an agent and the tools it ran. Works with the Claude Code CLI, the Claude desktop app's Code tab, the VS Code and JetBrains extensions, and the Agent SDK. - [Codex](https://staging-app.metricai.live/docs#codex): Meter your team's OpenAI Codex usage in MetricAI: every model call, attributed to a session, a developer and a surface. One config block covers the Codex CLI, the desktop app, and the IDE extension. - [Cursor](https://staging-app.metricai.live/docs#cursor): Meter your team's Cursor usage in MetricAI: every agent turn, attributed to a run, a developer, an agent and the tools it ran. Works with Cursor desktop, the CLI, cloud agents and Bugbot. Tested with Cursor 3.17.8. - [Hermes Agent](https://staging-app.metricai.live/docs#hermes): Point official Hermes Agent at MetricAI. No Hermes source edits. MetricAI meters the LLM call and forwards it to the vendor. Local Hermes tools (files, terminal, browser) stay ₹0 — only model calls bill. - [Kiro](https://staging-app.metricai.live/docs#kiro): Track Kiro IDE and CLI usage in MetricAI. Use agent hooks on any plan. Enterprise admins can also push daily credit rollups. - [Windsurf](https://staging-app.metricai.live/docs#windsurf): Track Windsurf Cascade (also called Devin Desktop) in MetricAI. Hooks work on any plan. Enterprise adds credit spend via the Analytics API. - [GitHub Copilot](https://staging-app.metricai.live/docs#copilot): Track GitHub Copilot CLI and IDE agent usage in MetricAI. Hooks work on any plan. Org or Enterprise adds credit spend via Usage Metrics. Enterprise OpenTelemetry adds per-call tokens. - [Voice](https://staging-app.metricai.live/docs#voice): Deepgram, ElevenLabs, and Sarvam voice SDKs via client factories. Also auto-instrumented when keys are in llm_keys. For realtime agent sessions (e.g. LiveKit), attribute STT/LLM/TTS under one MetricAISession - see Sessions. - [LiveKit](https://staging-app.metricai.live/docs#livekit): The LiveKit integration wraps a LiveKit Agents AgentSession so the LLM, STT and TTS of one realtime call are attributed together - one agent, one user, one session - with per-turn aggregates. - [Sessions and telemetry](https://staging-app.metricai.live/docs#sessions): Group multi-agent, multi-provider workflows under one session_id. Pass a distinct agent_id per sub-agent so the dashboard breaks down cost by agent. Pass user_id for the end-user (your app's customer) and optional user_info for display in Invoices and Sessions. - [Create a project from the API](https://staging-app.metricai.live/docs#create-project-api): You can create a project and a project-scoped API key without the dashboard. Authenticate with a personal MetricAI API key from Settings → API keys (personal workspace). Project-scoped keys are rejected. - [Billing policies and customer wallets](https://staging-app.metricai.live/docs#billing-policies-and-wallets): This guide is for you (X): the MetricAI account that sells AI to your own customers (Y). It is not the page you send to Y. Y only sees a hosted pay link when you start a plan or mint a top-up. - [Pricing rules API](https://staging-app.metricai.live/docs#billing-policies-api): Price what each end customer (Y) pays you (X). These rules are the same objects the dashboard Pricing page saves. You can create them with a project-scoped MetricAI API key — no UI required. How rules, wallets, and collection fit together: Billing policies and customer wallets. - [End-user subscriptions API](https://staging-app.metricai.live/docs#end-user-subscriptions-api): Collect a monthly Subscription + overage fee from one Y, credit their prepaid wallet after they pay, and invoice leftover usage at overageMarkup. Uses the same hosted pay page as invoices (Route or BYOR). Dashboard: Customer wallets. Concept walkthrough: Billing policies and customer wallets. - [Invoice REST API](https://staging-app.metricai.live/docs#invoice-api): Fetch end-customer usage invoices and mint hosted payment links over HTTPS. These routes live on the API host (https://api.metricai.co.in), not the LLM proxy. The Python SDK methods get_invoices, create_invoice_payment_link, get_invoice_payment_status, and mark_invoice_collected call the same endpoints. For a monthly plan plus wallet, start from Billing policies and customer wallets, then Pricing rules API and End-user subscriptions API — instead of (or in addition to) a usage payment link. - [Invoice payments: Route](https://staging-app.metricai.live/docs#invoice-payments-route): Recommended default. MetricAI hosts checkout, splits each payment, and transfers your share to the bank you connected in the dashboard. You do not give MetricAI Razorpay API keys. - [Invoice payments: BYOR hosted](https://staging-app.metricai.live/docs#invoice-payments-byor): You collect on your own Razorpay account. MetricAI still hosts pay.metricai.co.in and creates the Razorpay order with the keys you stored in the dashboard (encrypted at rest). After the customer pays, a platform fee accrues for you to settle. - [Invoice payments: BYOR self-collect](https://staging-app.metricai.live/docs#invoice-payments-self-collect): You render the invoice and run Razorpay Checkout on your own site with keys in your .env. MetricAI never sees the customer's card. After a successful payment you report it so platform fees can accrue. - [Customers](https://staging-app.metricai.live/docs#customers-page): Customers is your end customers - the people your agents serve, billed as Y in the MetricAI model. One row per end_user_id with cost, revenue and margin for the selected range, from /v1/analytics/margin/by-end-user. - [Pricing rules in the dashboard](https://staging-app.metricai.live/docs#pricing-dashboard): Pricing is where you set what your customers pay you - distinct from Model pricing, which is what providers charge you. Rules are stored per workspace and versioned; changing a rule bumps its version rather than rewriting history. - [Invoices in the dashboard](https://staging-app.metricai.live/docs#invoices-dashboard): Invoices is one invoice per end customer per period: all of that customer's sessions in the period, rolled up with cost, markup and final amount. Backed by /v1/invoices/period. - [Platform fees](https://staging-app.metricai.live/docs#platform-fees): A platform fee is MetricAI's cut of money you collect from your end customers. It exists only in BYOR settlement, where the payment never passes through MetricAI, so the cut has to be accrued and settled separately. In Route settlement there is no platform fee page to pay - the cut is withheld at payment time. - [Settlement and payments](https://staging-app.metricai.live/docs#settlement-payments): Settlement is how money your end customers pay reaches your bank account. You pick a mode once per workspace; everything else - pay links, fees, webhooks - follows from it. - [Payouts onboarding](https://staging-app.metricai.live/docs#payouts-onboarding): Route settlement needs a payout account: a Razorpay linked account in your name that MetricAI transfers your share to. Settings / Payouts is the form that creates it. One payout account per project - a project's collections settle to that project's account. - [Budgets and policies](https://staging-app.metricai.live/docs#budgets-dashboard): Two different controls live on this page. Budget caps track and cap spend per customer. Policies are rules evaluated on every proxy request - allowlists, thresholds, classifications. Caps are about money; policies are about what is permitted. - [Alerts](https://staging-app.metricai.live/docs#alerts): Alerts has two halves: rules you define, and alerts that have fired. MetricAI also raises forecast and anomaly alerts on its own, which appear in the same list without a rule behind them. - [Notifications](https://staging-app.metricai.live/docs#notifications): The bell in the top bar is in-app notifications for things that need a decision or a response from you, read from GET /user/notifications. The badge counts undismissed items. - [GPU Bridge](https://staging-app.metricai.live/docs#gpu-bridge): The MetricAI Bridge is a small agent you install on your own GPU machines. It reads real GPU telemetry from the vendor driver and reports it to MetricAI per GPU, per process and per user, so GPU time becomes something you can see, allocate and charge for alongside your LLM spend. - [GPU dashboard](https://staging-app.metricai.live/docs#gpu-dashboard): GPU Infrastructure is its own dashboard with its own hours, rate cards, wallets and invoice series. It shows what the Bridge agent reports from your nodes - per GPU, per job and per user - over the time range selected at the top. - [GPU metering and billing](https://staging-app.metricai.live/docs#gpu-metering): Once the Bridge is reporting, GPU hours can be priced: internal chargeback, a departmental budget, or real invoices. Everything lives under /v1/gpu/billing and takes your API key as a bearer token. - [Workspaces and projects](https://staging-app.metricai.live/docs#workspaces): The switcher in the top bar - the one that reads Personal by default - changes which workspace the whole dashboard describes. Every page, every number and most settings are scoped to it. - [Roles and permissions](https://staging-app.metricai.live/docs#roles): Roles exist inside a project. A personal workspace has no roles - you are the only user. Set a role when you invite someone, and change it later with PATCH /v1/projects/{id}/members/{user_id}/role. - [Profile and account](https://staging-app.metricai.live/docs#profile-account): Settings / Profile is the small set of things that belong to you rather than to a workspace: your display name, your password, and deleting the account. - [Data and privacy](https://staging-app.metricai.live/docs#data-privacy): MetricAI meters calls; it does not need their content to do it. Prompt and response text is off by default and is only stored if you deliberately turn it on. - [API keys](https://staging-app.metricai.live/docs#api-keys): A MetricAI API key authenticates the SDK and the proxy, and decides which workspace usage bills to. It is the METRICAI_API_KEY in every quickstart. - [Billing markup](https://staging-app.metricai.live/docs#billing-markup): Markup is the percentage you add to provider cost when you invoice your customers. It is the difference between what AI costs you and what your customers pay. - [Model pricing](https://staging-app.metricai.live/docs#model-pricing): Model pricing is the price book: the provider cost rates your workspace is metered against. It is what AI costs you, not what your customers pay - markup is added on invoices, not on these rates. - [Plan, quotas and limits](https://staging-app.metricai.live/docs#plans): MetricAI has three plans. The plan sets your included request quota, how long analytics stay readable, how many projects you can create, and which features are unlocked. - [Webhooks](https://staging-app.metricai.live/docs#webhooks): Register one HTTPS endpoint and MetricAI POSTs billing events to it - principally invoice.paid, when one of your end customers pays. It is how you learn about a payment without polling. - [Currency and FX](https://staging-app.metricai.live/docs#currency): Costs are metered and stored in USD. The currency switcher in the top bar is a display conversion - it changes what you read, never what was charged. - [MetricAI Assistant](https://staging-app.metricai.live/docs#assistant): The Assistant is the in-app copilot. Ask it about your own spend, agents, customers, alerts or budgets, or about how MetricAI works, and it answers by reading your dashboard data and the product docs - then offers a one-click link to the page that proves it. - [Idempotency keys](https://staging-app.metricai.live/docs#idempotency): Every billable event can carry an idempotency key, so a retry after a timeout cannot charge twice or log the same call twice. The SDK sends one automatically; you only need to think about it when you retry by hand or build your own HTTP client. - [Ledger and reconciliation](https://staging-app.metricai.live/docs#ledger): Metering is append-only. Every billable call writes one event, keyed so a retry cannot write it twice, and nothing downstream edits it. Invoices, analytics and margin are all projections of that event stream, which is what makes the numbers reconcilable. - [Usage export](https://staging-app.metricai.live/docs#usage-export): Export your metered usage as CSV or JSON for your own billing system, warehouse or spreadsheet. One row per billing event, returned inline - there is no async job to poll. - [Wallet and usage](https://staging-app.metricai.live/docs#wallet): Two wallets. get_balance() is yours (X) — plan quota and MetricAI spend. Customer wallets are per end user (Y) in a project and never mix with yours. Concept guide: Billing policies and customer wallets. - [Proxy reference](https://staging-app.metricai.live/docs#proxy-reference): Default host: https://proxy.metricai.co.in. Override with METRICAI_PROXY_URL. - [Error handling](https://staging-app.metricai.live/docs#errors): Every status code, cause and fix: Error codes. - [Error codes](https://staging-app.metricai.live/docs#error-codes): Every error MetricAI returns, what causes it and what to do. Errors carry a plain detail string, or an object with an error code when the code matters to your handling. - [API cheat sheet](https://staging-app.metricai.live/docs#api-reference) ## Full text - [llms-full.txt](https://staging-app.metricai.live/llms-full.txt)