From ff9d30bc7992f77dbc7352079fb942cfe095ccb2 Mon Sep 17 00:00:00 2001 From: shivam Date: Thu, 17 Sep 2026 23:44:39 +0000 Subject: [PATCH] refactor(batches): declare credential transport attribute on Logging Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../proxy/common_utils/check_batch_cost.py | 6 +----- litellm/batches/batch_line_item_logging.py | 4 +--- litellm/litellm_core_utils/litellm_logging.py | 1 + 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py index b41b3a6e1ad..d3bd830a9c0 100644 --- a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py +++ b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py @@ -867,11 +867,7 @@ class CheckBatchCost: optional_params={}, custom_llm_provider=str(llm_provider) if llm_provider else None, ) - # deployment credentials stay off litellm_params because every callback sees those; the - # line-item logger reads them back off this private attribute to fetch the batch files - setattr( # noqa: B010 # Logging has no declared attribute for trusted credentials transport - logging_obj, "_litellm_internal_model_credentials", MappingProxyType(dict(credentials)) - ) + logging_obj._litellm_internal_model_credentials = MappingProxyType(dict(credentials)) # pyright: ignore[reportPrivateUsage] # trusted credentials transport, consumed by batch_line_item_logging if not await self._claim_job_for_costing(job): verbose_proxy_logger.info( diff --git a/litellm/batches/batch_line_item_logging.py b/litellm/batches/batch_line_item_logging.py index 8a4206d3606..911a4d478ec 100644 --- a/litellm/batches/batch_line_item_logging.py +++ b/litellm/batches/batch_line_item_logging.py @@ -299,9 +299,7 @@ async def log_batch_line_items( is logged and swallowed: aggregate accounting must be unaffected.""" emitted = 0 # rebind-ok: loop accumulator for emitted line count try: - internal_credentials: Final = getattr(parent, "_litellm_internal_model_credentials", None) or ( - litellm_params.get("_litellm_internal_model_credentials") if litellm_params else None - ) + internal_credentials: Final = parent._litellm_internal_model_credentials # pyright: ignore[reportPrivateUsage] # declared transport attribute on Logging internal_mapping: Final = _as_object_mapping(internal_credentials) fetch_params: Final[dict[str, object] | None] = ( # mutable-ok: file fetcher requires a plain dict dict(internal_mapping) # mutable-ok: the file fetcher reads credential kwargs off a plain dict diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index acba0eb1025..64cbf8eff4b 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -574,6 +574,7 @@ class Logging(LiteLLMLoggingBaseClass): self.sync_streaming_chunks: list[Any] = [] # for generating complete stream response self.log_raw_request_response = log_raw_request_response self._native_callback_fast_path: bool = False + self._litellm_internal_model_credentials: Mapping[str, object] | None = None # Initialize dynamic callbacks self.dynamic_input_callbacks: list[str | Callable | CustomLogger] | None = dynamic_input_callbacks