Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(cloud): tool-loop 422 on lu-cloud — tool messages were missing tool_call_id

purpleed99f8294228
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 1f72ebb8..f50eb739 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -1241,7 +1241,13 @@ export function useAgentChat() {
return ''
}
- if (providerId === 'openai' || providerId === 'anthropic') {
+ // lu-cloud is OpenAI-compatible (DeepInfra) and STRICTLY validates the
+ // OpenAI tool shape: assistant tool_calls carry ids and every tool-result
+ // message needs a matching tool_call_id. Route it through the id-based
+ // branch (not the id-less `native` one below) — otherwise DeepInfra 422s
+ // "ChatCompletionToolMessage.tool_call_id: Field required" and every
+ // follow-up turn fails. Ollama/LM-Studio are lenient; only cloud bit.
+ if (providerId === 'openai' || providerId === 'anthropic' || providerId === 'lu-cloud') {
agentMessages.push({
role: 'assistant',
content: turnContent || '',
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index 9ba6c98e..6080d835 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -1315,7 +1315,14 @@ export function useCodex() {
return settings.smallModelMode ? truncateToolResult(text) : text
}
- if (providerId === 'openai' || providerId === 'anthropic') {
+ // lu-cloud is OpenAI-compatible (DeepInfra) and STRICTLY validates the
+ // OpenAI tool shape: assistant tool_calls carry ids and every tool-result
+ // message needs a matching tool_call_id. Route it through the id-based
+ // branch (not the id-less `native` one below) — otherwise DeepInfra 422s
+ // "messages.N…ChatCompletionToolMessage.tool_call_id: Field required"
+ // and every follow-up turn in the conversation fails. Ollama/LM-Studio
+ // are lenient, which is why this only bit the cloud path.
+ if (providerId === 'openai' || providerId === 'anthropic' || providerId === 'lu-cloud') {
messages.push({ role: 'assistant', content: turnContent || '', tool_calls: toolCalls })
for (const { tc } of batch) {
const result = results.find((r) => r.id === batch.find((b) => b.tc === tc)?.ac.id)!