Agent Quickstart

Connect your agent to Metrx in 60 seconds

Get real-time cost tracking, optimization recommendations, and business outcome attribution.

1

Sign up

Create a free Metrx account. Get your API key in 30 seconds.

2

Install SDK

Add Metrx to your agent via MCP, Python, TypeScript, or REST API.

3

Track & Measure

See costs, ROI, and optimization opportunities in your dashboard.

Choose your integration

3 ways to integrate

MMCP Server — Best for Claude & Compatible Agents

Use Metrx as an MCP server. 23 tools for cost optimization, budgets, experiments, leak detection, and attribution.

npx @metrxbot/mcp-server

Or add to your Claude Desktop config:

{
  "mcpServers": {
    "metrx": {
      "command": "npx",
      "args": ["@metrxbot/mcp-server"],
      "env": {
        "METRX_API_KEY": "your-api-key-here"
      }
    }
  }
}

View MCP Server on npm

PPython SDK — Best for Python Agents

Auto-instrument your LLM calls. Metrx patches OpenAI and Anthropic clients to track every token and dollar automatically.

pip install metrx

Initialize in your code:

from metrx import Metrx

client = Metrx(api_key="your-api-key")

# Auto-instrument OpenAI, Anthropic, etc.
instrumented = client.instrument()
# Returns: ['openai', 'anthropic'] — all detected providers

# Your existing code works unchanged — costs are tracked automatically
from openai import OpenAI
openai = OpenAI()
response = openai.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}]
)
# ^ This call is now tracked by Metrx

# Log business outcomes to measure ROI
client.log_outcome(
    outcome_type="deal_closed",
    value_cents=10000
)

View on PyPI

TTypeScript SDK — Best for Node & Browser Agents

Route LLM calls through the Metrx gateway. Drop-in replacement for OpenAI and Anthropic clients with automatic cost tracking.

npm install @metrx/sdk

Initialize in your code:

import { MetrxbotClient } from '@metrx/sdk';

const client = new MetrxbotClient({
  apiKey: 'your-api-key',
  defaultAgentId: 'my-support-agent'
});

// OpenAI-compatible chat — costs tracked automatically
const response = await client.chat({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello' }]
});

// Anthropic-compatible messages
const anthropicResponse = await client.messages({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello' }]
});

// Access cost metadata from response headers
console.log(response._meta?.costMicrocents);
console.log(response._meta?.latencyMs);

View on npm

What you get after integrating

Real-time Cost Dashboard

See every call, token, and dollar spent by your agent. Breakdown by model, method, and time period.

Optimization Recommendations

Automatic suggestions to reduce costs: model switching, prompt optimization, caching strategies.

ROI Attribution

Link agent costs to business outcomes. See revenue per agent, cost per customer, and true ROI.

Budget Controls

Set hard or soft spending limits per agent. Get alerts when approaching budget or anomalies detected.

Model Experiments

Run A/B tests comparing models. Measure cost vs quality tradeoffs automatically.

Cost Leak Detection

Automatic detection of duplicate calls, token-heavy patterns, and unusual spending anomalies.

API & Documentation

All SDKs and servers use the same underlying API. Full documentation available:

Ready to measure your agent's ROI?

Set up takes 60 seconds. Start tracking today.

Get API key