{"record":{"id":"ccd00809e21001a4","repo":"BerriAI/litellm","slug":"litellm-managed-file-object-with-id-file-id-not","errorCode":null,"errorMessage":"LiteLLM Managed File object with id={file_id} not found","messagePattern":"LiteLLM Managed File object with id=(.+?) not found","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"enterprise/litellm_enterprise/proxy/hooks/managed_files.py","lineNumber":368,"sourceCode":"        )\n\n        if result:\n            return LiteLLM_ManagedFileTable.model_validate(result)\n\n        ## CHECK DB\n        db_object = await _managed_file_table(self.prisma_client).find_first(where={\"unified_file_id\": file_id})\n\n        if db_object:\n            return LiteLLM_ManagedFileTable.model_validate(db_object.model_dump())\n        return None\n\n    async def delete_unified_file_id(\n        self, file_id: str, litellm_parent_otel_span: Optional[Span] = None\n    ) -> OpenAIFileObject:\n        ## get old value\n        initial_value = await _managed_file_table(self.prisma_client).find_first(where={\"unified_file_id\": file_id})\n        if initial_value is None:\n            raise Exception(f\"LiteLLM Managed File object with id={file_id} not found\")\n        ## delete old value\n        await self.internal_usage_cache.async_set_cache(\n            key=file_id,\n            value=None,\n            litellm_parent_otel_span=litellm_parent_otel_span,\n        )\n        await _managed_file_table(self.prisma_client).delete(where={\"unified_file_id\": file_id})\n        return initial_value.file_object\n\n    async def can_user_call_unified_file_id(self, unified_file_id: str, user_api_key_dict: UserAPIKeyAuth) -> bool:\n        managed_file = await _managed_file_table(self.prisma_client).find_first(\n            where={\"unified_file_id\": unified_file_id}\n        )\n\n        if managed_file:\n            return can_access_resource(\n                user_api_key_dict=user_api_key_dict,\n                created_by=managed_file.created_by,","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/proxy/hooks/managed_files.py#L350-L386","documentation":"Generic Exception raised by ManagedFiles.delete_unified_file_id: a find_first on the managed-file table by unified_file_id returned None, so there is nothing to delete. The file id supplied does not exist (or was already deleted / belongs to a different object type).","triggerScenarios":"DELETE on a managed file whose unified_file_id is absent from the managed files table: retrying a delete that already succeeded, an id from a different environment, or passing a plain OpenAI file id where a LiteLLM unified id is expected.","commonSituations":"Client retry logic re-sending a successful delete without idempotency handling; id mismatch between provider file ids and LiteLLM unified ids when managed files/batches are enabled; concurrent deletion by another request or admin.","solutions":["Confirm the id is a LiteLLM unified file id (the one returned by the managed upload/list endpoints), not the raw provider id","Treat 'not found' on delete as idempotent success in client code instead of surfacing an error","List files for the owner first (list endpoint) and delete using an id from that result"],"exampleFix":"# before\nawait managed_files.delete_unified_file_id(file_id)  # may raise\n\n# after\nexisting = await managed_files.get_file_by_unified_id(file_id)\nif existing is None:\n    return  # already deleted / never existed\nawait managed_files.delete_unified_file_id(file_id)","handlingStrategy":"type-guard","validationCode":"existing = await managed_files.get_file_by_unified_id(file_id)\nif existing is None:\n    return {'deleted': False}  # idempotent no-op","typeGuard":"async def file_exists(mf, file_id: str) -> bool:\n    return await mf.get_file_by_unified_id(file_id) is not None","tryCatchPattern":"try:\n    await managed_files.delete_unified_file_id(file_id)\nexcept Exception as e:\n    if 'not found' in str(e):\n        return  # already gone; treat delete as idempotent\n    raise","preventionTips":["Make deletes idempotent: check-then-delete or swallow not-found","Only delete ids obtained from upload/list responses"],"tags":["managed-files","not-found","delete","litellm-enterprise"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}