mastra-ai/mastra · error

Platform integration: missing required config field(s): ${mi

Error message

Platform integration: missing required config field(s): ${missing.join(', ')}.

What it means

The `PlatformApiClient` constructor validates its config and throws when any of the required fields `baseUrl` or `accessToken` is missing/empty, listing the offending field names in the message. This catches programmatically-constructed (not env-derived) configurations before any network call is made.

Source

Thrown at mastracode/factory/src/integrations/platform/api-client.ts:46

  readonly retryAfterSeconds: number | null;

  constructor(message: string, status: number, retryAfterSeconds: number | null = null) {
    super(message);
    this.name = 'PlatformApiError';
    this.status = status;
    this.retryAfterSeconds = retryAfterSeconds;
  }
}

export class PlatformApiClient {
  readonly #baseUrl: string;
  readonly #accessToken: string;
  readonly #fetch: typeof fetch;

  constructor(config: PlatformApiClientConfig) {
    const missing = ['baseUrl', 'accessToken'].filter(field => !config[field as keyof PlatformApiClientConfig]);
    if (missing.length > 0) {
      throw new Error(`Platform integration: missing required config field(s): ${missing.join(', ')}.`);
    }
    this.#baseUrl = config.baseUrl.replace(/\/+$/, '');
    this.#accessToken = config.accessToken;
    this.#fetch = config.fetchImpl ?? globalThis.fetch;
  }

  async request<T>(
    method: string,
    path: string,
    body?: unknown,
    options?: { signal?: AbortSignal; actingUserId?: string },
  ): Promise<T> {
    const response = await this.#send(method, path, body, options);
    if (!response.ok) {
      const message = redact(await extractError(response), this.#accessToken);
      const retryAfterSeconds = parseRetryAfter(response.headers.get('retry-after'));
      logPlatformError('Platform API request failed', {
        method,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Populate both `baseUrl` and `accessToken` in the `PlatformApiClientConfig` object before construction.
  2. Prefer `platformApiClientConfigFromEnv()` to build the config so missing values fail with the clearer env-var error instead.
  3. Add a pre-construction check/logging of the config keys to spot which field is absent.
  4. If fields come from a config file, validate the parsed object's shape before passing it to the constructor.

Example fix

// before
const client = new PlatformApiClient({ baseUrl: 'https://api.example.com' });
// after
const client = new PlatformApiClient({
  baseUrl: 'https://api.example.com',
  accessToken: process.env.MASTRA_PLATFORM_ACCESS_TOKEN!,
});
Defensive patterns

Strategy: validation

Validate before calling

function assertPlatformConfig(config: Partial<PlatformApiClientConfig>): asserts config is PlatformApiClientConfig {
  const missing = (['baseUrl', 'accessToken'] as const).filter(k => !config[k]);
  if (missing.length) throw new Error(`PlatformApiClient config missing: ${missing.join(', ')}`);
}

Type guard

function isCompletePlatformConfig(c: Partial<PlatformApiClientConfig>): c is PlatformApiClientConfig {
  return typeof c.baseUrl === 'string' && c.baseUrl.length > 0 && typeof c.accessToken === 'string' && c.accessToken.length > 0;
}

Try / catch

try {
  const client = new PlatformApiClient(config);
} catch (e) {
  if (e.message.startsWith('Platform integration: missing required config field')) {
    console.error('Invalid PlatformApiClient config:', e.message);
    config = platformApiClientConfigFromEnv(); // fall back to env-derived config
    return new PlatformApiClient(config);
  }
  throw e;
}

Prevention

When it happens

Trigger: Constructing `new PlatformApiClient(config)` where `config.baseUrl` or `config.accessToken` is `undefined`, `null`, or an empty string — e.g. building the config object by hand, spreading a partial options object, or a custom config loader that returned incomplete values instead of using `platformApiClientConfigFromEnv`.

Common situations: Hardcoding a client in tests/scripts and forgetting `accessToken`; a factory that conditionally sets fields and skips empty ones; reading config from a parsed JSON/YAML file where a key is absent; renaming a field in the config type without updating all construction sites.

Related errors


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