{"record":{"id":"ea5601d4ab4ebcb2","repo":"mastra-ai/mastra","slug":"could-not-identify-provider-from-model-id-modeli","errorCode":null,"errorMessage":"Could not identify provider from model id ${modelId}","messagePattern":"Could not identify provider from model id (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/models-dev.ts","lineNumber":313,"sourceCode":"    // provider default; prefer it when present.\n    const perModelApi = config?.modelOverrides?.[modelId]?.api;\n    const template = perModelApi ?? config?.url;\n\n    if (!template) {\n      return;\n    }\n\n    // Check for custom base URL from env vars (explicit override still wins)\n    const baseUrlEnvVar = `${providerId.toUpperCase().replace(/-/g, '_')}_BASE_URL`;\n    const customBaseUrl = envVars?.[baseUrlEnvVar] || process.env[baseUrlEnvVar];\n\n    return customBaseUrl || interpolateUrlTemplate(template, envVars);\n  }\n\n  getApiKey(modelId: string): Promise<string> {\n    const [provider, model] = modelId.split('/');\n    if (!provider || !model) {\n      throw new Error(`Could not identify provider from model id ${modelId}`);\n    }\n    const config = this.providerConfigs[provider];\n\n    if (!config) {\n      throw new Error(`Could not find config for provider ${provider} with model id ${modelId}`);\n    }\n\n    const apiKey = resolveApiKeyFromEnv(config.apiKeyEnvVar);\n\n    if (!apiKey) {\n      const envVarDisplay = Array.isArray(config.apiKeyEnvVar) ? config.apiKeyEnvVar.join(' or ') : config.apiKeyEnvVar;\n      throw new Error(`Could not find API key process.env.${envVarDisplay} for model id ${modelId}`);\n    }\n\n    return Promise.resolve(apiKey);\n  }\n\n  async resolveLanguageModel({","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/models-dev.ts#L295-L331","documentation":"getApiKey parses the model id as 'provider/model'; if either part is missing after splitting on '/', the provider cannot be determined and a plain Error is thrown. The models.dev gateway keys its provider configs by the id prefix, so a malformed id is unusable.","triggerScenarios":"Calling getApiKey with ids like 'gpt-4o' (no slash), 'openai/' (empty model), '/gpt-4o' (empty provider), or ids containing extra text where the split yields an empty segment.","commonSituations":"Users passing bare model names from OpenAI SDK habits instead of 'openai/gpt-4o'; building ids programmatically with undefined segments; copying ids from other tools with different id formats.","solutions":["Pass the full router-style id: 'provider/model' (e.g. 'openai/gpt-4o').","Validate the id contains a non-empty provider and model segment before calling.","Normalize programmatic id construction to guard against undefined segments."],"exampleFix":"// before\nawait gw.getApiKey('gpt-4o');\n// after\nawait gw.getApiKey('openai/gpt-4o');","handlingStrategy":"validation","validationCode":"function parseModelId(modelId) {\n  const [provider, model] = modelId.split('/');\n  if (!provider || !model) throw new Error(`Model id must be 'provider/model', got: ${modelId}`);\n  return { provider, model };\n}\nparseModelId(id); // call before getApiKey","typeGuard":"function isValidModelId(id) { return typeof id === 'string' && /^[^/]+\\/[^/]+$/.test(id); }","tryCatchPattern":null,"preventionTips":["Always use router-style ids: 'provider/model'.","Normalize/trim ids coming from user input or other SDKs.","Add form validation rejecting ids without a '/' or with empty segments.","Write a unit test for id parsing with edge cases."],"tags":["models-dev","invalid-input","model-id","gateway"],"backgroundTag":"unknown-model-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}