Skip to main content
@squasher-ai/agent records the model calls and tool calls of your server-side AI code. With the Vercel AI SDK, versions 4 to 7, you wrap the ai module once, and every generateText and streamText call appears in AI observability.

What the SDK records

Install the SDK

Add your ingest key and project ID to the server environment as SQUASHER_API_KEY and SQUASHER_PROJECT_ID. To get both values, see Create an ingest key. The package is ESM only and runs on the server.

Wrap the AI SDK once

src/ai.ts
ai has the same exports and types as the ai package. Your callbacks and telemetry settings stay as they are.

Scope each request

Call .with() to add the session and user of a request. It returns a new scoped module and does not change the shared one.
src/chat.ts
Nested .with() calls merge: the inner values win, and attributes merge by key.

Flush before a serverless function ends

The SDK sends data in batches. In a serverless function, flush before the function returns:
src/handler.ts
For a stream, flush after the stream finishes, for example in the runtime’s waitUntil. A flush before the stream ends can miss the last data. Call ai.close() when the process shuts down, not after each request.

Record prompts and output text

Prompts and output text are off by default. Turn them on only where you have a policy to keep them:
captureReasoning: true also records reasoning text. On AI SDK 6 and 7, capturePayloads keeps the provider response, which can contain reasoning. To make sure that no content is recorded, set privacyMode: true: it wins over the other options.

Record quality scores

Link a score to a trace: set your own traceId (32 hex characters) on the request, then send the score with the same traceId.
src/answer.ts

Send data without the AI SDK

For other frameworks, use the client directly. Every generation and tool call needs a traceId and a spanId; Squasher drops events without them.
captureToolCall(name, input) records a tool call the same way. To send AI data without any SDK, see HTTP batch ingest.

Options

Limits

  • The wrapper records generateText and streamText only. generateObject, streamObject, embeddings, and agent classes work as before, but Squasher does not record them.
  • On AI SDK 4 and 5, streamed output text is not recorded, even with capturePayloads.
  • If Squasher cannot record a call, your model call still runs and returns as normal.
  • The package also exports lower-level parts: createAiSdkTelemetryIntegration, createAiSdkV6TelemetryIntegration, and squasherMiddleware. When you use the integration directly, prompts and output are recorded unless you set privacyMode: true.

Give the setup to a coding agent

Next steps

AI observability

Read the data in the dashboard.

OpenRouter

Record OpenRouter calls with their exact cost.