{"record":{"id":"86001af39129f02f","repo":"BerriAI/litellm","slug":"filtering-by-target-model-names-is-not-supported","errorCode":null,"errorMessage":"Filtering by 'target_model_names' is not supported when using managed batches.","messagePattern":"Filtering by 'target_model_names' is not supported when using managed batches\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"enterprise/litellm_enterprise/proxy/hooks/managed_files.py","lineNumber":429,"sourceCode":"        self,\n        user_api_key_dict: UserAPIKeyAuth,\n        limit: Optional[int] = None,\n        after: Optional[str] = None,\n        provider: Optional[str] = None,\n        target_model_names: Optional[str] = None,\n        llm_router: Optional[Router] = None,\n    ) -> Dict[str, object]:\n        # Provider filtering is not supported for managed batches\n        # This is because the encoded object ids stored in the managed objects table do not contain the provider information\n        # To support provider filtering, we would need to store the provider information in the encoded object ids\n        if provider:\n            raise Exception(\"Filtering by 'provider' is not supported when using managed batches.\")\n\n        # Model name filtering is not supported for managed batches\n        # This is because the encoded object ids stored in the managed objects table do not contain the model name\n        # A hash of the model name + litellm_params for the model name is encoded as the model id. This is not sufficient to reliably map the target model names to the model ids.\n        if target_model_names:\n            raise Exception(\"Filtering by 'target_model_names' is not supported when using managed batches.\")\n\n        owner_filter = build_owner_filter(user_api_key_dict)\n        if owner_filter is None:\n            return build_list_page([])\n\n        where_clause: Dict[str, object] = {\"file_purpose\": \"batch\", **owner_filter}\n\n        if after:\n            cursor_row = await _managed_object_table(self.prisma_client).find_first(\n                where={**where_clause, \"unified_object_id\": after}\n            )\n            if cursor_row is None:\n                raise HTTPException(\n                    status_code=400,\n                    detail=f\"Invalid 'after' cursor: no batch found with id '{after}'.\",\n                )\n\n        page_size: Final = min(limit or 20, 100)","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/proxy/hooks/managed_files.py#L411-L447","documentation":"Generic Exception from list_user_batches: a non-None target_model_names filter is rejected because managed object ids encode only a hash of model name + litellm_params, which cannot be reliably mapped back to target model names. The check sits directly below the provider check in the same method.","triggerScenarios":"Calling list_user_batches with target_model_names set (e.g. 'gpt-4o,claude-3-5') under managed batches. Any truthy value raises before pagination logic runs.","commonSituations":"Copy-pasting parameters from the non-managed batch list API; UI offering model filters that the managed backend cannot honor; SDK wrappers that always populate optional filter kwargs.","solutions":["Drop target_model_names from the call and filter returned batches client-side against your own model metadata","Tag batches with model info at creation time (via metadata you store) if model-based listing is a hard requirement","Remember provider filtering is equally unsupported for managed batches"],"exampleFix":"# before\nbatches = await managed_files.list_user_batches(\n    user_api_key_dict, limit=20, target_model_names='gpt-4o')\n\n# after\nbatches = await managed_files.list_user_batches(user_api_key_dict, limit=20)\ngpt4o = [b for b in batches['data'] if b.get('model') == 'gpt-4o']","handlingStrategy":"validation","validationCode":"def clean_batch_filters(provider=None, target_model_names=None, **kw):\n    if target_model_names:\n        logger.warning('target_model_names unsupported for managed batches; dropped')\n    kw.pop('target_model_names', None)\n    return kw","typeGuard":"def is_supported_batch_filter(target_model_names: str | None) -> bool:\n    return target_model_names is None","tryCatchPattern":"try:\n    await managed_files.list_user_batches(uak, limit=20, target_model_names=m)\nexcept Exception as e:\n    if 'not supported when using managed batches' in str(e):\n        page = await managed_files.list_user_batches(uak, limit=20)\n        return [b for b in page['data'] if b.get('model') in m.split(',')]\n    raise","preventionTips":["Never forward optional filter params blindly from UI to managed batch APIs","Store model metadata per batch id in your own store at creation time"],"tags":["managed-batches","unsupported-operation","validation","litellm-enterprise"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}