Skip to Content

Other AI SDKs

TanStack AI

Automatic tracking for TanStack AI chat middleware with Raindrop.

@raindrop-ai/tanstack-ai adds Raindrop to TanStack AI chat() via a ChatMiddleware. It captures each chat invocation as a Raindrop event plus an OTel trace, and uses TanStack threadId to keep multi-turn chats grouped together.

Install

pnpm add @raindrop-ai/tanstack-ai @tanstack/ai @tanstack/ai-openai

Quick start

import { createRaindropTanstackAI } from "@raindrop-ai/tanstack-ai";
import { chat } from "@tanstack/ai";
import { openaiText } from "@tanstack/ai-openai/adapters";

const raindrop = createRaindropTanstackAI({
  writeKey: process.env.RAINDROP_WRITE_KEY,
  endpoint: "https://api.raindrop.ai/v1",
  events: { enabled: true },
  traces: { enabled: true },
  defaults: {
    userId: "user-123",
    eventName: "support_chat",
  },
});

for await (const chunk of chat({
  adapter: openaiText(),
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello!" }],
  threadId: "convo-abc",
  middleware: [raindrop.middleware],
  context: {
    userId: "user-123",
    convoId: "convo-abc",
    eventName: "support_chat",
    eventId: "evt_123",
  },
})) {
  void chunk;
}

await raindrop.flush();

Configuration

createRaindropTanstackAI() accepts the public options exported by the package:

OptionDescription
writeKeyOptional Raindrop write key. Omit it to keep telemetry local-only or disabled, depending on your workshop setup.
endpointOptional Raindrop API endpoint.
projectIdOptional project slug. Sets X-Raindrop-Project-Id on outbound event and trace requests.
localWorkshopUrlOptional explicit Workshop / local debugger URL. Pass false to opt out of local mirroring.
eventsEvent shipping controls (enabled, debug, partialFlushMs).
tracesTrace shipping controls (enabled, debug, debugSpans, flushIntervalMs, maxBatchSize, maxQueueSize).
defaultsFallback userId, convoId, eventName, eventId, and properties when a call omits them.
captureContentWhen false, omits message bodies, system prompts, tool args, and tool results from captured telemetry.
appGitApplication Git values/discovery options, or false to disable client enrichment.

For multi-project organizations, create one client per project and pass each project's slug as projectId. Omit projectId to use the organization's default project.

Per-call overrides go on TanStack AI's context object:

chat({
  ...
  context: {
    userId: "user-123",
    convoId: "convo-abc",
    eventName: "support_chat",
    eventId: "evt_123", // or event_id
    properties: { source: "docs" },
  },
});

eventId / event_id override the generated event ID for that request. When convoId is omitted, the middleware falls back to TanStack AI's threadId.

What gets captured

  • One Raindrop event per chat() call
  • One trace per chat() call
  • Message content and system prompts when captureContent is left on
  • Tool calls and tool results
  • Per-call metadata from context.properties

Tool catalog capture (ai.prompt.tools)

Every model call's span records the tools the engine handed the adapter for that call as ai.prompt.tools (TanStack inputSchemas are converted with convertSchemaToJsonSchema). This is exact per-call capture; captureContent: false suppresses it with the rest of the prompt. Pass tools in the middleware options to record a different list instead (it replaces the inferred one; tools: [] records an empty catalog). See Tool catalog capture for the attribute format, the absent / [] semantics and the override shapes accepted.

Known limitations

  • TanStack AI does not expose a public attachment channel on the chat() capture path yet, so attachments are not captured here.
  • Capture currently ships through the partial-event route, so the event is emitted first and finalized by patching the partial record.

Application Git identity

In ordinary Node.js runtimes, createRaindropTanstackAI discovers a reliable application SHA in the background. Use appGit for commitSha, commitDirty, branch, sourceDirectory, detectBranch, or autoDetect; browser builds require explicit build injection. See the TypeScript Git reference.

On this page