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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
(fix) IBM Watsonx using ZenApiKey (#7821)
Ishaan Jaffb492551d3da3
diff --git a/litellm/llms/watsonx/common_utils.py b/litellm/llms/watsonx/common_utils.pyindex d5bbe3fc141..62f141c4744 100644--- a/litellm/llms/watsonx/common_utils.py+++ b/litellm/llms/watsonx/common_utils.py@@ -177,12 +177,12 @@ class IBMWatsonXMixin:return {**default_headers, **headers}token = cast(Optional[str],- optional_params.get("token")- or get_secret_str("WATSONX_ZENAPIKEY")- or get_secret_str("WATSONX_TOKEN"),+ optional_params.get("token") or get_secret_str("WATSONX_TOKEN"),)if token:headers["Authorization"] = f"Bearer {token}"+ elif zen_api_key := get_secret_str("WATSONX_ZENAPIKEY"):+ headers["Authorization"] = f"ZenApiKey {zen_api_key}"else:token = _generate_watsonx_token(api_key=api_key, token=token)# build auth headersdiff --git a/tests/llm_translation/test_watsonx.py b/tests/llm_translation/test_watsonx.pyindex 41b3f099e55..bbebe325077 100644--- a/tests/llm_translation/test_watsonx.py+++ b/tests/llm_translation/test_watsonx.py@@ -98,9 +98,16 @@ def test_watsonx_token_in_env_var(mock_post, _ = watsonx_chat_completion_call(patch_token_call=False)assert mock_post.call_count == 1- assert (- mock_post.call_args[1]["headers"]["Authorization"] == "Bearer my-custom-token"- )+ if env_var_key == "WATSONX_ZENAPIKEY":+ assert (+ mock_post.call_args[1]["headers"]["Authorization"]+ == "ZenApiKey my-custom-token"+ )+ else:+ assert (+ mock_post.call_args[1]["headers"]["Authorization"]+ == "Bearer mock_access_token"+ )def test_watsonx_chat_completions_endpoint(watsonx_chat_completion_call):