Litellm dev 01 22 2025 p4 (#7932)

* feat(main.py): add new 'provider_specific_header' param

allows passing extra header for specific provider

* fix(litellm_pre_call_utils.py): add unit test for pre call utils

* test(test_bedrock_completion.py): skip test now that bedrock supports this
This commit is contained in:
Krish Dholakia 2025-01-22 21:52:07 -08:00 committed by GitHub
parent 4911cd80a1
commit 27560bd5ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 119 additions and 5 deletions

View file

@ -179,6 +179,7 @@ from .types.utils import (
HiddenParams,
LlmProviders,
PromptTokensDetails,
ProviderSpecificHeader,
all_litellm_params,
)
@ -832,6 +833,9 @@ def completion( # type: ignore # noqa: PLR0915
model_info = kwargs.get("model_info", None)
proxy_server_request = kwargs.get("proxy_server_request", None)
fallbacks = kwargs.get("fallbacks", None)
provider_specific_header = cast(
Optional[ProviderSpecificHeader], kwargs.get("provider_specific_header", None)
)
headers = kwargs.get("headers", None) or extra_headers
ensure_alternating_roles: Optional[bool] = kwargs.get(
"ensure_alternating_roles", None
@ -937,6 +941,13 @@ def completion( # type: ignore # noqa: PLR0915
api_base=api_base,
api_key=api_key,
)
if (
provider_specific_header is not None
and provider_specific_header["custom_llm_provider"] == custom_llm_provider
):
headers.update(provider_specific_header["extra_headers"])
if model_response is not None and hasattr(model_response, "_hidden_params"):
model_response._hidden_params["custom_llm_provider"] = custom_llm_provider
model_response._hidden_params["region_name"] = kwargs.get(