line 253-258, pass extra_headers fields from settings to litellm, exception handling to check if extra_headers is in dict format

This commit is contained in:
chandan84
2025-02-22 14:38:38 -05:00
parent e7b05732f8
commit 0e4a1d9ab8

View File

@ -251,8 +251,10 @@ class LiteLLMAIHandler(BaseAiHandler):
get_logger().info(f"\nUser prompt:\n{user}")
#Added support for extra_headers while using litellm to call underlying model, via a api management gateway, would allow for passing custom headers for security and authorization
if get_settings().get("LITELLM.EXTRA_HEADERS", None):
kwargs["extra_headers"] = json.loads(get_settings().litellm.extra_headers)
litellm_extra_headers = json.loads(get_settings().litellm.extra_headers)
if not isinstance(litellm_extra_headers, dict):
raise ValueError("LITELLM.EXTRA_HEADERS must be a JSON object")
kwargs["extra_headers"] = litellm_extra_headers
response = await acompletion(**kwargs)
except (openai.APIError, openai.APITimeoutError) as e: