Skip to main content
Use @squasher-ai/agent when you need structured telemetry for AI workflows rather than plain errors and logs. It is a good fit for:
  • agent backends
  • customer chat assistants
  • tool-calling workflows
  • OpenRouter / OpenAI-compatible inference pipelines
  • internal copilots and runbooks

Install

Initialize

src/agent.ts

Capture a session lifecycle

Vercel AI SDK / streamText() integration

If you already use AI SDK 7, attach Squasher as an AI SDK telemetry integration through telemetry. AI SDK 7 requires Node.js 22+ and ESM imports. Squasher turns its lifecycle events into session, span, generation, and tool-call observations for the AI observability views. The shortest path is the AI SDK telemetry integration hook:
You can also use the lower-level callback factory when adapting a runtime that invokes lifecycle methods itself. For AI SDK 7 calls, prefer createAiSdkTelemetryIntegration() so the v7 onStepEnd, onToolExecutionStart, onToolExecutionEnd, and onEnd events are mapped correctly.
This captures, automatically and per step:
  • the enclosing session and run span
  • each completed generation
  • tool call start/finish events with sanitized input/output payloads
  • prompt / completion / total tokens
  • reasoning tokens (usage.outputTokenDetails.reasoningTokens from the AI SDK) — surfaced as reasoning_tokens on the observation
  • cached input tokens (usage.inputTokenDetails.cacheReadTokens) — surfaced as cached_input_tokens
  • the assistant text output (final text)
  • the reasoning text only when you explicitly set captureReasoning: true — stored alongside the text in the generation’s output payload as reasoning
  • cost in USD — taken from providerMetadata.openrouter.usage.cost (OpenRouter), providerMetadata.gateway.cost (Vercel AI Gateway), or any explicit costUsd you pass through. When none of those are present, Squasher computes cost server-side from the token counts × a maintained per-model rate table, so the dashboard always shows a number for known models
  • provider + model metadata (with the AI SDK’s .chat / .responses suffix stripped)
If you want a cost value Squasher cannot derive from providerMetadata, pass costUsd in the second argument to captureGeneration("message", { ..., costUsd: 0.0123 }) or set it on the result you forward to onStepFinish. Use privacyMode: true when customer or model content should not leave your service. Token counts, model/provider identifiers, finish status, tool names, timings, prompt references without variables, and your custom attributes still flow through. Prompt messages, prompt variables, generation text, reasoning text, provider payloads, warnings, raw error text, and tool input/output are omitted. Reasoning text is opt-in even when privacy mode is disabled. Set captureReasoning: true only when you have a deliberate retention and access policy for provider-supplied reasoning content. privacyMode: true always wins and suppresses reasoning text.
To capture reasoning text explicitly:

Editable human feedback

Ratings and thumbs feedback can be attached to the exact generation a user judged. A stable feedback id makes edits replace the prior value:
Use sentiment: "positive" | "negative" instead of rating for thumbs feedback. Squasher records both forms as human annotations.

How it appears in Squasher

Agent telemetry is sent to Squasher’s remote observability pipeline and is stored with your project telemetry. Use local logs or development artifacts only as temporary debugging aids; Squasher remains the system of record for production AI observability, historical search, and AI triage context.

Good fit

  • Agent backends that need per-run traces.
  • Tool execution and generation visibility.
  • Session-level analytics tied back to a customer, workflow, or environment.

Agent handoff

Use this prompt when a coding agent is instrumenting an AI workflow:

Notes

  • @squasher-ai/agent is for server-side runtimes.
  • Flush before shutdown so queued telemetry is delivered.
  • Completed generations count toward your plan’s AI request quota.
  • Free plans drop additional AI requests after the monthly included quota is exhausted.
  • Paid plans continue ingesting above the included quota and meter overage usage.
  • For a full OpenRouter example, see /integrations/openrouter.
  • If you don’t want to install an SDK at all, send the same generations directly to the AI batch ingest endpoint — see Direct HTTP ingest on the OpenRouter page for the worked curl example.