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

# Mastra

> Use Mastra with Keywords AI

This tutorial shows how to set up Keywords AI tracing with [Mastra](https://mastra.ai/) to monitor and trace your AI-powered applications.

To help you get started quickly, we’ve provided a pre-built example. You can find the code [on GitHub](https://github.com/Keywords-AI/keywordsai-example-projects/tree/main/mastra-ai-weather-agent).

## Setup

Here's the tutorial about the Mastra Weather Agent example.

### 1. Install Dependencies

```bash theme={"system"}
pnpm install
```

### 2. Environment Variables

Copy the example environment file and add your API keys:

```bash theme={"system"}
cp .env.local.example .env.local
```

Update .env.local with your credentials:

```bash .env.local theme={"system"}
OPENAI_API_KEY=your-openai-api-key
KEYWORDSAI_API_KEY=your-keywordsai-api-key
KEYWORDSAI_BASE_URL=https://api.keywordsai.co
```

### 3. Setup Mastra client with Keywords AI tracing

Configure with KeywordsAI telemetry in `src/mastra/index.ts`:

```typescript theme={"system"}
telemetry: {
  serviceName: "keywordai-mastra-example",
  enabled: true,

# ===== Add this section =====
  export: {
    type: "custom",
    exporter: new KeywordsAIExporter({
      apiKey: process.env.KEYWORDSAI_API_KEY,
      baseUrl: process.env.KEYWORDSAI_BASE_URL,
      debug: true,
    })
  }
}
```

### 3. Run the Project

```bash theme={"system"}
mastra dev
```

This opens the Mastra playground where you can interact with the weather agent.

## Observability

Once configured, you can view your traces and analytics in the [Keywords AI platform](https://platform.keywordsai.co/platform/traces).
