{"record":{"id":"08e914b969fe81bc","repo":"BoundaryML/baml","slug":"image-is-not-a-url-08e914","errorCode":null,"errorMessage":"Image is not a URL","messagePattern":"Image is not a URL","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/typescript_src/image.ts","lineNumber":69,"sourceCode":"    const response = await fetch(url);\n    const blob = await response.blob();\n    return BamlImage.fromBlob(blob);\n  }\n\n  /**\n   * Check if the image is stored as a URL\n   */\n  isUrl(): boolean {\n    return this.type === 'url';\n  }\n\n  /**\n   * Get the URL of the image if it's stored as a URL\n   * @throws Error if the image is not stored as a URL\n   */\n  asUrl(): string {\n    if (!this.isUrl()) {\n      throw new Error('Image is not a URL');\n    }\n    return this.content;\n  }\n\n  /**\n   * Get the base64 data and media type if the image is stored as base64\n   * @returns [base64Data, mediaType]\n   * @throws Error if the image is not stored as base64\n   */\n  asBase64(): [string, string] {\n    if (this.type !== 'base64') {\n      throw new Error('Image is not base64');\n    }\n    return [this.content, this.mediaType || ''];\n  }\n\n  /**\n   * Convert the image to a JSON representation","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/typescript_src/image.ts#L51-L87","documentation":"BAML's Image object stores content either as a URL or base64. asUrl() narrows to the URL case and throws when the image is not URL-backed, protecting callers from receiving base64 data mistaken for a URL.","triggerScenarios":"Calling image.asUrl() on an Image built from base64 (fromBase64) or another non-URL source, so isUrl() returns false.","commonSituations":"Rendering image URLs in UI code while the model returned inline base64 images; passing config-loaded images (often base64) into code that assumes URL storage.","solutions":["Guard with image.isUrl() before calling asUrl()","Create the Image with Image.fromUrl(...) if URL access is required","Handle both storage types explicitly (branch to asBase64() when not a URL)"],"exampleFix":"// before\nconst url = image.asUrl(); // throws for base64 image\n// after\nconst src = image.isUrl() ? image.asUrl() : `data:${image.asBase64()[1]};base64,${image.asBase64()[0]}`;","handlingStrategy":"type-guard","validationCode":"if (!image.isUrl()) { /* handle base64 branch */ }","typeGuard":"const isUrlImage = (i) => i.isUrl();","tryCatchPattern":"try { const url = image.asUrl(); }\ncatch { const [b64, mt] = image.asBase64(); }","preventionTips":["Check isUrl() before asUrl()","Render images from data URLs when content is base64","Normalize media at ingestion time to the storage type consumers expect"],"tags":["image","media","base64","url"],"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-14T11:17:12.474Z"}