Budibase/budibase · error · HTTPError

agentId in body does not match path

Error message

agentId in body does not match path

What it means

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.

Source

Thrown at packages/server/src/api/controllers/ai/chatConversations.ts:349

        error: updateError,
      })
    })
}

interface ResolvedChatStreamRequest {
  agentId: string
  chat: ChatAgentRequest
  userId: string
  user: ContextUser
}

const applyChatStreamPathParams = (
  chat: ChatAgentRequest,
  params: UserCtx<ChatAgentRequest, void>["params"]
) => {
  const agentId = params?.agentId
  if (agentId && chat.agentId && chat.agentId !== agentId) {
    throw new HTTPError("agentId in body does not match path", 400)
  }

  const chatConversationId = params?.chatConversationId
  if (
    chatConversationId &&
    chatConversationId !== "new" &&
    chat._id &&
    chat._id !== chatConversationId
  ) {
    throw new HTTPError("chatConversationId in body does not match path", 400)
  }

  if (agentId) {
    chat.agentId = agentId
  }
  if (chatConversationId && chatConversationId !== "new") {
    chat._id = chatConversationId
  }

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Make body.agentId match the path agentId
  2. Omit agentId from the body and rely on the path parameter
  3. Regenerate the request body when switching agents instead of mutating a stale one

Example fix

// before
POST /api/ai/chat/agent_123/stream
{ "agentId": "agent_999", ... }
// after
POST /api/ai/chat/agent_123/stream
{ "agentId": "agent_123", ... }
Defensive patterns

Strategy: validation

Validate before calling

if (body.agentId && pathAgentId && body.agentId !== pathAgentId) {
  throw new Error("body.agentId must match the path agentId")
}

Try / catch

try {
  await streamChat(pathAgentId, body)
} catch (e) {
  if (e.status === 400 && String(e.message).includes("agentId in body does not match path")) {
    // rebuild the request body for the target agent
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Client caches the chat request body across conversations/agents and forgets to update body.agentId; proxy rewriting the path but not the body.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/08612d4b04c43b5b. Report an issue: GitHub.