{"record":{"id":"59279b648fc8d61d","repo":"mastra-ai/mastra","slug":"no-api-url-found-for-providerid-modelid","errorCode":null,"errorMessage":"No API URL found for ${providerId}/${modelId}","messagePattern":"No API URL found for (.+?)/(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/models-dev.ts","lineNumber":387,"sourceCode":"        ) as unknown as GatewayLanguageModel;\n      case 'xai':\n        return createXai({ apiKey, baseURL, headers: mastraHeaders }).responses(modelId);\n      case 'deepseek':\n        return createDeepSeek({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'perplexity':\n        return createPerplexity({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'cerebras':\n        return createCerebras({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'togetherai':\n        return createTogetherAI({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'deepinfra':\n        return createDeepInfra({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'vercel':\n        return createGateway({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      case 'moonshotai':\n      case 'moonshotai-cn': {\n        // moonshotai uses Anthropic-compatible API endpoint\n        if (!baseURL) throw new Error(`No API URL found for ${providerId}/${modelId}`);\n        return createAnthropic({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n      }\n      default: {\n        // Check if this provider uses a specific SDK package (e.g., kimi-for-coding uses @ai-sdk/anthropic).\n        // A per-model override wins over the provider default.\n        const config = this.providerConfigs[providerId];\n        const npm = override?.npm ?? config?.npm;\n\n        // Pattern match for any alibaba variant (alibaba, alibaba-cn, alibaba-coding-plan, etc.)\n        if (providerId.includes('alibaba')) {\n          if (!baseURL) throw new Error(`No API URL found for ${providerId}/${modelId}`);\n          return createAlibaba({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n        }\n\n        if (npm === '@ai-sdk/anthropic') {\n          if (!baseURL) throw new Error(`No API URL found for ${providerId}/${modelId}`);\n          return createAnthropic({ apiKey, baseURL, headers: mastraHeaders })(modelId);\n        }","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/models-dev.ts#L369-L405","documentation":"In resolveLanguageModel, the moonshotai and moonshotai-cn providers are routed through the Anthropic-compatible SDK, which requires an explicit baseURL (Moonshot's Anthropic-compatible endpoint). If buildUrl produced no baseURL (no provider URL template result and no <PROVIDER>_BASE_URL env override), this error is thrown instead of creating a misconfigured provider.","triggerScenarios":"Resolving a model like 'moonshotai/kimi-k2...' or 'moonshotai-cn/...' via the models-dev gateway when neither the provider's URL template resolves (e.g. its env-interpolated template has a missing env var) nor MOONSHOTAI_BASE_URL / MOONSHOTAI_CN_BASE_URL is set.","commonSituations":"Relying on a models.dev URL template that depends on an env var you haven't set; pinning a custom MOONSHOTAI_BASE_URL that is empty string; a registry/config update where the provider lost its default URL; self-hosted or proxied Moonshot setups where the default template doesn't apply.","solutions":["Set the provider base URL env var, e.g. process.env.MOONSHOTAI_BASE_URL='https://api.moonshot.ai/anthropic' (or the CN endpoint for moonshotai-cn), before model resolution.","Check that any env var the provider's URL template interpolates is actually set (the template silently yields no URL when a placeholder is missing).","If using a custom gateway/provider registration, supply a default baseURL in the provider config so buildUrl always resolves.","Verify the model id/provider id spelling — an unrecognized provider may fall into the config-less path with no URL."],"exampleFix":"// before\nconst agent = new Agent({ model: 'moonshotai/kimi-k2-0711-preview' });\n// after\nprocess.env.MOONSHOTAI_BASE_URL ??= 'https://api.moonshot.ai/anthropic';\nconst agent = new Agent({ model: 'moonshotai/kimi-k2-0711-preview' });","handlingStrategy":"validation","validationCode":"for (const v of ['MOONSHOTAI_BASE_URL']) {\n  if (!process.env[v]) throw new Error(`${v} must be set for moonshotai models`);\n}","typeGuard":"function hasBaseUrl(providerId: string, env: NodeJS.ProcessEnv = process.env): boolean {\n  const key = `${providerId.toUpperCase().replace(/-/g, '_')}_BASE_URL`;\n  return typeof env[key] === 'string' && env[key]!.length > 0;\n}","tryCatchPattern":"try {\n  const model = await gateway.resolveLanguageModel({ modelId, providerId: 'moonshotai', apiKey });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No API URL found')) {\n    console.error('Set MOONSHOTAI_BASE_URL before resolving moonshotai models');\n  }\n  throw e;\n}","preventionTips":["Set a sensible default base URL for Anthropic-compatible providers (MOONSHOTAI_BASE_URL) in your config/bootstrap.","Never set provider *_BASE_URL vars to empty strings — empty is treated as missing.","Document required env vars per provider in .env.example and README.","Smoke-test model resolution at boot (resolve one model per provider) to fail fast."],"tags":["configuration","base-url","moonshot","model-gateway"],"backgroundTag":"missing-base-url","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}