{"record":{"id":"5003c015f99c88ff","repo":"BoundaryML/baml","slug":"video-is-not-base64","errorCode":null,"errorMessage":"Video is not base64","messagePattern":"Video is not base64","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/typescript_src/video.ts","lineNumber":81,"sourceCode":"  /**\n   * Get the URL of the video if it's stored as a URL\n   * @throws Error if the video is not stored as a URL\n   */\n  asUrl(): string {\n    if (!this.isUrl()) {\n      throw new Error(\"Video is not a URL\");\n    }\n    return this.content;\n  }\n\n  /**\n   * Get the base64 data and media type if the video is stored as base64\n   * @returns [base64Data, mediaType]\n   * @throws Error if the video is not stored as base64\n   */\n  asBase64(): [string, string] {\n    if (this.type !== \"base64\") {\n      throw new Error(\"Video is not base64\");\n    }\n    return [this.content, this.mediaType || \"\"];\n  }\n\n  /**\n   * Convert the video to a JSON representation\n   */\n  toJSON(): { url: string } | { base64: string; media_type: string } {\n    if (this.type === \"url\") {\n      return { url: this.content };\n    }\n    return {\n      base64: this.content,\n      media_type: this.mediaType || \"\",\n    };\n  }\n}\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/typescript_src/video.ts#L63-L99","documentation":"Video.asBase64() throws this when the video's content is stored as a URL rather than base64 data. The accessor only returns [base64Data, mediaType] for the base64 representation, so it defensively throws when this.type is not \"base64\". Check isUrl()/the type field before calling it.","triggerScenarios":"Calling video.asBase64() on a Video constructed from a URL (this.type !== \"base64\"), e.g. Video.fromUrl(\"https://...\") content being piped into a code path that expects inline base64 media.","commonSituations":"Preparing multimodal requests for APIs that require base64 media while the source video was given as a URL; switching between local testing (URLs) and production (base64) media sources; assuming a uniform representation across Video instances deserialized from mixed inputs.","solutions":["Check video.type (or isUrl()) before calling asBase64() and fall back to asUrl() otherwise","Fetch the URL content and convert it to base64 with the correct media type before calling base64-based APIs","Construct the Video with base64 content if your downstream pipeline requires it","Normalize all videos through a converter function that handles both representations"],"exampleFix":"// before\nconst [data, mediaType] = video.asBase64();\n// after\nif (video.isUrl()) {\n  const res = await fetch(video.asUrl());\n  const buf = Buffer.from(await res.arrayBuffer());\n  var [data, mediaType] = [buf.toString(\"base64\"), res.headers.get(\"content-type\") ?? \"\"];\n} else {\n  [data, mediaType] = video.asBase64();\n}","handlingStrategy":"type-guard","validationCode":"if (video.type !== \"base64\") {\n  // fetch the URL and convert to base64 first\n}","typeGuard":"function isBase64Video(v) { return typeof v.type === \"string\" && v.type === \"base64\"; }","tryCatchPattern":"let data, mediaType;\ntry {\n  [data, mediaType] = video.asBase64();\n} catch (e) {\n  if (e.message === \"Video is not base64\") {\n    ({ data, mediaType } = await convertUrlToBase64(video.asUrl()));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Check this.type (or isUrl()) before every asBase64() call","Normalize media inputs to one representation at ingestion time","Write one videoToBase64 helper and route all base64 consumers through it"],"tags":["typescript","video","multimodal","base64","content-type"],"backgroundTag":"incompatible-source-type","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}