{"record":{"id":"a98bf8605a92b8a5","repo":"different-ai/openwork","slug":"endpoint-test-failed-response-status","errorCode":null,"errorMessage":"Endpoint test failed (${response.status}).","messagePattern":"Endpoint test failed \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/llm-provider-data.tsx","lineNumber":451,"sourceCode":"}\n\n/**\n * Probe an OpenAI-compatible endpoint through den-api: heals common URL\n * mistakes and returns the model ids the endpoint actually serves.\n */\nexport async function requestLlmProviderTestConnection(input: {\n  api: string;\n  apiKey?: string;\n  modelIds?: string[];\n}) {\n  const timeoutMs = input.modelIds?.length ? 60000 : 20000;\n  const { response, payload } = await requestJson(\n    `/v1/llm-providers/test-connection`,\n    { method: \"POST\", body: JSON.stringify(input) },\n    timeoutMs,\n  );\n  if (!response.ok) {\n    throw new Error(getErrorMessage(payload, `Endpoint test failed (${response.status}).`));\n  }\n  const result = isRecord(payload) ? asProbeResult(payload.result) : null;\n  if (!result) {\n    throw new Error(\"Endpoint test returned an unexpected response.\");\n  }\n  const verifications = isRecord(payload) && Array.isArray(payload.verifications)\n    ? payload.verifications\n        .map(asModelVerification)\n        .filter((entry): entry is LlmProviderModelVerification => entry !== null)\n    : [];\n  return { ...result, verifications };\n}\n\nexport async function requestLlmProviderCatalog(orgId: string) {\n  const { response, payload } = await requestJson(`/v1/llm-provider-catalog`, { method: \"GET\" }, 20000);\n  if (!response.ok) {\n    throw new Error(getErrorMessage(payload, `Failed to load the provider catalog (${response.status}).`));\n  }","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/llm-provider-data.tsx#L433-L469","documentation":"requestLlmProviderTestConnection posts to /v1/llm-providers/test-connection; if the HTTP response is not ok it throws with a server-provided message or the embedded status. This reports that the endpoint-test API call itself failed (as opposed to the tested endpoint failing its probe).","triggerScenarios":"POST /v1/llm-providers/test-connection returns non-2xx: 400 (invalid input body), 401/403 (session/permission issues), 404 (route absent on the server), 408/504 (timeout via proxy), 5xx (backend crash during probe).","commonSituations":"Testing a provider with a malformed API key/URL submitted in the form; user lacks admin rights in the org; frontend deployed against a server that lacks the test-connection route; long provider handshakes hitting the requestJson timeoutMs.","solutions":["Read response.status and the server message to distinguish 400 vs 401/403 vs 5xx.","Validate the form input (baseUrl, apiKey format) before submitting the test request.","Confirm the den-api server version implements /v1/llm-providers/test-connection.","Increase timeoutMs if the tested endpoint is legitimately slow, or check for proxy timeouts.","Check server logs for the failing probe to find the underlying cause."],"exampleFix":"// before\nthrow new Error(getErrorMessage(payload, `Endpoint test failed (${response.status}).`));\n// after (surface status-specific guidance)\nconst detail = getErrorMessage(payload, `Endpoint test failed (${response.status}).`);\nif (response.status === 401) throw new Error(\"Session expired — sign in again before testing endpoints.\");\nthrow new Error(detail);","handlingStrategy":"try-catch","validationCode":"// validate before calling\nfunction canSubmitTest(input: { baseUrl: string; apiKey: string }): boolean {\n  try { new URL(input.baseUrl); } catch { return false; }\n  return input.apiKey.length > 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await requestLlmProviderTestConnection(input, 20000);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.includes(\"(401)\")) promptReauth();\n  else if (msg.includes(\"(400)\")) showFormError(\"Check the base URL and API key.\");\n  else showFormError(msg);\n}","preventionTips":["Validate provider form fields (URL format, key presence) client-side before POSTing.","Keep timeoutMs generous but bounded; surface timeout errors distinctly.","Gate the test button behind the org permissions that the endpoint requires.","Confirm server version implements /v1/llm-providers/test-connection before rollout."],"tags":["network","http-status","llm-provider","den-web"],"backgroundTag":"endpoint-test-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}