BoundaryML/baml · error · Error

Audio is not a URL

Error message

Audio is not a URL

What it means

The TypeScript Audio Media wrapper stores content either as a URL or as base64 data. asUrl() is an accessor that is only valid when the audio was constructed as a URL; otherwise it throws 'Audio is not a URL'.

Solutions

  1. Check audio.isUrl() before calling asUrl().
  2. Use asBase64() when the audio holds base64 data.
  3. Construct the Audio with Audio.fromUrl if you need URL access later.

Example fix

// before
const url = audio.asUrl(); // throws for base64 audio
// after
const url = audio.isUrl() ? audio.asUrl() : null;
Defensive patterns

Strategy: type-guard

Validate before calling

if (audio.isUrl()) { /* safe to call asUrl */ }

Type guard

function isUrlAudio(audio) { return typeof audio.isUrl === 'function' && audio.isUrl(); }

Try / catch

try {
  const url = audio.asUrl();
} catch (e) {
  if (e.message === 'Audio is not a URL') { /* fall back to asBase64 */ }
  else throw e;
}

Prevention

When it happens

Trigger: Calling audio.asUrl() on an Audio instance created from base64 data (or vice versa) instead of a URL.

Common situations: Receiving media from an LLM response as base64 and assuming it's a URL, or mixing up which constructor (fromUrl vs fromBase64) produced the object.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/c791ebda166a94d4. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_typescript/audio.js:68

     */
    static async fromUrlAsync(url) {
        const response = await fetch(url);
        const blob = await response.blob();
        return BamlAudio.fromBlob(blob);
    }
    /**
     * Check if the audio is stored as a URL
     */
    isUrl() {
        return this.type === 'url';
    }
    /**
     * Get the URL of the audio if it's stored as a URL
     * @throws Error if the audio is not stored as a URL
     */
    asUrl() {
        if (!this.isUrl()) {
            throw new Error('Audio is not a URL');
        }
        return this.content;
    }
    /**
     * Get the base64 data and media type if the audio is stored as base64
     * @returns [base64Data, mediaType]
     * @throws Error if the audio is not stored as base64
     */
    asBase64() {
        if (this.type !== 'base64') {
            throw new Error('Audio is not base64');
        }
        return [this.content, this.mediaType || ''];
    }
    /**
     * Convert the audio to a JSON representation
     */
    toJSON() {

View on GitHub (pinned to bd85ce9dee)