Telemetry
DisabledCapabilities: Runtime evidence
OpenAI and Claude application usage
Node.js / TypeScript shared clients support direct non-streaming calls and streamed create calls. Python, Realtime and batch are outside this capability.
A workspace owner sets up one metadata receiver. Your application keeps its provider credentials; this setup needs no provider or admin key. Optional request labels can be added centrally.
Token observations and conditional estimates are separate from reported spend. Modality, tool fees and hidden retries are unverified. An effective, reviewed customer rate card is required; missing model, tier or cache details remain unavailable.
The helper is a private package, not available on npm. Build and distribute the approved workspace packages using the private distribution instructions before using this example.
Setup is unavailable on this deployment. Local SDK fixtures do not activate a production receiver.
Private build and distribution
In the approved TokenFlow checkout, build both local packages and pack them. Transfer both archives through your organization’s private artifact channel.
pnpm --filter @tokenflow/runtime-metadata build
pnpm --filter @tokenflow/telemetry build
mkdir -p /tmp/tokenflow-private
pnpm --filter @tokenflow/runtime-metadata pack --pack-destination /tmp/tokenflow-private
pnpm --filter @tokenflow/telemetry pack --pack-destination /tmp/tokenflow-private
# In the application checkout, install both supplied archives together:
npm install ./tokenflow-runtime-metadata-0.0.0.tgz ./tokenflow-telemetry-0.0.0.tgzNo package publication is required. Pin the approved build’s archive checksums and retain your existing SDK versions.
Shared client example
import type OpenAI from "openai";
import type Anthropic from "@anthropic-ai/sdk";
import type { ResponseCreateParamsNonStreaming } from "openai/resources/responses/responses";
import type { MessageCreateParamsNonStreaming } from "@anthropic-ai/sdk/resources/messages";
import { createMetadataExporter, createUsageObserver,
extractOpenAiResponse, extractClaudeMessage } from "@tokenflow/telemetry";
// One setup in your shared client module after installing the approved private build.
export function sharedUsage(openai: OpenAI, anthropic: Anthropic,
endpoint: string, receiverToken: string) {
const exporter = createMetadataExporter({schemaVersion: 2, endpoint, token: receiverToken});
const observer = createUsageObserver({exporter, context: {service: {
name: "answer-service", namespace: null, environment: "production",
resourceId: null, accountId: null, region: null, repositoryUrl: null, revision: null,
}}});
return {
response: (params: ResponseCreateParamsNonStreaming) =>
observer.observeOpenAiResponse(() => openai.responses.create(params), extractOpenAiResponse),
message: (params: MessageCreateParamsNonStreaming) =>
observer.observeClaudeMessage(() => anthropic.messages.create(params), extractClaudeMessage),
// Call flush at your own safe point and close during graceful shutdown.
flush: () => exporter.flush(), close: () => exporter.close(),
stats: () => exporter.getStats(),
};
}Use typed application request parameters and the compiled examples for streaming. The application decides when to flush; the helper never makes a provider call.