Skip to main content
Use this guide to connect a TypeScript or Python agent runtime to AgentMeter.

1. Install the SDK

pnpm add @agentmeter/sdk
pip install agentmeter-ai
The Python package installs from agentmeter-ai, but the runtime import is agentmeter.

2. Create a telemetry API key

Sign in to the AgentMeter dashboard and create a telemetry-scoped API key. Store the plaintext key as AGENTMETER_API_KEY in your runtime secret store. The key is shown once.

3. Initialize the SDK

TypeScript

import agentmeter from "@agentmeter/sdk";

agentmeter.init({
  apiKey: process.env.AGENTMETER_API_KEY!,
});

Python

import os
import agentmeter

agentmeter.init(api_key=os.environ["AGENTMETER_API_KEY"])
The default cloud endpoint is https://api.agentmeter.com. Self-hosted deployments can pass an endpoint override.

4. Attribute calls to a customer and step

TypeScript

import { track } from "@agentmeter/sdk";

await track(
  { customer_id: "acme-corp", step_name: "evaluate" },
  async () => {
    return openai.chat.completions.create({
      model: "gpt-4o-mini",
      messages,
    });
  },
);

Python

from agentmeter import track_context

with track_context(customer_id="acme-corp", step_name="evaluate"):
    response = openai_client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages,
    )

5. Check the dashboard

After events arrive, use the dashboard to review:
  • Total cost and cost by customer.
  • Expensive agent steps.
  • Unknown pricing tasks that need a pricing rule.
  • Rule events, warnings, and alerts.

Production checklist

  • Use opaque customer_id values.
  • Use stable step_name labels such as retrieve_context, evaluate, or summarize.
  • Do not send prompts, completions, emails, phone numbers, or raw messages in telemetry metadata.
  • Configure pricing for any non-LLM metrics before relying on margin reports.