{"record":{"id":"4427eca284e3b2b6","repo":"invoke-ai/InvokeAI","slug":"failed-to-get-intermediates","errorCode":null,"errorMessage":"Failed to get intermediates","messagePattern":"Failed to get intermediates","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/images.py","lineNumber":283,"sourceCode":"\n    try:\n        count_deleted = ApiDependencies.invoker.services.images.delete_intermediates()\n        return count_deleted\n    except Exception:\n        raise HTTPException(status_code=500, detail=\"Failed to clear intermediates\")\n\n\n@images_router.get(\"/intermediates\", operation_id=\"get_intermediates_count\")\ndef get_intermediates_count(\n    current_user: CurrentUserOrDefault,\n) -> int:\n    \"\"\"Gets the count of intermediate images. Non-admin users only see their own intermediates.\"\"\"\n\n    try:\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.images.get_intermediates_count(user_id=user_id)\n    except Exception:\n        raise HTTPException(status_code=500, detail=\"Failed to get intermediates\")\n\n\n@images_router.patch(\n    \"/i/{image_name}\",\n    operation_id=\"update_image\",\n    response_model=ImageDTO,\n)\ndef update_image(\n    current_user: CurrentUserOrDefault,\n    image_name: str = Path(description=\"The name of the image to update\"),\n    image_changes: ImageRecordChanges = Body(description=\"The changes to apply to the image\"),\n) -> ImageDTO:\n    \"\"\"Updates an image\"\"\"\n    _assert_image_owner(image_name, current_user)\n    assert_image_move_maintenance_inactive()\n\n    try:\n        return ApiDependencies.invoker.services.images.update(image_name, image_changes)","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/images.py#L265-L301","documentation":"HTTP 500 raised by the GET intermediates-count endpoint when any exception escapes the call to ApiDependencies.invoker.services.images.get_intermediates_count(). The router wraps the service call in a broad try/except and converts every failure into a generic 'Failed to get intermediates' message, hiding the underlying cause.","triggerScenarios":"GET /api/v1/images/intermediates/count when the images service is unavailable, the underlying image records store raises (e.g. database locked/corrupt), or user_id filtering fails because session state is stale.","commonSituations":"Database file deleted or locked while InvokeAI runs; services not fully initialized after a failed startup; multi-user setups where the user record referenced by current_user no longer exists.","solutions":["Check server logs for the original exception logged before the 500 is returned","Verify the images database/sqlite file exists and is writable","Restart InvokeAI so services are re-initialized","If persistent, report with the traceback since the API response hides the cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// client side: ensure API is reachable before calling\nconst health = await fetch('/api/v1/app-version');\nif (!health.ok) throw new Error('API not ready');","typeGuard":null,"tryCatchPattern":"try {\n  const count = await api.getIntermediatesCount();\n} catch (e) {\n  if (e instanceof ApiError && e.status === 500) {\n    // service-level failure; surface server log pointer, offer retry\n  }\n}","preventionTips":["Keep the sqlite DB file present, writable, and backed up","Restart the app after any service init errors before hitting the API","Watch server logs — the 500 detail hides the real cause","Avoid manual deletion of DB files while InvokeAI is running"],"tags":["http-500","api","invokeai"],"backgroundTag":"internal-server-error-500","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}