From 9fd4c00b064e6358fdb5202daa417b3cfb482796 Mon Sep 17 00:00:00 2001 From: Chesars Date: Tue, 3 Mar 2026 11:06:38 -0300 Subject: [PATCH] fix(proxy): re-encode response IDs in retrieve_batch for model-based routing The provider returns raw IDs in the retrieve response (output_file_id, error_file_id). These need to be encoded with model info so the client can use them for subsequent file download calls through the proxy. --- litellm/proxy/batches_endpoints/endpoints.py | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py index cdee69f2b30..d3e983c5ad5 100644 --- a/litellm/proxy/batches_endpoints/endpoints.py +++ b/litellm/proxy/batches_endpoints/endpoints.py @@ -464,8 +464,30 @@ async def retrieve_batch( # noqa: PLR0915 custom_llm_provider=credentials["custom_llm_provider"], **data # type: ignore ) - - + + # Re-encode response IDs so the client always sees encoded IDs. + # The provider returns raw IDs (e.g. output_file_id, error_file_id) + # which the client needs encoded to route future file downloads. + if response and hasattr(response, "id") and response.id: + response.id = encode_file_id_with_model( + file_id=response.id, model=model_from_id, id_type="batch", + ) + + if hasattr(response, "output_file_id") and response.output_file_id: + response.output_file_id = encode_file_id_with_model( + file_id=response.output_file_id, model=model_from_id + ) + + if hasattr(response, "error_file_id") and response.error_file_id: + response.error_file_id = encode_file_id_with_model( + file_id=response.error_file_id, model=model_from_id + ) + + if hasattr(response, "input_file_id") and response.input_file_id: + response.input_file_id = encode_file_id_with_model( + file_id=response.input_file_id, model=model_from_id + ) + verbose_proxy_logger.debug( f"Retrieved batch using model: {model_from_id}, original_id: {original_batch_id}" )