mem0ai/mem0 · error · Error

image_url content part is missing image_url.url

Error message

image_url content part is missing image_url.url

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/utils/memory.ts:36

  ]);
  return response;
};

const parse_vision_messages = async (messages: Message[]) => {
  const parsed_messages = [];
  for (const message of messages) {
    let new_message = {
      role: message.role,
      content: "",
    };
    if (message.role !== "system") {
      if (
        typeof message.content === "object" &&
        message.content.type === "image_url"
      ) {
        const imageUrl = message.content.image_url?.url;
        if (!imageUrl) {
          throw new Error("image_url content part is missing image_url.url");
        }
        const description = await get_image_description(imageUrl);
        new_message.content =
          typeof description === "string"
            ? description
            : JSON.stringify(description);
        parsed_messages.push(new_message);
      } else parsed_messages.push(message);
    }
  }
  return parsed_messages;
};

export { parse_vision_messages };

View on GitHub (pinned to 001c235229)

Solutions

  1. Ensure every image_url content part has a non-empty image_url.url string (http(s) URL or base64 data URI).
  2. Filter out or skip malformed image parts before calling memory.add().
  3. Type your messages with the OpenAI SDK's ChatCompletionContentPart types so the compiler catches the missing url.

Example fix

// before
messages: [{ role: 'user', content: { type: 'image_url', image_url: {} } }]
// after
messages: [{ role: 'user', content: { type: 'image_url', image_url: { url: 'data:image/png;base64,...' } } }]
Defensive patterns

Strategy: type-guard

Validate before calling

function hasValidImageUrl(content: unknown): boolean {
  return (
    typeof content === 'object' && content !== null &&
    (content as any).type === 'image_url' &&
    typeof (content as any).image_url?.url === 'string' &&
    (content as any).image_url.url.length > 0
  );
}

Type guard

type ImageUrlPart = { type: 'image_url'; image_url: { url: string } };
function isImageUrlPart(c: unknown): c is ImageUrlPart {
  return (
    !!c && typeof c === 'object' && (c as any).type === 'image_url' &&
    typeof (c as any).image_url?.url === 'string' && (c as any).image_url.url !== ''
  );
}

Try / catch

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; }

Prevention

When it happens

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

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/96758a825c56d3cb. Report an issue: GitHub.