From 1ec50835425dd81bdc41d950c05a395ed5e8286e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 19 Jan 2024 17:06:24 -0800 Subject: [PATCH] fix(anthropic.py): fix pr for anthropic headers --- litellm/llms/anthropic.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/llms/anthropic.py b/litellm/llms/anthropic.py index f7d056bf9e5..2116aca19e1 100644 --- a/litellm/llms/anthropic.py +++ b/litellm/llms/anthropic.py @@ -78,7 +78,7 @@ class AnthropicConfig: # makes headers for API call -def validate_environment(api_key): +def validate_environment(api_key, user_headers): if api_key is None: raise ValueError( "Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params" @@ -89,6 +89,8 @@ def validate_environment(api_key): "content-type": "application/json", "x-api-key": api_key, } + if user_headers is not None and isinstance(user_headers, dict): + headers = {**headers, **user_headers} return headers @@ -107,7 +109,7 @@ def completion( logger_fn=None, headers={}, ): - headers = { **validate_environment(api_key), **headers } + headers = validate_environment(api_key, headers) if model in custom_prompt_dict: # check if the model has a registered custom prompt model_prompt_details = custom_prompt_dict[model]