{"record":{"id":"7d70b723d5651834","repo":"Budibase/budibase","slug":"error-fetching-agent-session-detail-text-res","errorCode":null,"errorMessage":"Error fetching agent session detail: ${text || response.statusText}","messagePattern":"Error fetching agent session detail: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agentLogs/liteLLM.ts","lineNumber":116,"sourceCode":"      page: String(page),\n      page_size: String(pageSize),\n    })\n    const response = await fetch(\n      `${liteLLMUrl}/spend/logs/session/ui?${params.toString()}`,\n      {\n        headers: {\n          Authorization: liteLLMAuthorizationHeader,\n        },\n      }\n    )\n\n    if (response.status === 404) {\n      return { rows: [], total: 0 }\n    }\n\n    if (!response.ok) {\n      const text = await response.text()\n      throw new Error(\n        `Error fetching agent session detail: ${text || response.statusText}`\n      )\n    }\n\n    const data = (await response.json()) as LiteLLMRequestListResponse\n    rows.push(...(data.data || []))\n    total = data.total || total || rows.length\n    totalPages = data.total_pages || 1\n    page += 1\n  }\n\n  return { rows, total }\n}\n\nasync function fetchLiteLLMRequestPayloadById(\n  requestId: string\n): Promise<LiteLLMRequestPayload | null> {\n  const response = await fetch(","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentLogs/liteLLM.ts#L98-L134","documentation":"fetchLiteLLMSessionRows pages through LiteLLM's /requests endpoint for a session and throws this Error when any page returns a non-ok, non-404 status. 404 is treated as an empty result set ({rows: [], total: 0}); any other failure aborts session detail assembly with the LiteLLM error body in the message.","triggerScenarios":"Calling fetchLiteLLMSessionRows (via session detail endpoints) when LiteLLM returns e.g. 401 Unauthorized due to a bad key, 500 because LiteLLM's spend-log database is unavailable, or 502 when the proxy is down mid-pagination.","commonSituations":"LITELLM key rotated but server not restarted; LiteLLM proxy container crashed; firewall/DNS change making AGENT_LITELLM_BASE_URL unreachable; LiteLLM version upgrade changing the /requests route shape.","solutions":["Confirm the LiteLLM base URL and API key env vars match the running proxy; restart the server after key changes","Check LiteLLM logs / its Postgres DB health when the body shows an internal error","Test the exact /requests route manually with curl using the same auth header to see the real upstream message","Add retry logic for transient 5xx statuses before surfacing the error"],"exampleFix":"// before\nthrow new Error(`Error fetching agent session detail: ${text || response.statusText}`)\n// after\nconst err = new Error(`Error fetching agent session detail: ${text || response.statusText}`)\n;(err as any).status = response.status\nthrow err","handlingStrategy":"retry","validationCode":"const res = await fetch(`${base}/requests?session_id=${sessionId}`, { headers: { Authorization: `Bearer ${key}` } })\nif (res.status === 401) throw new Error(\"LiteLLM authentication failed\")","typeGuard":null,"tryCatchPattern":"try {\n  const session = await getSessionDetail(sessionId)\n} catch (err) {\n  console.error(\"Session detail fetch failed\", err)\n  return { rows: [], total: 0 }\n}","preventionTips":["Restart the server after rotating LiteLLM keys","Add retry-with-backoff for 5xx responses during pagination","Alert on LiteLLM proxy downtime","Pin/verify LiteLLM route compatibility after upgrades"],"tags":["network","http","litellm","pagination"],"backgroundTag":"upstream-http-error","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}