Back to Guides

Mastra

Build AI agents with TypeScript and React

TypeScripteasy

Mastra is a TypeScript framework for building AI agents. Decyra captures all agent interactions and LLM calls, providing comprehensive observability into your Mastra agents.

Prerequisites

  • Decyra account with API key
  • Node.js 18+ installed
  • Mastra package installed

Installation

npm install @mastra/core @mastra/ai @decyra/sdk

Integration

Wrap the OpenAI client with Decyra:

import { createMastra } from '@mastra/core';
import { createOpenAI } from '@mastra/ai';
import { wrapOpenAI } from '@decyra/sdk';

const openaiClient = createOpenAI({
  apiKey: process.env.DECYRA_API_KEY,
  baseURL: 'https://proxy.decyra.com/v1',
  defaultHeaders: {
    'X-Decyra-API-Key': process.env.DECYRA_API_KEY!,
  },
});

const decyraClient = wrapOpenAI(openaiClient);

const mastra = createMastra({
  name: 'my-app',
  ai: {
    providers: {
      openai: decyraClient,
    },
  },
});

Define and use an agent:

const agent = mastra.agent({
  name: 'assistant',
  instructions: 'You are a helpful assistant',
  model: 'gpt-4',
});

const response = await agent.generate('Explain quantum computing');
console.log(response.text);

What Gets Captured

FieldDescription
ModelThe AI model used
TemperatureTemperature parameter
Agent NameName of the Mastra agent
InstructionsAgent system instructions
Prompt HashHash of the input prompt
Response TimeTime for agent execution
Token UsageInput/output tokens
CostEstimated API cost

Verify

Check your Decyra dashboard to see agent interactions in the traces view. Each agent call will include full context and model details.

Next Steps