Litellm dev 01 21 2025 p1 (#7898)

* fix(utils.py): don't pass 'anthropic-beta' header to vertex - will cause request to fail

* fix(utils.py): add flag to allow user to disable filtering invalid headers

ensure user can control behaviour

* style(utils.py): cleanup message

* test(test_utils.py): add unit test to cover invalid header filtering

* fix(proxy_server.py): fix custom openapi schema generation

* fix(utils.py): pass extra headers if set

* fix(main.py): fix image variation to use 'client' param
This commit is contained in:
Krish Dholakia 2025-01-21 20:36:11 -08:00 committed by GitHub
parent b73980ecd5
commit dec558ba4c
9 changed files with 161 additions and 21 deletions

View file

@ -112,6 +112,7 @@ from litellm.router_utils.get_retry_from_policy import (
reset_retry_policy,
)
from litellm.secret_managers.main import get_secret
from litellm.types.llms.anthropic import ANTHROPIC_API_ONLY_HEADERS
from litellm.types.llms.openai import (
AllMessageValues,
AllPromptValues,
@ -2601,6 +2602,25 @@ def _remove_unsupported_params(
return non_default_params
def get_clean_extra_headers(extra_headers: dict, custom_llm_provider: str) -> dict:
"""
For `anthropic-beta` headers, ensure provider is anthropic.
Vertex AI raises an exception if `anthropic-beta` is passed in.
"""
if litellm.filter_invalid_headers is not True: # allow user to opt out of filtering
return extra_headers
clean_extra_headers = {}
for k, v in extra_headers.items():
if k in ANTHROPIC_API_ONLY_HEADERS and custom_llm_provider != "anthropic":
verbose_logger.debug(
f"Provider {custom_llm_provider} does not support {k} header. Dropping from request, to prevent errors."
) # Switching between anthropic api and vertex ai anthropic fails when anthropic-beta is passed in. Welcome feedback on this.
else:
clean_extra_headers[k] = v
return clean_extra_headers
def get_optional_params( # noqa: PLR0915
# use the openai defaults
# https://platform.openai.com/docs/api-reference/chat/create
@ -2739,6 +2759,12 @@ def get_optional_params( # noqa: PLR0915
)
}
## Supports anthropic headers
if extra_headers is not None:
extra_headers = get_clean_extra_headers(
extra_headers=extra_headers, custom_llm_provider=custom_llm_provider
)
## raise exception if function calling passed in for a provider that doesn't support it
if (
"functions" in non_default_params
@ -3508,6 +3534,12 @@ def get_optional_params( # noqa: PLR0915
for k in passed_params.keys():
if k not in default_params.keys():
optional_params[k] = passed_params[k]
if extra_headers is not None:
optional_params.setdefault("extra_headers", {})
optional_params["extra_headers"] = {
**optional_params["extra_headers"],
**extra_headers,
}
print_verbose(f"Final returned optional params: {optional_params}")
return optional_params