{"record":{"id":"f3d5c844abe4b4e5","repo":"mastra-ai/mastra","slug":"expected-format-gatewayprefix-model-but-got","errorCode":null,"errorMessage":"Expected format ${gatewayPrefix}/model, but got ${routerId}","messagePattern":"Expected format (.+?)/model, but got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateway-resolver.ts","lineNumber":34,"sourceCode":"  if (gatewayPrefix === 'azure-openai') {\n    const modelId = idParts.slice(1).join('/');\n    if (!modelId) {\n      throw new Error(`Expected format azure-openai/deployment-name, but got ${routerId}`);\n    }\n    return {\n      providerId: 'azure-openai',\n      modelId, // Deployment name\n    };\n  }\n\n  // Provider-equals-gateway: a gateway whose provider id is the same as its\n  // gateway id (e.g. amazon-bedrock) uses a 2-part router id (gateway/model),\n  // because there is no separate provider segment to namespace. Catalog ids\n  // for such gateways are always two parts (model ids contain no slashes).\n  if (gatewayPrefix && idParts.length === 2 && idParts[0] === gatewayPrefix) {\n    const modelId = idParts[1];\n    if (!modelId) {\n      throw new Error(`Expected format ${gatewayPrefix}/model, but got ${routerId}`);\n    }\n    return {\n      providerId: gatewayPrefix,\n      modelId,\n    };\n  }\n\n  // Standard 3-part format for other prefixed gateways (Netlify, etc.)\n  if (gatewayPrefix && idParts.length < 3) {\n    throw new Error(\n      `Expected atleast 3 id parts ${gatewayPrefix}/provider/model, but only saw ${idParts.length} in ${routerId}`,\n    );\n  }\n\n  const providerId = idParts.at(gatewayPrefix ? 1 : 0);\n  const modelId = idParts.slice(gatewayPrefix ? 2 : 1).join(`/`);\n\n  if (!routerId.includes(`/`) || !providerId || !modelId) {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateway-resolver.ts#L16-L52","documentation":"Gateways without a separate provider segment (e.g. \"amazon-bedrock\") use a 2-part router id \"gateway/model\". When the id has exactly 2 parts and the first matches the gatewayPrefix, the second part (model id) must be non-empty; otherwise the function throws because it cannot resolve an empty model.","triggerScenarios":"parseModelRouterId(\"amazon-bedrock/\", \"amazon-bedrock\") — gateway-prefixed id whose model segment after the slash is empty.","commonSituations":"Model variable empty/undefined during string interpolation; trailing slash left from path joining; data migrated with truncated ids.","solutions":["Supply the model id: \"amazon-bedrock/your-model-id\".","Guard the model value is non-empty before constructing the router id.","Strip trailing slashes when composing ids from base path + model."],"exampleFix":"// before\nparseModelRouterId(`amazon-bedrock/${modelId}`, \"amazon-bedrock\"); // modelId === \"\"\n// after\nif (!modelId) throw new Error(\"modelId is required\");\nparseModelRouterId(`amazon-bedrock/${modelId}`, \"amazon-bedrock\");","handlingStrategy":"validation","validationCode":"const modelId = 'embed-model-id';\nif (!modelId) throw new Error('Model id is required for gateway router id');\nconst routerId = `amazon-bedrock/${modelId}`;\nparseModelRouterId(routerId, 'amazon-bedrock');","typeGuard":"const isValidGatewayModelId = (id, prefix) => id.startsWith(`${prefix}/`) && Boolean(id.split('/')[1]);","tryCatchPattern":"try {\n  const { providerId, modelId } = parseModelRouterId(routerId, 'amazon-bedrock');\n} catch (e) {\n  if (e instanceof Error && e.message.includes(`${gatewayPrefix}/model`)) {\n    console.error(`Empty model segment in router id: \"${routerId}\"`);\n  } else throw e;\n}","preventionTips":["Trim trailing slashes when composing gateway/model ids.","Guard interpolated variables for emptiness before building ids.","Validate stored ids at load time so failures surface at boot, not at request time."],"tags":["parsing","gateway","validation"],"backgroundTag":"invalid-model-string-format","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}