{"record":{"id":"8e2f608022ce2e9a","repo":"mastra-ai/mastra","slug":"invalid-data-url-format","errorCode":"INVALID_DATA_URL_FORMAT","errorMessage":"Invalid data URL format in content ${content.toString()}","messagePattern":"Invalid data URL format in content (.+?)","errorType":"exception","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/stream/aisdk/v5/compat/content.ts","lineNumber":72,"sourceCode":"    return { data: new Uint8Array(content), mediaType: undefined };\n  }\n\n  // Attempt to create a URL from the data. If it fails, we can assume the data\n  // is not a URL and likely some other sort of data.\n  if (typeof content === 'string') {\n    try {\n      content = new URL(content);\n    } catch {\n      // ignored\n    }\n  }\n\n  // Extract data from data URL:\n  if (content instanceof URL && content.protocol === 'data:') {\n    const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(content.toString());\n\n    if (dataUrlMediaType == null || base64Content == null) {\n      throw new MastraError({\n        id: 'INVALID_DATA_URL_FORMAT',\n        text: `Invalid data URL format in content ${content.toString()}`,\n        domain: ErrorDomain.LLM,\n        category: ErrorCategory.USER,\n      });\n    }\n\n    return { data: base64Content, mediaType: dataUrlMediaType };\n  }\n\n  return { data: content, mediaType: undefined };\n}\n","sourceCodeStart":54,"sourceCodeEnd":85,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/stream/aisdk/v5/compat/content.ts#L54-L85","documentation":"When converting AI SDK v5 content parts to Mastra's format, a data: URL must contain both a media type and base64 content. splitDataUrl returned null for one of these, meaning the URL is a malformed data URL (e.g. 'data:' with no media type or no comma-separated payload). MastraError with id INVALID_DATA_URL_FORMAT is thrown as a USER-category error.","triggerScenarios":"Passing new URL('data:image/png') or 'data:base64,xxx' (missing '/' in mime) or 'data:text/plain,' (empty payload) as a URL-backed media part in a message to an agent/stream.","commonSituations":"Hand-building data URLs with template strings and forgetting the comma or mime type; encoding empty buffers; receiving truncated data URLs from external systems.","solutions":["Format the data URL fully: data:<mimeType>;base64,<base64Payload> (e.g. 'data:image/png;base64,iVBORw0...')","Use Buffer.from(bytes).toString('base64') and prefix the header, instead of string concatenation with the raw bytes","Validate with a regex before sending: /^data:[\\w.+-]+\\/[\\w.+-]+;base64,[A-Za-z0-9+/=]+$/","If the source is a remote file, pass an https:// URL or Blob instead of a data URL"],"exampleFix":"// before\nnew URL(`data:${mimeType},${base64}`);\n// after\nnew URL(`data:${mimeType};base64,${base64}`);","handlingStrategy":"validation","validationCode":"const DATA_URL = /^data:[\\w.+-]+\\/[\\w.+-]+(;base64)?,[\\s\\S]+$/;\nfunction assertValidDataUrl(url: URL) {\n  if (url.protocol === 'data:' && !DATA_URL.test(url.toString())) {\n    throw new Error(`Malformed data URL: ${url}`);\n  }\n}","typeGuard":"function isWellFormedDataUrl(u: unknown): u is URL & { toString(): `data:${string};base64,${string}` } {\n  return u instanceof URL && /^data:[^,]+,[\\s\\S]+$/.test(u.toString());\n}","tryCatchPattern":"try {\n  return await agent.stream({ messages: withMedia(dataUrl) });\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'INVALID_DATA_URL_FORMAT') {\n    logger.error('Fix data URL format: data:<mime>;base64,<payload>', { url: dataUrl });\n  }\n  throw e;\n}","preventionTips":["Always build data URLs with the full header: data:<mime>;base64,<payload>","Use a helper instead of template-string concatenation for data URLs","Prefer https URLs or Blobs for remote content instead of hand-rolled data URLs","Validate media payloads at ingestion time, before constructing messages"],"tags":["validation","data-url","multimodal","aisdk"],"backgroundTag":"invalid-data-url","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}