@usagetap/observer
v0.1.4
Published
A tiny metadata-only UsageTap observer for AI usage and cost trials.
Maintainers
Readme
@usagetap/observer
A tiny, fail-open wrapper for UsageTap's 30-day usage and cost analysis trial. It sends only provider/model metadata, token counts, timing, status, and optional feature tags. It never sends prompts, model responses, or provider credentials.
import OpenAI from "openai";
import { observeOpenAI } from "@usagetap/observer";
const openai = observeOpenAI(new OpenAI(), {
feature: "support-assistant",
});
const response = await openai.chat.completions.create({
model: "gpt-4.1-mini",
messages,
});Anthropic uses the same options:
import Anthropic from "@anthropic-ai/sdk";
import { observeAnthropic } from "@usagetap/observer";
const anthropic = observeAnthropic(new Anthropic());Set USAGETAP_API_KEY as a server-side environment variable. Trial keys infer
their private workspace automatically. Full accounts can optionally pass a
customerId when one key reports usage for multiple end customers.
The observer supports OpenAI-compatible chat completions, Responses API calls, and Anthropic Messages calls. Streams pass through while the observer reads only metadata-bearing usage events; it never buffers or sends content chunks.
UsageTap network requests are kept off the provider response path. In ordinary long-running Node processes, queued metadata is delivered in the background. In short-lived jobs or serverless handlers, flush before the process exits:
await openai.flushUsageTap();Move to @usagetap/sdk when you deliberately need customer or user attribution,
limits, gateway routing, sampling, managed compression, alerts, or forecasts.
