{"record":{"id":"360bf9627d16ea91","repo":"mastra-ai/mastra","slug":"invalid-model-configuration-provided","errorCode":null,"errorMessage":"Invalid model configuration provided","messagePattern":"Invalid model configuration provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/resolve-model.ts","lineNumber":141,"sourceCode":"    }\n    // Unknown specificationVersion from a third-party provider (e.g. ollama-ai-provider-v2).\n    // If the model has doStream/doGenerate methods, wrap it as a modern model\n    // to prevent the stream()/streamLegacy() catch-22 where neither method accepts the model.\n    if (typeof (modelConfig as any).doStream === 'function' && typeof (modelConfig as any).doGenerate === 'function') {\n      return new AISDKV5LanguageModel(modelConfig as unknown as LanguageModelV2);\n    }\n    return modelConfig as MastraLanguageModel;\n  }\n\n  const gatewayRecord = mastra?.listGateways();\n  const customGateways = gatewayRecord ? Object.values(gatewayRecord) : undefined;\n\n  // If it's a string (magic string like \"openai/gpt-4o\") or OpenAICompatibleConfig, create ModelRouterLanguageModel\n  if (typeof modelConfig === 'string' || isOpenAICompatibleObjectConfig(modelConfig)) {\n    return new ModelRouterLanguageModel(modelConfig, customGateways);\n  }\n\n  throw new Error('Invalid model configuration provided');\n}\n","sourceCodeStart":123,"sourceCodeEnd":143,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/resolve-model.ts#L123-L143","documentation":"resolveModelConfig accepts either a magic string (e.g. 'openai/gpt-4o') or an OpenAI-compatible config object and returns a ModelRouterLanguageModel; any other shape is unsupported and triggers this generic Error with no detail about what was received.","triggerScenarios":"Passing a model config that is neither a string nor an OpenAI-compatible object into resolveModelConfig — e.g. an arbitrary object, undefined from a bad lookup, a provider SDK client instance, or a malformed nested config.","commonSituations":"Config loaded from JSON/env where the model field is null/undefined; passing an OpenAI SDK client object instead of a string; refactors that changed the model config shape; forgetting to upgrade a legacy model object format.","solutions":["Pass a router string like 'openai/gpt-4o' or a valid OpenAICompatibleConfig object","Log/inspect the runtime modelConfig value — the error message does not include it","Check for undefined/null from config loaders before calling resolveModelConfig","Verify legacy model instances are migrated to the supported config shapes"],"exampleFix":"// before\nconst model = await loadConfig(); // could be undefined\nresolveModelConfig(model);\n// after\nconst cfg = await loadConfig();\nif (typeof cfg !== 'string' && !(cfg && typeof cfg === 'object' && 'url' in cfg)) {\n  throw new Error(`Unsupported model config: ${JSON.stringify(cfg)}`);\n}\nresolveModelConfig(cfg);","handlingStrategy":"type-guard","validationCode":"function isValidModelConfig(c: unknown): boolean {\n  return typeof c === 'string' || (typeof c === 'object' && c !== null && 'url' in c);\n}","typeGuard":"interface OpenAICompatibleConfig { url: string; [k: string]: unknown }\nfunction isOpenAICompatibleConfig(c: unknown): c is string | OpenAICompatibleConfig {\n  return typeof c === 'string' ||\n    (typeof c === 'object' && c !== null && typeof (c as any).url === 'string');\n}","tryCatchPattern":"try {\n  const model = resolveModelConfig(cfg as any);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid model configuration provided') {\n    console.error('Bad model config:', JSON.stringify(cfg));\n  }\n  throw e;\n}","preventionTips":["Validate model config at config-load time, before it reaches resolveModelConfig","Type config fields as string | OpenAICompatibleConfig so bad shapes fail compile-time","Handle undefined/null from env/config lookups with explicit defaults"],"tags":["configuration","model","invalid-argument","typescript"],"backgroundTag":"invalid-config-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}