Agent Quickstart
Connect an agent to Metrx with the SDK or OpenTelemetry you already run.
Metrx records what each task cost and how it turned out, then grades the agent against the contract you set.
Sign up
Create a free account and an API key in Settings → Security. Put it in METRX_API_KEY.
Instrument
Add the Python or TypeScript SDK, or point your OpenTelemetry exporter at Metrx.
Report outcomes
Wrap each unit of work in a task and record whether it succeeded.
Choose your integration
Connect your agent
PPython SDK
instrument() patches the OpenAI and Anthropic clients; task() groups a unit of work's calls and records its outcome.
pip install "metrxbot[openai]>=0.4.0"
export METRX_API_KEY=sk_live_... # Settings -> Security -> API Keysimport os
from metrx import Metrx
from openai import OpenAI
m = Metrx(api_key=os.environ["METRX_API_KEY"], agent_key="refund-triage")
m.instrument() # patches OpenAI/Anthropic CLASSES: clients you create before or after are tracked
client = OpenAI()
with m.task(task_id="ticket-4821") as t: # any string id; non-UUID ids map to a deterministic UUIDv5 client-side
reply = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Summarise ticket 4821"}],
)
t.set_outcome(success=True)
# short scripts flush at exit automatically; on serverless call m.flush()TTypeScript SDK
The OpenTelemetry OpenAI instrumentation creates the spans; the Metrx exporter sends them. Supports openai versions below 7, compiled to CommonJS.
npm install @metrxbot/sdk@0.7.0 @opentelemetry/api@1.9.1 @opentelemetry/sdk-trace-node@2.11.0 @opentelemetry/instrumentation@0.222.0 @opentelemetry/instrumentation-openai@0.20.0 openai@6.49.0// metrx.ts: import this first, before anything imports "openai".
// Compile to CommonJS (tsc "module": "commonjs"). openai 7.x is not instrumented yet.
import { NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { OpenAIInstrumentation } from '@opentelemetry/instrumentation-openai';
import { MetrxbotClient, MetrxbotSpanExporter, MetrxbotSpanProcessor } from '@metrxbot/sdk';
export const exporter = new MetrxbotSpanExporter({
apiKey: process.env.METRX_API_KEY!,
agentId: 'refund-triage',
});
const provider = new NodeTracerProvider({
spanProcessors: [new MetrxbotSpanProcessor(), new SimpleSpanProcessor(exporter)],
});
provider.register();
registerInstrumentations({ instrumentations: [new OpenAIInstrumentation()] });
export const metrx = new MetrxbotClient({ apiKey: process.env.METRX_API_KEY! });import { exporter, metrx } from './metrx';
import { task } from '@metrxbot/sdk';
import OpenAI from 'openai';
const client = new OpenAI();
export async function handleTicket() {
return task(metrx, async (t) => {
const reply = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Draft a reply to ticket 4821' }],
});
await exporter.forceFlush(); // send the span before the outcome
t.setOutcome({ success: true });
return reply;
});
}OOpenTelemetry
Send OTLP/HTTP traces to https://gateway.metrxbot.com/v1/traces. The receiver accepts JSON encoding only. Node needs only environment variables; the agent name comes from service.name.
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://gateway.metrxbot.com/v1/traces"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/json"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20${METRX_API_KEY}"
export OTEL_RESOURCE_ATTRIBUTES="service.name=refund-triage"
export OTEL_BSP_MAX_EXPORT_BATCH_SIZE="100"npm install @opentelemetry/api@1.9.1 @opentelemetry/auto-instrumentations-node@0.81.2 openai@6.49.0
node --require @opentelemetry/auto-instrumentations-node/register app.jsThe OpenAI instrumentation records spans for openai 4.19 to 6.x only. With openai 7 it records nothing and reports no error, so the install pins openai@6.49.0.
Python's OTLP exporter sends protobuf only, which Metrx does not accept yet. Use the Python SDK above, or run an OpenTelemetry Collector that re-encodes to JSON:
# otel-collector.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
send_batch_size: 100
send_batch_max_size: 100
exporters:
otlphttp/metrx:
traces_endpoint: https://gateway.metrxbot.com/v1/traces
encoding: json
compression: none
headers:
Authorization: "Bearer ${env:METRX_API_KEY}"
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlphttp/metrx]MMCP Server
Lets an MCP client such as Claude Desktop or Cursor work with your Metrx data. It does not instrument your agent; use an SDK or OpenTelemetry for that. The tool list is published at /.well-known/agent-card.json.
npx @metrxbot/mcp-server{
"mcpServers": {
"metrx": {
"command": "npx",
"args": ["-y", "@metrxbot/mcp-server"],
"env": { "METRX_API_KEY": "sk_live_..." }
}
}
}No account yet? The same public desk tools answer on the synthetic Northwind demo with no key, over stdio or as the Claude Code plugin:
npx @metrxbot/mcp-server --democlaude plugin marketplace add metrxbots/mcp-server && claude plugin install metrx-desk@metrxbotsThe plugin's skills, the hosted tool set and the error classes are on the manager's desk page.
What you get after connecting
Measured cost per agent
Tokens, model and cost for every LLM call, by agent and by task.
Task outcomes
Each task's success or failure, and reviewer corrections when you send them.
A contract
The acceptance criteria and model-spend budget you set for the agent.
A scorecard
The agent graded against its contract. Rates appear once 20 outcomes are in.
API & Documentation
All SDKs and servers use the same underlying API. Full documentation available:
- API Reference — Complete REST API documentation
- Full Documentation — Guides, examples, and best practices
Ready to connect your first agent?
Create an account, mint a key, and send your first task.
Get API key