Agentrics

SDKs

JavaScript SDK

The Agentrics JavaScript SDK wraps your OpenAI and Anthropic clients to automatically track every API call. Works in Node.js and any runtime with the Fetch API. Full TypeScript support included.

Installation

npm install @agentrics/sdk

new Agentrics({ apiKey })

Create a single Agentrics instance at startup and use it to wrap all your AI clients.

import { Agentrics } from "@agentrics/sdk";

const agentrics = new Agentrics({
  apiKey: process.env.AGENTRICS_API_KEY!,
});
OptionTypeDescription
apiKeyrequiredstringYour Agentrics API key. Generate one from Settings → API Keys.
Base URL override: Set the AGENTRICS_BASE_URL environment variable to point at a different server (e.g. http://localhost:3000 during local development). By default the SDK posts to https://www.agentrics.io.

wrapAnthropic(client, agentId, agentName?)

Wraps an Anthropic client instance. Returns a Proxy with the same interface — use it identically to the original.

import Anthropic from "@anthropic-ai/sdk";
import { Agentrics } from "@agentrics/sdk";

const agentrics = new Agentrics({ apiKey: process.env.AGENTRICS_API_KEY! });

const client = agentrics.wrapAnthropic(
  new Anthropic(),
  "support-classifier",
  "Support Classifier",  // optional display name
);

const response = await client.messages.create({
  model: "claude-3-5-sonnet-20241022",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.content);
ParameterTypeDescription
clientrequiredAnthropicAn new Anthropic() instance.
agentIdrequiredstringStable identifier for this agent, e.g. "summarizer".
agentNamestringHuman-readable display name. Defaults to agentId.

wrapOpenAI(client, agentId, agentName?)

Wraps an OpenAI client instance. Intercepts all chat.completions.create() calls.

import OpenAI from "openai";
import { Agentrics } from "@agentrics/sdk";

const agentrics = new Agentrics({ apiKey: process.env.AGENTRICS_API_KEY! });

const client = agentrics.wrapOpenAI(new OpenAI(), "research-agent");

const response = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Summarize this document..." }],
});
console.log(response.choices[0].message.content);
ParameterTypeDescription
clientrequiredOpenAIA new OpenAI() instance.
agentIdrequiredstringStable identifier for this agent, e.g. "researcher".
agentNamestringHuman-readable display name. Defaults to agentId.

TypeScript

The SDK ships with full TypeScript types. The wrapped clients are typed as the original client type (T extends OpenAILike / T extends AnthropicLike), so autocomplete and type-checking work without any changes.

import { Agentrics, AgentricsOptions } from "@agentrics/sdk";

const options: AgentricsOptions = {
  apiKey: process.env.AGENTRICS_API_KEY!,
};

const agentrics = new Agentrics(options);

Error handling

Tracking calls are fire-and-forget using fetch(...).catch(() => {} ) — a network failure never blocks or throws in your application. If the underlying AI API raises, the SDK records the failure before re-throwing.