{"record":{"id":"0b58843486ad9bf4","repo":"mastra-ai/mastra","slug":"invalid-copilot-models-response-missing-data-ar","errorCode":null,"errorMessage":"Invalid Copilot models response: missing `data` array","messagePattern":"Invalid Copilot models response: missing `data` array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/auth/providers/github-copilot.ts","lineNumber":483,"sourceCode":"}): 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;\n\n    const id = obj.id;\n    if (typeof id !== 'string' || !id) continue;\n\n    const name = typeof obj.name === 'string' ? obj.name : id;","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/auth/providers/github-copilot.ts#L465-L501","documentation":"After a successful HTTP response, fetchCopilotModels parses the JSON and validates that it has a `data` array per the models API contract. If the body is missing, is not an object, or `data` is not an array, the library throws this contract-validation error rather than iterating over malformed data.","triggerScenarios":"The models endpoint returns 2xx with an unexpected body: an HTML login/proxy page, an error JSON without `data` (e.g. {message: ...} from a gateway), or an API version change that renamed/moved the `data` field.","commonSituations":"Corporate proxy or captive portal returning 200 with HTML; a reverse proxy intercepting the request; GitHub changing the Copilot models API shape; pointing the provider at a non-Copilot endpoint.","solutions":["Log/inspect the raw response body to see what was actually returned (proxy pages and error JSON are common culprits)","Verify the request targets the official Copilot models endpoint, not a proxy or wrong base URL","Bypass proxies/VPNs and retry to rule out interception","If GitHub changed the API shape, update the SDK/provider version"],"exampleFix":"// before (proxy returns 200 + HTML)\nbaseURL: 'http://proxy.internal/github'\n// after\nbaseURL: 'https://api.individual.githubcopilot.com'","handlingStrategy":"type-guard","validationCode":"// Pre-flight probe: fetch and validate the shape yourself before trusting the provider\nconst res = await fetch(modelsUrl, { headers, signal });\nconst ct = res.headers.get('content-type') ?? '';\nif (!ct.includes('application/json')) {\n  throw new Error(`Unexpected content-type from models endpoint: ${ct} (proxy interception?)`);\n}","typeGuard":"function hasDataArray(json: unknown): json is { data: unknown[] } {\n  return typeof json === 'object' && json !== null && Array.isArray((json as { data?: unknown }).data);\n}","tryCatchPattern":"try {\n  models = await provider.models();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('missing `data` array')) {\n    // 2xx but wrong shape: log body, check for proxy/captive-portal interference\n    console.error('Copilot models endpoint returned a non-contract payload; bypass proxy and retry.');\n  } else throw err;\n}","preventionTips":["Ensure no proxy/captive portal can return 200 HTML pages for API hosts","Pin/verify the correct Copilot models endpoint URL in configuration","Log raw response bodies on contract errors to detect interception early","Keep the SDK updated for Copilot API shape changes"],"tags":["network","api","schema-validation","response-parsing","github-copilot"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}