From 9d16a3000b24d255f70ab74c01eb6267354df151 Mon Sep 17 00:00:00 2001 From: Juan Cruz-Benito Date: Wed, 18 Jun 2025 15:31:50 +0200 Subject: [PATCH] Fixing watsonx error: 'model_id' or 'model' cannot be specified in the request body for models in a deployment space --- litellm/llms/openai_like/chat/handler.py | 6 +++++- tests/llm_translation/test_watsonx.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/litellm/llms/openai_like/chat/handler.py b/litellm/llms/openai_like/chat/handler.py index 821fc9b7f15..25b7fc2e98c 100644 --- a/litellm/llms/openai_like/chat/handler.py +++ b/litellm/llms/openai_like/chat/handler.py @@ -272,7 +272,11 @@ class OpenAILikeChatHandler(OpenAILikeBase): ) data = { - "model": model, + # watsonx: Deployment models do not support 'model_id' in their payload + # https://github.com/BerriAI/litellm/issues/11837 + "model": None + if custom_llm_provider == "watsonx" and model.startswith("deployment/") + else model, "messages": messages, **optional_params, **extra_body, diff --git a/tests/llm_translation/test_watsonx.py b/tests/llm_translation/test_watsonx.py index e0c125a9017..e399c6de7a9 100644 --- a/tests/llm_translation/test_watsonx.py +++ b/tests/llm_translation/test_watsonx.py @@ -207,6 +207,7 @@ def test_watsonx_deployment_space_id(monkeypatch, watsonx_chat_completion_call, assert mock_post.call_count == 1 json_data = json.loads(mock_post.call_args.kwargs["data"]) assert my_fake_space_id not in json_data + assert json_data.get("model") is None def test_watsonx_deployment_space_id_embedding(monkeypatch, watsonx_embedding_call): @@ -218,3 +219,4 @@ def test_watsonx_deployment_space_id_embedding(monkeypatch, watsonx_embedding_ca assert mock_post.call_count == 1 json_data = json.loads(mock_post.call_args.kwargs["data"]) assert my_fake_space_id not in json_data + assert json_data.get("model") is None