Documentation menu
DocsProduct SDKs

Product SDKs

Choose the TypeScript SDK, Python SDK, or HTTP API for product-runtime cost attribution.

View source

Use a product integration when your application calls an LLM on behalf of a customer or end user. Every integration sends the same attribution dimensions to /api/v1/events, but installation, usage extraction, cost calculation, and delivery differ by runtime.

Choose an integration

IntegrationBest forUsage extractionDelivery
TypeScript and Node.jsNode.js services, Next.js, Express, streams, adapters, and active request guardrailsOpenAI and Anthropic response shapesConfigurable adapters, including batched cloud delivery
PythonPython services, scripts, OpenAI, Anthropic, LangChain, and LangGraphOpenAI and Anthropic response shapesBounded background queue with batched cloud delivery
HTTP and cURLOther runtimes or existing telemetry pipelinesSupplied by your applicationYour application owns delivery and retries

The TypeScript SDK requires Node.js 20.9 or newer. The Python SDK requires Python 3.9 or newer and has no required runtime dependencies.

Send a first event

TypeScript is selected by default. Choose the tab for your runtime.

npm install @traice/sdk openai
import OpenAI from "openai";
import { configure, flush, meter } from "@traice/sdk";

configure({
  adapters: ["cloud"],
  cloudApiKey: process.env.TRAICE_API_KEY,
});

const openai = new OpenAI();
const completion = await meter(
  () =>
    openai.chat.completions.create({
      model: "gpt-4o-mini",
      messages: [{ role: "user", content: "Summarize this ticket" }],
    }),
  {
    feature: "support-summary",
    userId: "user_123",
    tenantId: "customer_42",
    workflowId: "support",
  },
);

await flush();

Shared attribution fields

DimensionPurposeExample
tenantIdPaying customer or accountcustomer_42
userIdEnd useruser_123
featureProduct feature or request pathsupport-summary
workflowIdWorkflow definitionsupport
runIdOne workflow or agent executionrun_01J...
stepIdStep within a runretrieve-context
agentIdAgent identitysupport-agent
toolNameTool used by an agentsearch-tickets
retryCountRetry attempt number1
outcomeProduct or workflow resultresolved
metadataAdditional structured context{ "plan": "pro" }

Pass tenantId on every customer-facing event. Missing customer attribution prevents customer-level margin analysis.

Cost and delivery behavior

The TypeScript and Python SDKs extract token usage from supported provider responses and calculate known-model cost locally. Unknown models keep their token counts and use zero cost until you configure local pricing.

Both SDKs are designed to keep collection failures out of the provider-call result. Explicitly flush short-lived scripts, jobs, and serverless handlers before the process exits. The HTTP integration leaves extraction, pricing, batching, retries, and shutdown behavior to your application.

Continue with one language