BerriAI/litellm · error · Exception

Filtering by 'target_model_names' is not supported when usin

Error message

Filtering by 'target_model_names' is not supported when using managed batches.

What it means

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.

Source

Thrown at enterprise/litellm_enterprise/proxy/hooks/managed_files.py:429

        self,
        user_api_key_dict: UserAPIKeyAuth,
        limit: Optional[int] = None,
        after: Optional[str] = None,
        provider: Optional[str] = None,
        target_model_names: Optional[str] = None,
        llm_router: Optional[Router] = None,
    ) -> Dict[str, object]:
        # Provider filtering is not supported for managed batches
        # This is because the encoded object ids stored in the managed objects table do not contain the provider information
        # To support provider filtering, we would need to store the provider information in the encoded object ids
        if provider:
            raise Exception("Filtering by 'provider' is not supported when using managed batches.")

        # Model name filtering is not supported for managed batches
        # This is because the encoded object ids stored in the managed objects table do not contain the model name
        # 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.
        if target_model_names:
            raise Exception("Filtering by 'target_model_names' is not supported when using managed batches.")

        owner_filter = build_owner_filter(user_api_key_dict)
        if owner_filter is None:
            return build_list_page([])

        where_clause: Dict[str, object] = {"file_purpose": "batch", **owner_filter}

        if after:
            cursor_row = await _managed_object_table(self.prisma_client).find_first(
                where={**where_clause, "unified_object_id": after}
            )
            if cursor_row is None:
                raise HTTPException(
                    status_code=400,
                    detail=f"Invalid 'after' cursor: no batch found with id '{after}'.",
                )

        page_size: Final = min(limit or 20, 100)

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Drop target_model_names from the call and filter returned batches client-side against your own model metadata
  2. Tag batches with model info at creation time (via metadata you store) if model-based listing is a hard requirement
  3. Remember provider filtering is equally unsupported for managed batches

Example fix

# before
batches = await managed_files.list_user_batches(
    user_api_key_dict, limit=20, target_model_names='gpt-4o')

# after
batches = await managed_files.list_user_batches(user_api_key_dict, limit=20)
gpt4o = [b for b in batches['data'] if b.get('model') == 'gpt-4o']
Defensive patterns

Strategy: validation

Validate before calling

def clean_batch_filters(provider=None, target_model_names=None, **kw):
    if target_model_names:
        logger.warning('target_model_names unsupported for managed batches; dropped')
    kw.pop('target_model_names', None)
    return kw

Type guard

def is_supported_batch_filter(target_model_names: str | None) -> bool:
    return target_model_names is None

Try / catch

try:
    await managed_files.list_user_batches(uak, limit=20, target_model_names=m)
except Exception as e:
    if 'not supported when using managed batches' in str(e):
        page = await managed_files.list_user_batches(uak, limit=20)
        return [b for b in page['data'] if b.get('model') in m.split(',')]
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/86001af39129f02f. Report an issue: GitHub.