Product SDKs
Choose the TypeScript SDK, Python SDK, or HTTP API for product-runtime cost attribution.
View sourceUse 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
| Integration | Best for | Usage extraction | Delivery |
|---|---|---|---|
| TypeScript and Node.js | Node.js services, Next.js, Express, streams, adapters, and active request guardrails | OpenAI and Anthropic response shapes | Configurable adapters, including batched cloud delivery |
| Python | Python services, scripts, OpenAI, Anthropic, LangChain, and LangGraph | OpenAI and Anthropic response shapes | Bounded background queue with batched cloud delivery |
| HTTP and cURL | Other runtimes or existing telemetry pipelines | Supplied by your application | Your 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 openaiimport 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
| Dimension | Purpose | Example |
|---|---|---|
tenantId | Paying customer or account | customer_42 |
userId | End user | user_123 |
feature | Product feature or request path | support-summary |
workflowId | Workflow definition | support |
runId | One workflow or agent execution | run_01J... |
stepId | Step within a run | retrieve-context |
agentId | Agent identity | support-agent |
toolName | Tool used by an agent | search-tickets |
retryCount | Retry attempt number | 1 |
outcome | Product or workflow result | resolved |
metadata | Additional 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.