{"record":{"id":"82bb79526aea6373","repo":"mastra-ai/mastra","slug":"could-not-find-config-for-provider-provider-wit","errorCode":null,"errorMessage":"Could not find config for provider ${provider} with model id ${modelId}","messagePattern":"Could not find config for provider (.+?) with model id (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/models-dev.ts","lineNumber":318,"sourceCode":"      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({\n    modelId,\n    providerId,\n    apiKey,\n    headers,\n  }: {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/models-dev.ts#L300-L336","documentation":"The model id parsed to a provider segment that has no entry in providerConfigs — the models.dev registry either wasn't fetched/synced, or the provider isn't in models.dev. The gateway can't determine which env var holds the API key, so it throws. Related to but distinct from 1378: here the id format is valid, but the provider is unknown.","triggerScenarios":"getApiKey('someprovider/some-model') where this.providerConfigs['someprovider'] is undefined — registry not yet synced (fetchProviders not called/failed), provider missing from models.dev, or a custom provider not injected via providerConfigs.","commonSituations":"Calling getApiKey before fetchProviders(); typo'd provider prefix ('oepnai/...'); niche or brand-new provider not yet in models.dev; custom/self-hosted providers without a provided config; 1377's fetch failed leaving configs empty.","solutions":["Ensure fetchProviders() ran successfully before resolving API keys (or the gateway auto-syncs at startup).","Fix the provider prefix spelling in the model id.","Inject a ProviderConfig for custom providers via the providerConfigs constructor option.","Check for an accompanying 1377 error — a failed registry fetch leaves providerConfigs empty."],"exampleFix":"// before\nawait gw.getApiKey('oepnai/gpt-4o'); // typo provider\n// after\nawait gw.getApiKey('openai/gpt-4o');\n// or for custom providers:\nnew ModelsDevGateway({ providerConfigs: { myprovider: { apiKeyEnvVar: 'MY_KEY', npm: '...', url: '...' } } })","handlingStrategy":"try-catch","validationCode":"const [provider] = id.split('/');\nif (gw.providerConfigs && !gw.providerConfigs[provider]) {\n  throw new Error(`Provider '${provider}' not in registry — check spelling or inject a providerConfig`);\n}","typeGuard":"function isKnownProvider(modelId, configs) {\n  const [provider] = modelId.split('/');\n  return Boolean(configs && Object.prototype.hasOwnProperty.call(configs, provider));\n}","tryCatchPattern":"try {\n  const key = await gw.getApiKey(modelId);\n} catch (e) {\n  if (/Could not find config for provider/.test(e.message)) {\n    const [provider] = modelId.split('/');\n    throw new Error(`Unknown provider '${provider}'. Sync models.dev registry or add a custom providerConfig.`);\n  }\n  throw e;\n}","preventionTips":["Ensure fetchProviders() completes (and succeeded) before resolving keys.","Catch and treat 1377 failures as fatal during startup so providerConfigs is never silently empty.","Inject providerConfigs for custom/self-hosted providers.","Keep provider prefixes consistent with models.dev naming; lint user configs for common typos."],"tags":["models-dev","configuration","provider","model-id"],"backgroundTag":"unknown-model-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}