{"record":{"id":"96758a825c56d3cb","repo":"mem0ai/mem0","slug":"image-url-content-part-is-missing-image-url-url","errorCode":null,"errorMessage":"image_url content part is missing image_url.url","messagePattern":"image_url content part is missing image_url\\.url","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/utils/memory.ts","lineNumber":36,"sourceCode":"  ]);\n  return response;\n};\n\nconst parse_vision_messages = async (messages: Message[]) => {\n  const parsed_messages = [];\n  for (const message of messages) {\n    let new_message = {\n      role: message.role,\n      content: \"\",\n    };\n    if (message.role !== \"system\") {\n      if (\n        typeof message.content === \"object\" &&\n        message.content.type === \"image_url\"\n      ) {\n        const imageUrl = message.content.image_url?.url;\n        if (!imageUrl) {\n          throw new Error(\"image_url content part is missing image_url.url\");\n        }\n        const description = await get_image_description(imageUrl);\n        new_message.content =\n          typeof description === \"string\"\n            ? description\n            : JSON.stringify(description);\n        parsed_messages.push(new_message);\n      } else parsed_messages.push(message);\n    }\n  }\n  return parsed_messages;\n};\n\nexport { parse_vision_messages };\n","sourceCodeStart":18,"sourceCodeEnd":51,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/utils/memory.ts#L18-L51","documentation":"In the message preprocessing path (parse_messages), when a message content part is typed as image_url the code reads message.content.image_url.url and calls get_image_description on it. If the url field is absent or empty it throws this error rather than sending a malformed request downstream to the vision LLM. It guards the shape of multimodal OpenAI-style content parts.","triggerScenarios":"Adding a memory with messages: [{ role: 'user', content: { type: 'image_url', image_url: {} } }] where url is missing; url: '' empty string; nested shape wrong (image_url set to a string instead of { url }).","commonSituations":"Hand-building multimodal messages instead of using OpenAI SDK types; receiving content parts from a client that omits url for some images; data-URI generation failing upstream leaving url undefined.","solutions":["Ensure every image_url content part has a non-empty image_url.url string (http(s) URL or base64 data URI).","Filter out or skip malformed image parts before calling memory.add().","Type your messages with the OpenAI SDK's ChatCompletionContentPart types so the compiler catches the missing url."],"exampleFix":"// before\nmessages: [{ role: 'user', content: { type: 'image_url', image_url: {} } }]\n// after\nmessages: [{ role: 'user', content: { type: 'image_url', image_url: { url: 'data:image/png;base64,...' } } }]","handlingStrategy":"type-guard","validationCode":"function hasValidImageUrl(content: unknown): boolean {\n  return (\n    typeof content === 'object' && content !== null &&\n    (content as any).type === 'image_url' &&\n    typeof (content as any).image_url?.url === 'string' &&\n    (content as any).image_url.url.length > 0\n  );\n}","typeGuard":"type ImageUrlPart = { type: 'image_url'; image_url: { url: string } };\nfunction isImageUrlPart(c: unknown): c is ImageUrlPart {\n  return (\n    !!c && typeof c === 'object' && (c as any).type === 'image_url' &&\n    typeof (c as any).image_url?.url === 'string' && (c as any).image_url.url !== ''\n  );\n}","tryCatchPattern":"try { await memory.add(messages) } catch (e) { if (e instanceof Error && /missing image_url\\.url/.test(e.message)) { /* drop/repair malformed image parts and retry */ } throw e; }","preventionTips":["Build multimodal messages with the OpenAI SDK content-part types.","Filter messages through isImageUrlPart before memory.add().","Generate data URIs with a helper that never returns an empty string."],"tags":["multimodal","input-validation","vision","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}