mastra-ai/mastra · error

Attempted to parse provider/model from ${routerId} but this

Error message

Attempted to parse provider/model from ${routerId} but this ID doesn't appear to contain a provider

What it means

After splitting the router ID, parseModelRouterId validates that the ID contains at least one slash and that both providerId and modelId resolved to non-empty strings. This error is thrown when the resulting providerId or modelId is empty (e.g. trailing/leading slashes) or — when no gatewayPrefix is given — the ID has no slash at all, so no provider can be extracted.

Source

Thrown at packages/core/src/llm/model/gateway-resolver.ts:53

    }
    return {
      providerId: gatewayPrefix,
      modelId,
    };
  }

  // Standard 3-part format for other prefixed gateways (Netlify, etc.)
  if (gatewayPrefix && idParts.length < 3) {
    throw new Error(
      `Expected atleast 3 id parts ${gatewayPrefix}/provider/model, but only saw ${idParts.length} in ${routerId}`,
    );
  }

  const providerId = idParts.at(gatewayPrefix ? 1 : 0);
  const modelId = idParts.slice(gatewayPrefix ? 2 : 1).join(`/`);

  if (!routerId.includes(`/`) || !providerId || !modelId) {
    throw new Error(
      `Attempted to parse provider/model from ${routerId} but this ID doesn't appear to contain a provider`,
    );
  }

  return {
    providerId,
    modelId,
  };
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Include the provider in the ID, e.g. use 'openai/gpt-4o' instead of 'gpt-4o'.
  2. Check for empty ID segments — remove trailing or duplicate slashes like 'openai/' or '//model'.
  3. Inspect any template-string construction of the ID for undefined/null variables that collapse to empty segments.
  4. Log the exact routerId in the message and verify it matches the catalog/model-list ID you intend to resolve.

Example fix

// before
const model = gateway.resolveModel('gpt-4o');
// after
const model = gateway.resolveModel('openai/gpt-4o');
Defensive patterns

Strategy: validation

Validate before calling

function ensureProviderPrefixedId(routerId: string): void {
  const parts = routerId.split('/');
  if (parts.length < 2 || !parts[0] || !parts[1]) {
    throw new Error(`Router ID must include a provider: expected provider/model, got "${routerId}"`);
  }
}

Type guard

function hasProviderAndModel(routerId: string): boolean {
  const [provider, model] = routerId.split('/');
  return Boolean(provider && model);
}

Try / catch

try {
  const { providerId, modelId } = parseModelRouterId(routerId);
} catch (e) {
  throw new Error(`Router ID "${routerId}" lacks a provider segment; use provider/model form`, { cause: e });
}

Prevention

When it happens

Trigger: Calling parseModelRouterId with an unprefixed ID lacking a slash (e.g. 'gpt-4o'), or IDs with empty segments such as 'openai/' or '/gpt-4o' (also reachable for gateway-prefixed IDs with empty trailing parts).

Common situations: Passing a bare model name without a provider prefix; string interpolation producing empty segments (e.g. `"${provider}/${undefined}"` -> 'openai/'); trimming or joining strings incorrectly before resolution.

Related errors


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