{"record":{"id":"d2aeea3a55663d30","repo":"mastra-ai/mastra","slug":"models-dev-returned-response-status","errorCode":null,"errorMessage":"models.dev returned ${response.status}","messagePattern":"models\\.dev returned (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/providers/amazon-bedrock.ts","lineNumber":52,"sourceCode":"interface CatalogCacheEntry {\n  fetchedAt: number;\n  ttl: number;\n  models: BedrockModelEntry[];\n}\n\nlet catalogCache: CatalogCacheEntry | null = null;\nlet inflightFetch: Promise<BedrockModelEntry[]> | null = null;\n\n/** Reset the in-process Bedrock catalog cache (test seam). */\nexport function clearBedrockCatalogCache(): void {\n  catalogCache = null;\n  inflightFetch = null;\n}\n\nasync function fetchBedrockModels(signal: AbortSignal): Promise<BedrockModelEntry[]> {\n  const response = await fetch(MODELS_DEV_API_URL, { signal });\n  if (!response.ok) {\n    throw new Error(`models.dev returned ${response.status}`);\n  }\n  const data = (await response.json()) as Record<string, { models?: Record<string, unknown> }>;\n  const provider = data[BEDROCK_PROVIDER_ID];\n  const models = provider?.models ?? {};\n  return Object.keys(models)\n    .sort()\n    .map(id => ({ id }));\n}\n\n/**\n * Return the available Amazon Bedrock models.\n *\n * - Returns the cached list when a recent fetch succeeded.\n * - On cache miss / expiry, fetches the models.dev catalog with a 5s timeout and\n *   caches it for an hour.\n * - On fetch failure, returns a small hard-coded fallback (so packs still work\n *   offline) and caches that briefly to avoid hammering the network.\n *","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/providers/amazon-bedrock.ts#L34-L70","documentation":"fetchBedrockModels queries the models.dev API to enumerate available Amazon Bedrock models. When the HTTP response status is not ok (4xx/5xx), the function throws this generic error embedding the numeric status. It is a fail-fast guard against parsing garbage from a failed catalog request.","triggerScenarios":"Calling `models` (which calls fetchBedrockModels) when the models.dev endpoint returns a non-2xx status: 404 (API path changed), 429 (rate limited), 5xx (service outage), or a proxy/firewall blocking the request.","commonSituations":"Corporate proxies or firewalls returning 403/502 for external APIs; models.dev being temporarily down or rate-limiting; offline or air-gapped environments where a captive portal returns an HTML error page with 4xx/5xx; DNS hijacking to an error page.","solutions":["Check network connectivity and retry, since 5xx/429 are usually transient","Inspect the status code in the message: 403/401 means a proxy or firewall is intercepting the request","Verify MODELS_DEV_API_URL is reachable (curl it directly) and the API has not moved","Pin a fallback/offline model list or cache the last successful response for offline use"],"exampleFix":"// before\nconst models = await sdk.models();\n// after\nlet models;\ntry {\n  models = await sdk.models();\n} catch (err) {\n  if ((err as Error).message.startsWith('models.dev returned')) {\n    models = FALLBACK_BEDROCK_MODELS; // cached/known list\n  } else throw err;\n}","handlingStrategy":"fallback","validationCode":"const res = await fetch(MODELS_DEV_API_URL);\nif (!res.ok) throw new Error(`models.dev unreachable: ${res.status}`);","typeGuard":"null","tryCatchPattern":"try {\n  models = await sdk.models();\n} catch (err) {\n  if (err instanceof Error && /models\\.dev returned \\d+/.test(err.message)) {\n    models = CACHED_MODELS; // or rethrow with context\n  } else throw err;\n}","preventionTips":["Cache the last successful models.dev response for offline/failure fallback","Check the status code embedded in the message to distinguish transient (5xx/429) from permanent (404) failures","Add a timeout via AbortSignal so a hung request fails fast","Alert on repeated models.dev failures in production"],"tags":["network","http","api-outage"],"backgroundTag":"upstream-http-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}