{"record":{"id":"7f2a86a8139ba12e","repo":"BoundaryML/baml","slug":"audio-is-not-base64","errorCode":null,"errorMessage":"Audio is not base64","messagePattern":"Audio is not base64","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/audio.js","lineNumber":79,"sourceCode":"    }\n    /**\n     * Get the URL of the audio if it's stored as a URL\n     * @throws Error if the audio is not stored as a URL\n     */\n    asUrl() {\n        if (!this.isUrl()) {\n            throw new Error('Audio is not a URL');\n        }\n        return this.content;\n    }\n    /**\n     * Get the base64 data and media type if the audio is stored as base64\n     * @returns [base64Data, mediaType]\n     * @throws Error if the audio is not stored as base64\n     */\n    asBase64() {\n        if (this.type !== 'base64') {\n            throw new Error('Audio is not base64');\n        }\n        return [this.content, this.mediaType || ''];\n    }\n    /**\n     * Convert the audio to a JSON representation\n     */\n    toJSON() {\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}\nexports.BamlAudio = BamlAudio;\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/audio.js#L61-L97","documentation":"JavaScript client state guard: asBase64() was called on a BamlAudio object whose internal type is 'url', not 'base64'. The media objects are tagged unions; calling the accessor for the wrong representation throws. Use asUrl() instead, or convert the representation before calling.","triggerScenarios":"Calling audio.asBase64() on an Audio instance constructed from a URL (type !== 'base64').","commonSituations":"Passing a URL-based Audio where base64 payload is expected, or assuming an LLM-returned audio reference is inline base64.","solutions":["Check this.type === 'base64' (or an equivalent guard) before calling asBase64().","Use asUrl() for URL-stored audio.","Build the Audio with Audio.fromBase64 if base64 access is required."],"exampleFix":"// before\nconst [data, mediaType] = audio.asBase64(); // throws for URL audio\n// after\nconst [data, mediaType] = audio.type === 'base64' ? audio.asBase64() : [null, null];","handlingStrategy":"type-guard","validationCode":"if (audio.type === 'base64') { /* safe to call asBase64 */ }","typeGuard":"function isBase64Audio(audio) { return audio.type === 'base64'; }","tryCatchPattern":"try {\n  const [data, mt] = audio.asBase64();\n} catch (e) {\n  if (e.message === 'Audio is not base64') { /* use asUrl instead */ }\n  else throw e;\n}","preventionTips":["Inspect the `type` field before calling accessors.","Construct media with the accessor-compatible form you need."],"tags":["typescript","audio","media","state-error"],"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-23T08:17:48.524Z"}