Skip to content

Commit 48d06a7

Browse files
cosminachoclaude
andcommitted
Fix: lock use_responses_api to match discovered api_flavor
LangChain's ChatOpenAI auto-infers use_responses_api from parameters like reasoning={}, model names (gpt-5-pro), context_management, etc. This can silently switch a chat-completions-only model to the Responses API, sending an incompatible payload format. When api_flavor is locked: - chat-completions → use_responses_api = False (prevents auto-switch) - responses → use_responses_api = True (ensures correct format) - None → use_responses_api stays None (dynamic auto-detect) Also removes redundant use_responses_api logic from the factory since the model class now handles it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2ad1473 commit 48d06a7

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/uipath_langchain_client/src/uipath_langchain_client/clients/openai/chat_models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class UiPathChatOpenAI(UiPathBaseChatModel, ChatOpenAI): # type: ignore[overrid
4343
def setup_uipath_client(self) -> Self:
4444
if self.api_flavor is not None:
4545
self.api_config.api_flavor = self.api_flavor
46+
# Lock LangChain's use_responses_api to match the discovered flavor.
47+
# Without this, features like reasoning={} or certain model names
48+
# silently switch LangChain to the Responses API, which would fail
49+
# if the model only supports chat-completions (or vice versa).
50+
if self.api_flavor == ApiFlavor.CHAT_COMPLETIONS:
51+
self.use_responses_api = False
52+
elif self.api_flavor == ApiFlavor.RESPONSES:
53+
self.use_responses_api = True
4654
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
4755
locked_flavor = str(self.api_config.api_flavor) if self.api_config.api_flavor else None
4856

@@ -91,6 +99,10 @@ class UiPathAzureChatOpenAI(UiPathBaseChatModel, AzureChatOpenAI): # type: igno
9199
def setup_uipath_client(self) -> Self:
92100
if self.api_flavor is not None:
93101
self.api_config.api_flavor = self.api_flavor
102+
if self.api_flavor == ApiFlavor.CHAT_COMPLETIONS:
103+
self.use_responses_api = False
104+
elif self.api_flavor == ApiFlavor.RESPONSES:
105+
self.use_responses_api = True
94106
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
95107
locked_flavor = str(self.api_config.api_flavor) if self.api_config.api_flavor else None
96108

packages/uipath_langchain_client/src/uipath_langchain_client/factory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ def get_chat_model(
171171

172172
match discovered_vendor_type:
173173
case VendorType.OPENAI:
174-
if api_flavor == ApiFlavor.RESPONSES:
175-
model_kwargs["use_responses_api"] = True
176-
177174
if is_uipath_owned:
178175
from uipath_langchain_client.clients.openai.chat_models import (
179176
UiPathAzureChatOpenAI,

0 commit comments

Comments
 (0)