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
- 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
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
- 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
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
- chatConversationId in body does not match path
- Invalid bookmark query
- Invalid limit query
- Limit query must be between 1 and 100
- Invalid ${queryName} query
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/08612d4b04c43b5b.
Report an issue: GitHub.