{"record":{"id":"1f6d9088ce6dd3c2","repo":"mastra-ai/mastra","slug":"invalid-model-id-modelid","errorCode":null,"errorMessage":"Invalid model id: ${modelId}","messagePattern":"Invalid model id: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/agents/model.ts","lineNumber":117,"sourceCode":"    ? modelId.slice(MASTRACODE_GATEWAY_ID.length + 1)\n    : modelId;\n  // Deployed web registers a custom providers source (DB-backed, tenant\n  // scoped); when registered it is authoritative and settings.json custom\n  // providers are ignored. Undefined = local settings-based behavior.\n  const customProviders = resolveCustomProviders(options?.requestContext) ?? settings.customProviders;\n  // Ids selected from the shared /models catalog were previously persisted in\n  // the gateway-qualified `mastracode/<customProviderId>/<model>` form, which\n  // parses the provider as `mastracode` and breaks provider config lookup.\n  // Normalize at resolution time (in addition to stripping at selection time)\n  // so already-saved ids and any surface that persists the raw catalog id\n  // still resolve to the custom provider.\n  const normalizedInput = stripMastraCodeCustomProviderPrefix(bedrockNormalizedInput, customProviders);\n  const isMastraGatewayModel = normalizedInput.startsWith(MASTRA_GATEWAY_PREFIX);\n  const normalizedModelId = stripMastraGatewayPrefix(normalizedInput);\n  const [providerId, ...modelParts] = normalizedModelId.split('/');\n  const bareModelId = modelParts.join('/');\n  if (!providerId || !bareModelId) {\n    throw new Error(`Invalid model id: ${modelId}`);\n  }\n\n  if (providerId === AMAZON_BEDROCK_GATEWAY_ID) {\n    const bedrockGateway = createAmazonBedrockGateway();\n    const routerId = `${AMAZON_BEDROCK_GATEWAY_ID}/${bareModelId}`;\n    const auth = bedrockGateway.resolveAuth({\n      gatewayId: AMAZON_BEDROCK_GATEWAY_ID,\n      providerId: AMAZON_BEDROCK_GATEWAY_ID,\n      modelId: bareModelId,\n      routerId,\n    });\n    return bedrockGateway.resolveLanguageModel({\n      providerId: AMAZON_BEDROCK_GATEWAY_ID,\n      modelId: bareModelId,\n      apiKey: auth?.apiKey ?? '',\n      headers,\n    });\n  }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/agents/model.ts#L99-L135","documentation":"resolveModel parses a model id as `provider/rest-of-path` after stripping gateway/custom-provider prefixes. If either the provider segment or the remainder (bareModelId) is empty, the id is malformed and 'Invalid model id' is thrown. This includes ids with no slash at all (e.g. 'gpt-4o').","triggerScenarios":"resolveModel (via getObserverModel/getReflectorModel/getDynamicModel/etc.) receives a modelId that after normalization has no `provider/model` structure: empty string, bare model name without a slash, 'provider/' with empty remainder, or just '/'-degenerate strings.","commonSituations":"Writing 'gpt-4o' instead of 'openai/gpt-4o', config files with a blank or whitespace model field, accidentally deleting the provider prefix during edits, or copying an id with a trailing slash.","solutions":["Provide the full `provider/model-id` form, e.g. 'openai/gpt-4o' or 'anthropic/claude-sonnet-4'","Check the model config/env for an empty or whitespace-only value and set a valid id","If using gateway prefixes, keep the provider segment after the prefix (e.g. 'mastra/gateway/openai/gpt-4o' style per convention)","Log the raw modelId before resolveModel to see what is actually being passed"],"exampleFix":"// before\nmodel: 'gpt-4o'\n// after\nmodel: 'openai/gpt-4o'","handlingStrategy":"validation","validationCode":"const VALID = /^[a-z0-9-]+\\/.+$/i;\nif (!VALID.test(modelId)) throw new Error(`model id must be provider/model, got: ${modelId}`);","typeGuard":"const isProviderQualified = (id: string): boolean =>\n  id.includes('/') && id.split('/').every(p => p.length > 0);","tryCatchPattern":"try {\n  const model = resolveModel(modelId);\n} catch (err) {\n  if ((err as Error).message.startsWith('Invalid model id')) {\n    console.error(`Use provider/model form, e.g. openai/gpt-4o (got \"${modelId}\")`);\n  } else throw err;\n}","preventionTips":["Validate model ids against a known provider list at config load time","Never store bare model names in configs; always qualify with provider","Trim/normalize model id inputs before resolveModel"],"tags":["configuration","validation","model-id"],"backgroundTag":"invalid-model-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}