{"record":{"id":"6ee78ca5aa335eab","repo":"mastra-ai/mastra","slug":"failed-to-fetch-copilot-models-response-status","errorCode":null,"errorMessage":"Failed to fetch Copilot models: ${response.status} ${response.statusText}: ${text}","messagePattern":"Failed to fetch Copilot models: (.+?) (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/auth/providers/github-copilot.ts","lineNumber":478,"sourceCode":" */\nexport async function fetchCopilotModels(opts: {\n  baseUrl: string;\n  bearerToken: string;\n  signal?: AbortSignal;\n}): Promise<CopilotModelEntry[]> {\n  const url = `${opts.baseUrl.replace(/\\/$/, '')}/models`;\n  const response = await fetch(url, {\n    headers: {\n      Accept: 'application/json',\n      Authorization: `Bearer ${opts.bearerToken}`,\n      ...COPILOT_HEADERS,\n    },\n    signal: opts.signal,\n  });\n\n  if (!response.ok) {\n    const text = await response.text().catch(() => '');\n    throw new Error(`Failed to fetch Copilot models: ${response.status} ${response.statusText}: ${text}`);\n  }\n\n  const json = await response.json().catch(() => null);\n  if (!json || typeof json !== 'object' || !Array.isArray((json as { data?: unknown }).data)) {\n    throw new Error('Invalid Copilot models response: missing `data` array');\n  }\n\n  const data = (json as { data: unknown[] }).data;\n  const result: CopilotModelEntry[] = [];\n\n  for (const item of data) {\n    if (!item || typeof item !== 'object') continue;\n    const obj = item as Record<string, unknown>;\n\n    if (obj.model_picker_enabled !== true) continue;\n\n    const policy = obj.policy as Record<string, unknown> | undefined;\n    if (policy && policy.state === 'disabled') continue;","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/auth/providers/github-copilot.ts#L460-L496","documentation":"fetchCopilotModels calls the GitHub Copilot models API (the /models endpoint) and, when the HTTP response is not ok, includes the status, statusText, and response body text in this error. It surfaces upstream API failures (auth token problems, wrong endpoint, rate limits, server errors) to the caller.","triggerScenarios":"The Copilot API returns a non-2xx status: expired/invalid Copilot token (401), missing Copilot subscription/entitlement (403), wrong API base URL or enterprise domain, or 5xx outages. Called via provider.models() with valid stored credentials otherwise.","commonSituations":"Token expired after long idle; account lost Copilot access; self-hosted proxy or enterprise domain misconfigured; GitHub API incident/rate limit; network path through a corporate proxy returning HTML error pages.","solutions":["Read the embedded status/body: 401 → re-run login() to refresh the Copilot token; 403 → verify your account has an active Copilot subscription","Retry after checking https://www.githubstatus.com if the status is 5xx","Verify the API base URL / enterprise domain configuration used by the provider","Check corporate proxy/VPN interference with api.github.com / api.individual.githubcopilot.com"],"exampleFix":"// before\nconst models = await provider.models(); // throws on stale token\n// after\nlet models;\ntry {\n  models = await provider.models();\n} catch (err) {\n  if (String(err.message).includes('401')) await login('github-copilot');\n  models = await provider.models();\n}","handlingStrategy":"retry","validationCode":"// Pre-flight: verify credentials are present and fresh before calling models()\nconst creds = await loadCredentials();\nif (!creds || creds.expires <= Date.now()) {\n  await login('github-copilot'); // refresh before hitting the models API\n}","typeGuard":"function isModelsHttpError(err: unknown): err is Error & { status?: number } {\n  const m = err instanceof Error ? err.message.match(/Failed to fetch Copilot models: (\\d{3})/) : null;\n  return m !== null;\n}","tryCatchPattern":"try {\n  models = await provider.models({ signal });\n} catch (err) {\n  const m = err instanceof Error && err.message.match(/Failed to fetch Copilot models: (\\d{3})/);\n  if (m && (m[1] === '429' || m[1].startsWith('5'))) {\n    await backoff(); models = await provider.models({ signal }); // retry transient failures\n  } else if (m && m[1] === '401') {\n    await login('github-copilot'); models = await provider.models({ signal });\n  } else throw err;\n}","preventionTips":["Refresh the Copilot token before it expires instead of letting requests 401","Confirm the account has an active Copilot subscription before calling models()","Watch githubstatus.com and retry 5xx with exponential backoff","Test with proxies/VPN disabled to rule out middleboxes"],"tags":["network","http","api","github-copilot"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}