{"record":{"id":"f2a5d47ab59ce371","repo":"Budibase/budibase","slug":"error-fetching-agent-log-detail-text-respons","errorCode":null,"errorMessage":"Error fetching agent log detail: ${text || response.statusText}","messagePattern":"Error fetching agent log detail: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agentLogs/liteLLM.ts","lineNumber":77,"sourceCode":"    ),\n    page: \"1\",\n    page_size: \"1\",\n  })\n  const response = await fetch(\n    `${liteLLMUrl}/spend/logs/v2?${params.toString()}`,\n    {\n      headers: {\n        Authorization: liteLLMAuthorizationHeader,\n      },\n    }\n  )\n\n  if (!response.ok) {\n    if (response.status === 404) {\n      return null\n    }\n    const text = await response.text()\n    throw new Error(\n      `Error fetching agent log detail: ${text || response.statusText}`\n    )\n  }\n\n  const data = (await response.json()) as LiteLLMRequestListResponse | null\n  return data?.data?.[0] || null\n}\n\nexport async function fetchLiteLLMSessionRows(\n  sessionId: string\n): Promise<{ rows: LiteLLMRequestRecord[]; total: number }> {\n  const pageSize = 100\n  const rows: LiteLLMRequestRecord[] = []\n  let page = 1\n  let total = 0\n  let totalPages = 1\n\n  while (page <= totalPages) {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentLogs/liteLLM.ts#L59-L95","documentation":"fetchLiteLLMRequestSummaryById calls the LiteLLM proxy /requests/{request_id} endpoint and throws this plain Error whenever the HTTP response is not ok and not 404 (404 is translated to a null return). The thrown message embeds the LiteLLM response body if present, otherwise the HTTP status text, so the text usually names the real upstream problem (auth, bad route, proxy down).","triggerScenarios":"Calling fetchLiteLLMRequestSummaryById (via requestDetail) when LiteLLM returns a non-ok, non-404 status: 401 from a missing/wrong LITELLM_MASTER_KEY or Virtual Key, 500 from LiteLLM's DB (Postgres) being unreachable, 502/503 from the proxy being down or AGENT_LITELLM_URL pointing at the wrong host/port.","commonSituations":"LiteLLM proxy not running or misconfigured env var for its base URL; expired/rotated LiteLLM API key; LiteLLM's backing Postgres down causing 500s; reverse proxy returning HTML error pages that appear in the message body.","solutions":["Verify LiteLLM proxy is reachable: curl $AGENT_LITELLM_URL/health and confirm LITELLM_MASTER_KEY / base URL env vars are correct","Check the response body in the error message for the actual LiteLLM error (e.g. invalid API key) and fix credentials","Confirm LiteLLM's Postgres database is up, since /requests queries spend logs stored there","Retry the request if the status was 502/503 indicating a transient proxy outage"],"exampleFix":"// before\nconst text = await response.text()\nthrow new Error(`Error fetching agent log detail: ${text || response.statusText}`)\n// after\nconst text = await response.text()\nconsole.error(`LiteLLM request summary fetch failed (status ${response.status}): ${text || response.statusText}`)\nthrow new HTTPError(`Error fetching agent log detail: ${text || response.statusText}`, response.status)","handlingStrategy":"try-catch","validationCode":"const base = process.env.AGENT_LITELLM_URL\nif (!base) throw new Error(\"AGENT_LITELLM_URL is not configured\")\nconst health = await fetch(`${base}/health`)\nif (!health.ok) throw new Error(`LiteLLM proxy unhealthy: ${health.status}`)","typeGuard":"function isOkResponse(res: Response): res is Response & { ok: true } {\n  return res.ok\n}","tryCatchPattern":"try {\n  const detail = await fetchLiteLLMRequestSummaryById(requestId)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 404) return null\n  console.error(\"LiteLLM summary fetch failed\", err)\n  throw new HTTPError(\"Agent log detail unavailable\", 502)\n}","preventionTips":["Health-check the LiteLLM proxy before relying on agent logs","Keep AGENT_LITELLM_URL and API key env vars in sync with the running proxy","Monitor LiteLLM's Postgres dependency","Treat 404 separately from other failures (the SDK already does)"],"tags":["network","http","litellm","agent-logs"],"backgroundTag":"upstream-http-error","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}