{"record":{"id":"08612d4b04c43b5b","repo":"Budibase/budibase","slug":"agentid-in-body-does-not-match-path","errorCode":null,"errorMessage":"agentId in body does not match path","messagePattern":"agentId in body does not match path","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/chatConversations.ts","lineNumber":349,"sourceCode":"        error: updateError,\n      })\n    })\n}\n\ninterface ResolvedChatStreamRequest {\n  agentId: string\n  chat: ChatAgentRequest\n  userId: string\n  user: ContextUser\n}\n\nconst applyChatStreamPathParams = (\n  chat: ChatAgentRequest,\n  params: UserCtx<ChatAgentRequest, void>[\"params\"]\n) => {\n  const agentId = params?.agentId\n  if (agentId && chat.agentId && chat.agentId !== agentId) {\n    throw new HTTPError(\"agentId in body does not match path\", 400)\n  }\n\n  const chatConversationId = params?.chatConversationId\n  if (\n    chatConversationId &&\n    chatConversationId !== \"new\" &&\n    chat._id &&\n    chat._id !== chatConversationId\n  ) {\n    throw new HTTPError(\"chatConversationId in body does not match path\", 400)\n  }\n\n  if (agentId) {\n    chat.agentId = agentId\n  }\n  if (chatConversationId && chatConversationId !== \"new\") {\n    chat._id = chatConversationId\n  }","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/chatConversations.ts#L331-L367","documentation":"When streaming a chat, both the URL path (params.agentId) and the request body (chat.agentId) may carry an agent id. If both are present and differ, the request is ambiguous and rejected with HTTP 400 before any processing.","triggerScenarios":"POST to /api/ai/chat/:agentId/stream (or similar) with a body whose agentId differs from the path segment, e.g. reusing a cached body from a different agent.","commonSituations":"Client caches the chat request body across conversations/agents and forgets to update body.agentId; proxy rewriting the path but not the body.","solutions":["Make body.agentId match the path agentId","Omit agentId from the body and rely on the path parameter","Regenerate the request body when switching agents instead of mutating a stale one"],"exampleFix":"// before\nPOST /api/ai/chat/agent_123/stream\n{ \"agentId\": \"agent_999\", ... }\n// after\nPOST /api/ai/chat/agent_123/stream\n{ \"agentId\": \"agent_123\", ... }","handlingStrategy":"validation","validationCode":"if (body.agentId && pathAgentId && body.agentId !== pathAgentId) {\n  throw new Error(\"body.agentId must match the path agentId\")\n}","typeGuard":null,"tryCatchPattern":"try {\n  await streamChat(pathAgentId, body)\n} catch (e) {\n  if (e.status === 400 && String(e.message).includes(\"agentId in body does not match path\")) {\n    // rebuild the request body for the target agent\n  }\n}","preventionTips":["Derive body.agentId from the same variable used to build the URL","Don't cache and reuse chat request bodies across agents","Prefer omitting agentId in the body when the path already carries it"],"tags":["validation","http-400","api-mismatch"],"backgroundTag":"path-body-parameter-mismatch","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}