{"record":{"id":"19cfcc97804b3dc1","repo":"Budibase/budibase","slug":"file-id-not-found-19cfcc","errorCode":null,"errorMessage":"File id not found","messagePattern":"File id not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/llm/litellm.ts","lineNumber":240,"sourceCode":"  formdata.append(\"file\", fileBlob, filename)\n  formdata.append(\"model\", model)\n  const requestOptions = {\n    method: \"POST\",\n    headers: {\n      Authorization: liteLLMAuthorizationHeader,\n    },\n    body: formdata,\n  }\n\n  try {\n    const res = await fetch(\n      `${environment.LITELLM_URL}/v1/files`,\n      requestOptions\n    )\n\n    const json = await res.json()\n    if (typeof json.id !== \"string\") {\n      throw new Error(\"File id not found\")\n    }\n    return unwrapLiteLLMFileId(json.id)\n  } catch (e) {\n    console.error(\"Error uploading file to LiteLLM\", e)\n    throw e\n  }\n}\n\nexport function unwrapLiteLLMFileId(fileId: string): string {\n  if (!fileId.startsWith(\"file-\")) {\n    return fileId\n  }\n\n  const encodedPart = fileId.slice(\"file-\".length)\n  try {\n    const decoded = Buffer.from(encodedPart, \"base64\").toString(\"utf8\")\n    const match = decoded.match(/^litellm:(file-[^;]+);/)\n    if (match?.[1]) {","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/llm/litellm.ts#L222-L258","documentation":"Thrown in uploadFile when the LiteLLM /v1/files response JSON lacks a string `id`. The raw error is logged with console.error before being rethrown. This mirrors error 543 but for the direct LiteLLM client path rather than the BBAI client path.","triggerScenarios":"Uploading a file to LiteLLM (fileId flow) when LiteLLM returns a JSON body without `id` — provider upstream errors wrapped in a 200 response, LiteLLM version without compatible files API, or a proxy/gateway intercepting the upload.","commonSituations":"LiteLLM proxy misrouting /v1/files to an unsupported provider; older LiteLLM deployments; oversized files rejected upstream with an error JSON instead of an HTTP error status.","solutions":["Inspect the logged \"Error uploading file to LiteLLM\" output for the actual response payload","Upgrade the LiteLLM proxy to a version supporting OpenAI-compatible /v1/files for your target provider","Verify the file meets the provider's size/type limits and retry with a smaller file","Check the provider configured in LiteLLM for the model actually supports file inputs"],"exampleFix":"// before: silent shape failure\nconst json = await res.json()\nif (typeof json.id !== \"string\") {\n  throw new Error(\"File id not found\")\n}\n// after: include payload for diagnosis\nif (typeof json.id !== \"string\") {\n  throw new Error(`LiteLLM file upload returned no id: ${JSON.stringify(json).slice(0, 500)}`)\n}","handlingStrategy":"type-guard","validationCode":"const res = await fetch(`${env.LITELLM_URL}/v1/files`, requestOptions)\nconst json = await res.json()\nif (typeof json?.id !== \"string\") {\n  throw new Error(`LiteLLM upload failed: ${JSON.stringify(json).slice(0, 300)}`)\n}","typeGuard":"function isFileUploadResponse(x: unknown): x is { id: string } {\n  return typeof x === \"object\" && x !== null && typeof (x as { id?: unknown }).id === \"string\"\n}","tryCatchPattern":"try {\n  const id = await uploadFile(blob, purpose)\n} catch (e) {\n  if (e.message === \"File id not found\") {\n    // logged upstream; fall back or surface provider limit error\n    return { error: \"File could not be uploaded to LiteLLM\" }\n  }\n  throw e\n}","preventionTips":["Keep the LiteLLM proxy upgraded to a version supporting /v1/files for your providers","Enforce provider file size/type limits before upload","Add an upload smoke test to CI against your LiteLLM deployment"],"tags":["litellm","file-upload","api-response","budibase-ai"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}