Skip to content

Conversation

@Sameerlite
Copy link
Collaborator

@Sameerlite Sameerlite commented Dec 9, 2025

Title

Add anthropic retrieve batches and retreive file content support

Relevant issues

Fixes LIT-1457

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring

Changes

@vercel
Copy link

vercel bot commented Dec 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Dec 10, 2025 0:59am

)

verbose_proxy_logger.info(
f"Stored Anthropic batch managed object with unified_object_id={unified_object_id}, batch_id={model_object_id}"

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.

Copilot Autofix

AI 3 days ago

To address this issue, we should avoid logging the raw unified_object_id and batch_id values if they could incorporate or be derived from sensitive user data (such as API keys, passwords, identifiers, etc.). The best fix is to redact or mask the sensitive portions before logging, or simply omit logging these fields altogether if not strictly necessary. If logging is required for troubleshooting or audit, log only non-sensitive, high-level information (e.g., log that a batch managed object was stored, but do not log any identifiers).

The problematic code is in litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py, lines 513–514.
The fix involves updating the logging statement to either:

  1. Redact sensitive information;
  2. Omit the identifiers;
  3. Or hash the identifiers (e.g., use a one-way hash and log only the hash).

Given best practices, it’s preferable to simply remove the logging of the identifier or replace it with a generic statement that does not include potentially sensitive IDs.

Suggested changeset 1
litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
--- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
+++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
@@ -510,7 +510,7 @@
                 )
                 
                 verbose_proxy_logger.info(
-                    f"Stored Anthropic batch managed object with unified_object_id={unified_object_id}, batch_id={model_object_id}"
+                    "Stored Anthropic batch managed object for cost tracking."
                 )
             else:
                 verbose_proxy_logger.warning("Managed files hook not available, cannot store batch object for cost tracking")
EOF
@@ -510,7 +510,7 @@
)

verbose_proxy_logger.info(
f"Stored Anthropic batch managed object with unified_object_id={unified_object_id}, batch_id={model_object_id}"
"Stored Anthropic batch managed object for cost tracking."
)
else:
verbose_proxy_logger.warning("Managed files hook not available, cannot store batch object for cost tracking")
Copilot is powered by AI and may make mistakes. Always verify output.
else:
# Fallback to model name
actual_model_id = model_name
verbose_proxy_logger.warning(f"Model not found in router, using model name: {actual_model_id}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.

Copilot Autofix

AI 3 days ago

Sensitive data should never be logged, especially if it originates from untrusted input. Here, the problematic log statement is in AnthropicPassthroughLoggingHandler.get_actual_model_id_from_router. To fix the issue:

  • Avoid logging the actual, raw model name if it is user-supplied and not guaranteed to be safe (sanitize, redact, or hash).
  • Instead of printing the full model name, log only that the fallback occurred, or log a redacted version (e.g., truncating, masking, or indicating its class/type).
  • Optionally, use a utility to sanitize strings before logging, e.g., only print the model provider, or a fixed prefix, or a hash.
  • Apply this fix specifically to line 537 (and optionally 541 for consistency), in litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py.
  • No additional dependencies are needed, as the fix can be implemented in plain Python.
Suggested changeset 1
litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
--- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
+++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
@@ -534,9 +534,9 @@
             else:
                 # Fallback to model name
                 actual_model_id = model_name
-                verbose_proxy_logger.warning(f"Model not found in router, using model name: {actual_model_id}")
+                verbose_proxy_logger.warning("Model not found in router, using fallback model identifier.")
                 return actual_model_id
         else:
             # Fallback if router is not available
-            verbose_proxy_logger.warning(f"Router not available, using model name: {model_name}")
+            verbose_proxy_logger.warning("Router not available, using fallback model identifier.")
             return model_name
EOF
@@ -534,9 +534,9 @@
else:
# Fallback to model name
actual_model_id = model_name
verbose_proxy_logger.warning(f"Model not found in router, using model name: {actual_model_id}")
verbose_proxy_logger.warning("Model not found in router, using fallback model identifier.")
return actual_model_id
else:
# Fallback if router is not available
verbose_proxy_logger.warning(f"Router not available, using model name: {model_name}")
verbose_proxy_logger.warning("Router not available, using fallback model identifier.")
return model_name
Copilot is powered by AI and may make mistakes. Always verify output.
return actual_model_id
else:
# Fallback if router is not available
verbose_proxy_logger.warning(f"Router not available, using model name: {model_name}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.

Copilot Autofix

AI 3 days ago

To fix this issue, we want to ensure that potentially sensitive user-supplied values, such as model_name, are never included in clear-text logs. The best approach is to avoid including the real value of model_name in the log message and instead log a generic placeholder, such as [REDACTED], or simply do not mention the specific model name at all. This preserves logging context (e.g., that a fallback occurred) without risking data leakage. We will edit the log statement at line 541 in litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py, replacing the message string so the potentially sensitive data is not logged. No other changes are required.


Suggested changeset 1
litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
--- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
+++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
@@ -538,5 +538,5 @@
                 return actual_model_id
         else:
             # Fallback if router is not available
-            verbose_proxy_logger.warning(f"Router not available, using model name: {model_name}")
+            verbose_proxy_logger.warning("Router not available, using model name: [REDACTED]")
             return model_name
EOF
@@ -538,5 +538,5 @@
return actual_model_id
else:
# Fallback if router is not available
verbose_proxy_logger.warning(f"Router not available, using model name: {model_name}")
verbose_proxy_logger.warning("Router not available, using model name: [REDACTED]")
return model_name
Copilot is powered by AI and may make mistakes. Always verify output.
@Sameerlite Sameerlite marked this pull request as ready for review December 11, 2025 05:01
@Sameerlite Sameerlite merged commit 8942053 into main Dec 11, 2025
48 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants