{"record":{"id":"3ca1941e50922f8d","repo":"mastra-ai/mastra","slug":"model-router-no-gateway-found","errorCode":"MODEL_ROUTER_NO_GATEWAY_FOUND","errorMessage":"No Mastra model router gateway found for model id ${gatewayId}","messagePattern":"No Mastra model router gateway found for model id (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/gateway-helpers.ts","lineNumber":53,"sourceCode":"  });\n  if (prefixedGateway) {\n    return prefixedGateway;\n  }\n\n  // Then check gateways that explicitly claim this (possibly unprefixed) model\n  // id, e.g. a gateway that authenticates a bare `anthropic/...` id via OAuth.\n  const claimingGateway = gateways.find(g => getGatewayId(g) !== 'models.dev' && g.handlesModel?.(gatewayId) === true);\n  if (claimingGateway) {\n    return claimingGateway;\n  }\n\n  // Then check models.dev (provider registry without prefix)\n  const modelsDevGateway = gateways.find(g => getGatewayId(g) === 'models.dev');\n  if (modelsDevGateway) {\n    return modelsDevGateway;\n  }\n\n  throw new MastraError({\n    id: 'MODEL_ROUTER_NO_GATEWAY_FOUND',\n    category: 'USER',\n    domain: 'MODEL_ROUTER',\n    text: `No Mastra model router gateway found for model id ${gatewayId}`,\n  });\n}\n","sourceCodeStart":35,"sourceCodeEnd":60,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/gateway-helpers.ts#L35-L60","documentation":"findGatewayForModel could not resolve any registered gateway capable of serving the given model id. After checking all gateways (and falling back to the models.dev provider registry), none matched, so the model-router throws a USER-category MastraError. This usually means the model id is malformed or its provider is unknown.","triggerScenarios":"Calling findGatewayForModel with a gatewayId/model id that no gateway claims: e.g. 'my-model' with no prefix matching any gateway, an unsupported provider prefix like 'unknown-provider/gpt-x', or the models.dev registry gateway not registered.","commonSituations":"Typo in the model id ('gtp-4o'); using a provider prefix that isn't registered; custom model ids not added to models.dev; forgetting to register the models.dev gateway.","solutions":["Correct the model id spelling and use a known prefix (openai/gpt-4o, anthropic/claude-...).","Register the models.dev gateway (or the specific provider gateway) with the model router.","If it's a custom model, add a provider config covering it or route it explicitly.","Check getGatewayId() matching logic: ensure the id's prefix corresponds to a registered gateway id."],"exampleFix":"// before\nrouter.findGatewayForModel('gpt-4o-custom'); // no gateway owns this id\n// after\nrouter.findGatewayForModel('openai/gpt-4o');\n// or register: new MastraModelRouter({ gateways: [new ModelsDevGateway(), ...] })","handlingStrategy":"validation","validationCode":"function hasKnownGatewayPrefix(modelId, gatewayIds) {\n  const prefix = modelId.split('/')[0];\n  return gatewayIds.includes(prefix) || gatewayIds.includes('models.dev');\n}\nif (!hasKnownGatewayPrefix('openai/gpt-4o', ['models.dev'])) throw new Error('No gateway registered for this model id prefix');","typeGuard":"function isRoutedModelId(id) { return typeof id === 'string' && /^[\\w.-]+\\/[\\w.:-]+$/.test(id); }","tryCatchPattern":"try {\n  const gw = findGatewayForModel(modelId);\n} catch (e) {\n  if (e.id === 'MODEL_ROUTER_NO_GATEWAY_FOUND') {\n    console.error(`Unknown model id '${modelId}'. Register a gateway or fix the provider prefix.`);\n    throw new UserInputError(e.message);\n  }\n  throw e;\n}","preventionTips":["Register the models.dev gateway so unprefixed/registry models resolve.","Use canonical 'provider/model' ids from docs, not bare model names.","Validate user-supplied model ids against a known list before routing.","Catch this USER-category error at API boundaries and return a 400-style message."],"tags":["model-router","configuration","gateway","invalid-input"],"backgroundTag":"unknown-model-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}