mastra-ai/mastra · critical

Unable to locate pricing data JSONL at any known path: ${can

Error message

Unable to locate pricing data JSONL at any known path: ${candidates.join(', ')}

What it means

resolvePricingModelPath probes a list of known filesystem locations (package root, workspace, relative paths) to find the LLM pricing JSONL data file shipped with @mastra/observability. If none of the candidate paths exists on disk, it throws. This almost always means a broken/partial install or running from an unexpected working directory/build layout.

Source

Thrown at observability/mastra/src/metrics/pricing-registry.ts:180

  });
}

function resolvePricingModelPath(): string {
  const packageRoot = getPackageRoot();
  const candidates = [
    path.join(packageRoot, 'dist', 'metrics', DATA_FILE_NAME),
    path.join(packageRoot, 'src', 'metrics', DATA_FILE_NAME),
    path.join(process.cwd(), 'observability', 'mastra', 'src', 'metrics', DATA_FILE_NAME),
    path.join(process.cwd(), 'src', 'metrics', DATA_FILE_NAME),
  ];

  for (const candidate of candidates) {
    if (fs.existsSync(candidate)) {
      return candidate;
    }
  }

  throw new Error(`Unable to locate pricing data JSONL at any known path: ${candidates.join(', ')}`);
}

function getPackageRoot(): string {
  try {
    const require = createRequire(import.meta.url || 'file://');
    const packageJsonPath = require.resolve('@mastra/observability/package.json');
    return path.dirname(packageJsonPath);
  } catch {
    return process.cwd();
  }
}

function makePricingKey(args: { provider: string; model: string }): string {
  return `${normalizeKeyPart(args.provider)}::${normalizeKeyPart(args.model)}`;
}

function normalizeKeyPart(value: string): string {
  return value.trim().toLowerCase();

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Reinstall/clean-rebuild @mastra/observability (pnpm install; rebuild the package) so the pricing JSONL ships with node_modules.
  2. Verify the file exists at node_modules/@mastra/observability/ (search for *.jsonl); if missing, the package or bundler is dropping assets — fix the build's asset-copy step.
  3. If bundling, mark the JSONL as an external asset or copy it and point the resolver at a known path via the supported candidates.
  4. Check you're not using an unofficial/patched package version that omits the data file; upgrade to a released version.

Example fix

// before: bundler stripped data files
// after: esbuild config keeps the asset resolvable
export default {
  external: ['@mastra/observability'],
  loader: { '.jsonl': 'file' },
};
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from 'node:module';
import { existsSync } from 'node:fs';
const req = createRequire(import.meta.url);
const pkgRoot = req.resolve('@mastra/observability/package.json');
const hasPricingData = existsSync(require('node:path').join(require('node:path').dirname(pkgRoot), 'metrics')) 
  || existsSync('./metrics/llm-pricing.jsonl');
if (!hasPricingData) throw new Error('Pricing JSONL missing; reinstall @mastra/observability before initializing cost metrics');

Type guard

function pricingFileExists(paths: string[]): boolean {
  return paths.some((p) => existsSync(p));
}

Try / catch

try {
  costMetric.enable();
} catch (err) {
  if (String(err.message).includes('Unable to locate pricing data JSONL')) {
    console.error('Reinstall @mastra/observability — pricing data file missing');
    process.exitCode = 1;
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Creating a cost/pricing metric (pricing-registry `content` accessor) when the pricing JSONL file is missing from every candidate path — e.g. package published without bundled data files, monorepo build that skipped copying assets, or npm/pnpm install that pruned files.

Common situations: Installing from a registry mirror or pack that drops .jsonl assets; running tests from a bundle (esbuild/webpack) that didn't include the data file; developing inside the monorepo before building @mastra/observability; exotic package managers (Bun/Deno npm compat) resolving package.json differently.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/094e38177c174dbf. Report an issue: GitHub.