Tracking events

Use noryen.track() when you are not using a built-in wrapper, or when you need full control over the payload (custom providers, proxies, or non-HTTP flows).

Validation rules

  • model is required.
  • For successful calls prompt and response must be non-empty. Otherwise the event is dropped (a debug warning will appear if debug is on).
  • For failures, set success: false and prefer including error.

Example

track.ts
noryen.track({
model: "gpt-4o-mini",
provider: "openai",
prompt: "Summarize this text in 3 bullets.",
response: "1) ... 2) ... 3) ...",
latency: 820,
cost: 0.0012,
inputTokens: 120,
outputTokens: 80,
metadata: { env: "prod", feature: "summary" },
});

Common fields

Optional but useful fields include provider, latency (ms), cost, token counts (inputTokens, outputTokens, totalTokens), requestId, and metadata (see Metadata).

Failed requests

track-failure.ts
noryen.track({
model: "gpt-4o-mini",
success: false,
error: "Rate limited",
prompt: "…",
// response can be omitted or minimal when success is false
});
Events are queued and sent asynchronously. In short-lived environments, call flush() before the process or request ends.