{"record":{"id":"671b077900964955","repo":"mastra-ai/mastra","slug":"messageids-is-required","errorCode":null,"errorMessage":"messageIds is required","messagePattern":"messageIds is required","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":1730,"sourceCode":"});\n\nexport const DELETE_MESSAGES_ROUTE = createRoute({\n  method: 'POST',\n  path: '/memory/messages/delete',\n  responseType: 'json',\n  queryParamSchema: deleteMessagesQuerySchema,\n  bodySchema: deleteMessagesBodySchema,\n  responseSchema: deleteMessagesResponseSchema,\n  summary: 'Delete messages',\n  description: 'Deletes specific messages from memory',\n  tags: ['Memory'],\n  requiresAuth: true,\n  handler: async ({ mastra, agentId, resourceId, messageIds, requestContext }) => {\n    try {\n      const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);\n\n      if (messageIds === undefined || messageIds === null) {\n        throw new HTTPException(400, { message: 'messageIds is required' });\n      }\n\n      // Normalize messageIds to the format expected by deleteMessages\n      // Convert single values to arrays and extract IDs from objects\n      let normalizedIds: string[] | { id: string }[];\n\n      if (Array.isArray(messageIds)) {\n        // Already an array - keep as is (could be string[] or { id: string }[])\n        normalizedIds = messageIds;\n      } else if (typeof messageIds === 'string') {\n        // Single string ID - wrap in array\n        normalizedIds = [messageIds];\n      } else {\n        // Single object with id property - wrap in array\n        normalizedIds = [messageIds];\n      }\n\n      // Extract string IDs for validation and deletion","sourceCodeStart":1712,"sourceCodeEnd":1748,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L1712-L1748","documentation":"DELETE_MESSAGES_ROUTE (POST /memory/messages/delete) requires a messageIds payload. If messageIds is undefined or null after request parsing, the handler throws HTTPException 400 'messageIds is required'. The endpoint accepts a single string, a single { id } object, or arrays of either, but not an absent value.","triggerScenarios":"POST /api/memory/messages/delete with an empty body, a JSON body without the messageIds key, or a client SDK call like deleteMessages() invoked with no arguments (e.g., spreading an empty options object where the field is dropped).","commonSituations":"Client code building the request body conditionally so messageIds is omitted when the selection list is empty; sending Content-Type application/json with an empty body; older client versions sending a differently named field (e.g., ids) that the server ignores.","solutions":["Always send messageIds in the JSON body, e.g. { messageIds: ['msg-1', 'msg-2'] }.","Guard client-side: if the selection is empty, skip the API call instead of sending a body without messageIds.","Update @mastra/client-js to a version matching the server so the typed deleteMessages(messageIds) signature is enforced.","Send an array — single strings and { id } objects are accepted and normalized server-side."],"exampleFix":"// before\nawait client.post('/memory/messages/delete', {});\n\n// after\nif (selectedIds.length > 0) {\n  await client.post('/memory/messages/delete', { messageIds: selectedIds });\n}","handlingStrategy":"validation","validationCode":"if (!messageIds || (Array.isArray(messageIds) && messageIds.length === 0)) {\n  throw new Error('messageIds is required and must contain at least one id');\n}","typeGuard":"function hasMessageIds(body: unknown): body is { messageIds: string[] | { id: string }[] } {\n  const ids = (body as any)?.messageIds;\n  if (typeof ids === 'string') return ids.length > 0;\n  return Array.isArray(ids) && ids.length > 0;\n}","tryCatchPattern":"try {\n  await client.deleteMessages(messageIds);\n} catch (e) {\n  if (e instanceof HTTPException && e.status === 400 && /messageIds is required/.test(e.message)) {\n    console.error('Request body must include messageIds');\n    return;\n  }\n  throw e;\n}","preventionTips":["Type the request body so messageIds is non-optional.","No-op client-side when the selection is empty instead of sending a bare body.","Keep client-js and server versions aligned so schemas validate before send."],"tags":["http-400","validation","request-body","memory"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}