{"record":{"id":"fe18bcf2ba26019f","repo":"mastra-ai/mastra","slug":"netlify-gateway-no-site-id","errorCode":"NETLIFY_GATEWAY_NO_SITE_ID","errorMessage":"Missing NETLIFY_SITE_ID environment variable required for model: ${routerId}","messagePattern":"Missing NETLIFY_SITE_ID environment variable required for model: (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/netlify.ts","lineNumber":81,"sourceCode":"    return { netlify: config };\n  }\n\n  async buildUrl(routerId: string, envVars?: typeof process.env): Promise<string> {\n    // Check for Netlify site ID first (for token exchange)\n    const siteId = envVars?.['NETLIFY_SITE_ID'] || process.env['NETLIFY_SITE_ID'];\n    const netlifyToken = envVars?.['NETLIFY_TOKEN'] || process.env['NETLIFY_TOKEN'];\n\n    if (!netlifyToken) {\n      throw new MastraError({\n        id: 'NETLIFY_GATEWAY_NO_TOKEN',\n        domain: 'LLM',\n        category: 'UNKNOWN',\n        text: `Missing NETLIFY_TOKEN environment variable required for model: ${routerId}`,\n      });\n    }\n\n    if (!siteId) {\n      throw new MastraError({\n        id: 'NETLIFY_GATEWAY_NO_SITE_ID',\n        domain: 'LLM',\n        category: 'UNKNOWN',\n        text: `Missing NETLIFY_SITE_ID environment variable required for model: ${routerId}`,\n      });\n    }\n\n    try {\n      const tokenData = await this.getOrFetchToken(siteId, netlifyToken);\n      return tokenData.url.endsWith(`/`) ? tokenData.url.substring(0, tokenData.url.length - 1) : tokenData.url;\n    } catch (error) {\n      throw new MastraError({\n        id: 'NETLIFY_GATEWAY_TOKEN_ERROR',\n        domain: 'LLM',\n        category: 'UNKNOWN',\n        text: `Failed to get Netlify AI Gateway token for model ${routerId}: ${error instanceof Error ? error.message : String(error)}`,\n      });\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/netlify.ts#L63-L99","documentation":"The Netlify AI Gateway requires both a NETLIFY_TOKEN and a NETLIFY_SITE_ID environment variable to route model requests. This library throws NETLIFY_GATEWAY_NO_SITE_ID from buildUrl when a model routed through the Netlify gateway is used but the site ID is missing, because it cannot construct the gateway URL without it.","triggerScenarios":"Using a model with the netlify gateway (routerId prefixed for Netlify) while process.env.NETLIFY_SITE_ID is unset or empty when buildUrl is invoked (via baseURL).","commonSituations":"Deployed or local environments where NETLIFY_TOKEN is set but NETLIFY_SITE_ID was never exported; renamed/typo'd env var (NETLIFY_SITEID); using the gateway in CI without configuring secrets.","solutions":["Set the NETLIFY_SITE_ID environment variable to your Netlify site ID (netlify sites:list or the site dashboard)","Verify the variable is present in the runtime environment (dotenv loaded, CI secrets configured) before constructing the model","Confirm you actually intend to use the Netlify gateway; otherwise use a direct provider model config"],"exampleFix":"// before\nnew ModelRouterLanguageModel('netlify/openai/gpt-4o'); // NETLIFY_SITE_ID unset\n// after\nprocess.env.NETLIFY_SITE_ID = 'your-site-id';\nprocess.env.NETLIFY_TOKEN = 'your-netlify-token';\nnew ModelRouterLanguageModel('netlify/openai/gpt-4o');","handlingStrategy":"validation","validationCode":"if (!process.env.NETLIFY_SITE_ID) {\n  throw new Error('NETLIFY_SITE_ID must be set before using a Netlify gateway model');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const model = new ModelRouterLanguageModel('netlify/openai/gpt-4o');\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'NETLIFY_GATEWAY_NO_SITE_ID') {\n    console.error('Set NETLIFY_SITE_ID (and NETLIFY_TOKEN) in your environment');\n  }\n  throw e;\n}","preventionTips":["Load .env at process startup before any model construction","Validate required env vars with a startup checklist (fail fast at boot, not per-request)","Keep NETLIFY_TOKEN and NETLIFY_SITE_ID configured together as one secret group in CI/CD"],"tags":["env-var","netlify","configuration","gateway"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}