Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(files): build the next listing page's headers in one handler helper

mateo-berri7bddb656c10c
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py
index a70807bf6a5..884c5a6fada 100644
--- a/litellm/llms/custom_httpx/llm_http_handler.py
+++ b/litellm/llms/custom_httpx/llm_http_handler.py
@@ -5014,14 +5014,7 @@ class BaseLLMHTTPHandler:
if next_request is None:
return
url, params = next_request
- next_headers = provider_config.validate_environment(
- api_key=litellm_params.get("api_key"),
- headers=headers,
- model="",
- messages=[],
- optional_params={},
- litellm_params=litellm_params,
- )
+ next_headers = self._next_listing_page_headers(provider_config, headers, litellm_params)
try:
latest_page = client.get(url=url, headers=next_headers, params=params, timeout=timeout)
except Exception as e: # noqa: BLE001 # _handle_error maps every failure kind, like the first page's fetch
@@ -5049,19 +5042,27 @@ class BaseLLMHTTPHandler:
if next_request is None:
return
url, params = next_request
- next_headers = provider_config.validate_environment(
- api_key=litellm_params.get("api_key"),
- headers=headers,
- model="",
- messages=[],
- optional_params={},
- litellm_params=litellm_params,
- )
+ next_headers = self._next_listing_page_headers(provider_config, headers, litellm_params)
try:
latest_page = await client.get(url=url, headers=next_headers, params=params, timeout=timeout)
except Exception as e: # noqa: BLE001 # _handle_error maps every failure kind, like the first page's fetch
raise self._handle_error(e=e, provider_config=provider_config)
+ def _next_listing_page_headers(
+ self,
+ provider_config: BaseFilesConfig,
+ headers: dict, # mutable-ok: handed to validate_environment, which types it as a dict
+ litellm_params: dict, # mutable-ok: handed to the files contract, which types it as a dict
+ ) -> dict: # mutable-ok: validate_environment returns the header dict the files contract types
+ return provider_config.validate_environment(
+ api_key=litellm_params.get("api_key"),
+ headers=headers,
+ model="",
+ messages=[],
+ optional_params={},
+ litellm_params=litellm_params,
+ )
+
def _next_listing_request(
self,
latest_page: httpx.Response,