Installation
Install with your package manager of choice:Quick Start: Interaction API
The Interaction API uses a simple three-step pattern:begin()– Create an interaction and log the initial user input- Update – Optionally call
setProperty,setProperties, oraddAttachments finish()– Record the AI’s final output and close the interaction
Using Vercel AI SDK? Check out our automatic integration to track AI events and traces with zero configuration.
Example: Chat Completion
Updating an Interaction
Update an interaction at any point usingsetProperty, setProperties, or addAttachments:
Resuming an Interaction
If you no longer have the interaction object returned frombegin(), resume it with resumeInteraction():
Single-Shot Tracking (trackAi)
For simple request-response interactions, you can use trackAi() directly:
We recommend usingbegin()→finish()for new code to take advantage of partial-event buffering, tracing, and upcoming features like automatic token counts.
Tracking Signals (Feedback)
Signals capture quality ratings on AI events. UsetrackSignal() with the same eventId from begin() or trackAi():
Self Diagnostics
Self Diagnostics lets your agent proactively report its own issues — capability gaps, missing context, persistent tool failures — back to your team. Signals appear in Raindrop’s Self Diagnostics dashboard. The easiest way to enable Self Diagnostics is by usingwrap() with the Vercel AI SDK:
wrap() reference. For integrations that don’t use the Vercel AI SDK, or can’t use wrap(), the sections below cover standalone alternatives.
Self Diagnostics Tool
createSelfDiagnosticsTool() creates a tool your agent can call to report issues. It gives you:
- A reusable
execute()handler that tracks anagentsignal - Adapter-specific tool definitions for Vercel AI SDK, OpenAI SDK, and Anthropic SDK
missing_context, repeatedly_broken_tool, capability_gap, and complete_task_failure. You can replace these with your own.
eventId:
Supported adapters
createSelfDiagnosticsTool() supports these adapters:
Vercel AI SDK:
UI guidance
__raindrop_report is an internal tool. If your chat UI renders tool calls, hide this tool call from end users to avoid confusing them with internal diagnostics details.
Manual Reporting
If your agent already has its own way of detecting issues, useselfDiagnose() to report them directly — no LLM tool call needed.
Attachments
Attachments let you include additional context—documents, images, code, or embedded content—with your events. They work with bothbegin() interactions and trackAi() calls.
Feature Flags
Feature flags record which flags and experiment variants were active when an event happened, so you can compare AI quality across variants in Raindrop. Likeproperties, they attach to individual events — pass them wherever the event is created (begin() or trackAi()), or set them on a live interaction as your pipeline makes decisions.
Two input forms are accepted:
With begin()
Pass the flags that shaped the request — typically the values you just read from your flag provider (LaunchDarkly, Statsig, PostHog, etc.):
Updating a live interaction
UsesetFeatureFlag / setFeatureFlags when a flag decision happens mid-interaction — for example, a retrieval strategy chosen after begin():
Flags merge across calls; setting the same flag again overwrites its value.
With trackAi()
Identifying Users
PII Redaction
Read more about how Raindrop handles privacy and PII redaction here. Enable client-side PII redaction when initializing the SDK:Error Handling
Exceptions are raised when errors occur while sending events to Raindrop. Handle these appropriately in your application.Configuration
Call
await raindrop.close() before your process exits to flush any buffered events.
Projects
PassprojectId to scope every event from a client to a specific project. Under the hood this sets the X-Raindrop-Project-Id header on each request.
projectId (or passing "default") sends to the default Production project, which is the existing behavior. See Projects for isolation, archival, and the full behavior table.
Multiple projects in one process
When one service runs several agents that should report to different projects — e.g. an Express app serving a support agent and a billing agent — create oneRaindrop client per project and reuse them. The instance is the routing decision; there is no shared mutable project state to race on, so concurrent requests handled by different agents route independently.
begin() scopes every span produced in the current request/task to its client’s project, until the matching finish() (an interaction that is never finished releases its scope once garbage-collected). For LLM calls made outside an interaction, scope them explicitly with asCurrent():
On runtimes without
AsyncLocalStorage.enterWith — notably Cloudflare Workers (workerd) — begin() cannot scope auto-instrumented spans: it still records the interaction and its manual withSpan/withTool/events, but ambient span routing is skipped (so it can’t cross-contaminate concurrent requests). Use asCurrent() (or interaction.withSpan(...)) to route auto-instrumented spans there — those are built on AsyncLocalStorage.run, which Workers support.Tracing
Tracing captures detailed execution information from your AI pipelines—multi-model interactions, chained prompts, and tool calls. This helps you:- Visualize the full execution flow of your AI application
- Debug and optimize prompt chains
- Understand the intermediate steps that led to a response
Getting Started
Wrap your code withwithSpan or withTool on an interaction, and LLM calls inside are automatically captured:
raindrop-ai to serverExternalPackages in your config:
Using withSpan
Use withSpan to trace tasks or operations. Any LLM calls within the span are automatically captured:
Using withTool
Use withTool to trace agent actions—memory operations, web searches, API calls, and more:
Manual Tool Tracking
For more control over tool span tracking, usetrackTool or startToolSpan.
trackTool – Retroactive Logging
Use trackTool to log a tool call after it has completed:
startToolSpan – Real-Time Tracking
Use startToolSpan to track a tool as it executes:
Module Instrumentation
In some environments, automatic instrumentation may not work due to module loading order or bundler behavior. UseinstrumentModules to explicitly specify which modules to instrument:
openAI, anthropic, cohere, bedrock, google_vertexai, google_aiplatform, pinecone, together, langchain, llamaIndex, chromadb, qdrant, mcp.
For Bedrock, use a namespace import — same pattern as Anthropic above. Cross-region inference profile model IDs (e.g. us.anthropic.claude-*) are supported.
OpenTelemetry Integration
If you already have an OpenTelemetry setup (Sentry, Datadog, Honeycomb, etc.), integrate Raindrop alongside it usinguseExternalOtel:
Without
instrumentModules, getInstrumentations() returns instrumentations for all supported AI libraries. Specify instrumentModules to instrument only specific libraries.Direct tool spans in stateless handlers
bypassOtelForTools: true changes how tool spans are shipped, but they still read their parent from the active @opentelemetry/api context. trace.setSpanContext() with context.with() is sufficient when the handler, Sentry, and Raindrop share the same OpenTelemetry API singleton and context manager.
If a stateless handler cannot rely on ambient context, pass the propagated W3C hexadecimal IDs directly. Both values must be supplied together:
That’s it! You’re ready to explore your events in the Raindrop dashboard. Ping us on Slack or email us if you get stuck!