> ## Documentation Index
> Fetch the complete documentation index at: https://raindrop.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra (Beta)

> Automatic tracing for Mastra agents with Raindrop

## Installation

```bash npm theme={null}
npm install @raindrop-ai/mastra @mastra/core
```

## Quick Start

```typescript theme={null}
import { createRaindropMastra } from "@raindrop-ai/mastra";
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";

const raindrop = createRaindropMastra({
  writeKey: "your-write-key",
  userId: "user-123",
});

const agent = new Agent({
  name: "Assistant",
  model: openai("gpt-4o-mini"),
  instructions: "Be helpful",
});

const wrapped = raindrop.wrap(agent);

const response = await wrapped.generate("What is the capital of France?");
console.log(response.text);

await raindrop.shutdown();
```

## What Gets Traced

* **Agent generate** — input prompt, output text, model, token usage (promptTokens/completionTokens)
* **Errors** — captured with error status, re-thrown to caller

## Configuration

```typescript theme={null}
const raindrop = createRaindropMastra({
  writeKey: "your-write-key",       // Optional: omit to disable telemetry
  endpoint: "...",          // Optional: custom Raindrop API endpoint
  userId: "user-123",      // Optional: associate events with a user
  convoId: "convo-456",    // Optional: conversation/thread ID
  projectId: "support-prod", // Optional: route events to a specific project (slug)
  debug: false,             // Optional: enable verbose logging
});
```

## Projects

Route events to a specific [project](/platform/projects) by passing its slug as `projectId`:

```typescript theme={null}
const raindrop = createRaindropMastra({
  writeKey: "your-write-key",
  projectId: "support-prod",
});
```

This sets the `X-Raindrop-Project-Id` header on every event. Omit it (or pass `"default"`) to use your org's default **Production** project, which is the existing behavior. Single-project orgs need nothing new.

## Flushing and Shutdown

```typescript theme={null}
await raindrop.flush();     // flush pending data
await raindrop.shutdown();  // flush + release resources
```
