Skip to main content

Confident AI exporter

Confident AI is an LLM observability and evaluation platform for teams to build reliable AI applications in both development and production.

The @mastra/deepeval package sends your Mastra traces to Confident AI, where you can run metrics against them and track quality over time. It builds on DeepEval, the open-source evaluation SDK behind the platform.

Installation
Direct link to Installation

npm install @mastra/deepeval@latest

Configuration
Direct link to Configuration

Prerequisites
Direct link to Prerequisites

  1. Confident AI account: Sign up at confident-ai.com
  2. API key: Generate one in your Confident AI project settings
  3. Environment variables: Set your credentials:
.env
CONFIDENT_API_KEY=confident_proj_xxxxxxxxxxxxx

# Optional
CONFIDENT_TRACE_ENVIRONMENT=production # Defaults to "development"

Zero-Config Setup
Direct link to Zero-Config Setup

With environment variables set, use the exporter with no configuration:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { Observability } from '@mastra/observability'
import { DeepEvalExporter } from '@mastra/deepeval'

export const mastra = new Mastra({
observability: new Observability({
configs: {
deepeval: {
serviceName: 'my-service',
exporters: [new DeepEvalExporter()],
},
},
}),
})

Explicit Configuration
Direct link to Explicit Configuration

You can also pass credentials directly (takes precedence over environment variables):

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { Observability } from '@mastra/observability'
import { DeepEvalExporter } from '@mastra/deepeval'

export const mastra = new Mastra({
observability: new Observability({
configs: {
deepeval: {
serviceName: 'my-service',
exporters: [
new DeepEvalExporter({
apiKey: process.env.CONFIDENT_API_KEY,
environment: 'production',
}),
],
},
},
}),
})

Metric collections
Direct link to Metric collections

Confident AI evaluates incoming traces against metric collections defined in your project. Attach them at the trace level or per span type. Trace-level metrics run against the whole trace, and per-type metrics run against matching spans.

src/mastra/index.ts
new DeepEvalExporter({
metricCollection: 'trace-metrics', // trace-level
llmMetricCollection: 'llm-metrics', // applied to LLM spans
agentMetricCollection: 'agent-metrics', // applied to agent spans
toolMetricCollectionMap: {
search: 'search-tool-metrics', // applied to the "search" tool
},
})

Complete Configuration
Direct link to Complete Configuration

new DeepEvalExporter({
apiKey: process.env.CONFIDENT_API_KEY,
environment: 'production', // Default: "development"
name: 'my-trace', // Default: the Mastra serviceName
tags: ['production'],
metadata: { team: 'growth' },
})

Span type mapping
Direct link to Span type mapping

Mastra spans map to the span types shown in Confident AI:

Mastra span typeConfident AI span type
AGENT_RUN, WORKFLOW_RUNAGENT
MODEL_GENERATIONLLM
TOOL_CALL, MCP_TOOL_CALL, PROVIDER_TOOL_CALL, CLIENT_TOOL_CALLTOOL
RAG_EMBEDDING, RAG_VECTOR_OPERATIONRETRIEVER
All other exported span typesCUSTOM