BoundaryML/baml · error · anyhow::Error

BAML internal error (openai): audio url has no extension…

Error message

BAML internal error (openai): audio url has no extension and no mime type

What it means

For audio supplied as a URL, OpenAI's input_audio payload needs a format derived from either the media's mime type or the URL's file extension. When both are absent, BAML cannot determine the audio format and bails.

Solutions

  1. Set the mime_type explicitly on the audio media block (e.g. audio/mpeg)
  2. Use a URL that includes the audio extension (.mp3, .wav)
  3. Prefetch the audio and pass it as base64 media instead of a URL
  4. If the URL lacks an extension but you know the format, switch to base64 with the correct mime type

Example fix

// before
audio { url "https://cdn.example.com/track?token=abc" }
// after
audio { url "https://cdn.example.com/track.mp3" } // or set mime_type "audio/mpeg"
Defensive patterns

Strategy: validation

Validate before calling

// verify format derivability before sending audio-by-url
const ext = url.split(".").pop()?.split("?")[0];
if (!mimeType && !/^(mp3|wav|m4a|mpeg)$/.test(ext ?? "")) {
  throw new Error("Audio URL needs an extension or an explicit mime_type");
}

Type guard

function hasAudioFormat(m: { url: string; mime_type?: string }): boolean {
  return !!m.mime_type || /\.(mp3|wav|m4a)(\?|$)/.test(m.url);
}

Prevention

When it happens

Trigger: ChatMessagePart media of type Audio with content Url where media.mime_type is None and the URL has no recognizable extension (e.g. https://example.com/audio?token=x).

Common situations: Serving audio via extension-less CDN/signed URLs or API endpoints that stream audio without a file extension and without setting a mime type on the media block.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs:838

                            payload_key.into(),
                            json!({
                                "data": b64_media.base64,
                                "format": format_str
                            }),
                        );
                    }
                    BamlMediaContent::Url(url_content) => {
                        // note: openai only supports mp3/wav for audio input
                        // but we can still send other formats and allow openai to handle
                        // the conversion
                        let extension = url_content.url.split('.').next_back();

                        // use mime type if it exists otherwise use extension, otherwise error.
                        let extension = match media.mime_type.as_deref() {
                            Some(mime) => mime,
                            None => match extension {
                                Some(ext) => ext,
                                None => anyhow::bail!("BAML internal error (openai): audio url has no extension and no mime type"),
                            },
                        };

                        let format_str = match extension {
                            "mpeg" => "mp3",
                            other => other,
                        };
                        content.insert(
                            payload_key.into(),
                            json!({ "data": url_content.url, "format": format_str }),
                        );
                    }
                    BamlMediaContent::File(_) => {
                        anyhow::bail!(
                            "BAML internal error (openai): audio file should have been resolved to base64, not processed directly."
                        );
                    }
                }

View on GitHub (pinned to bd85ce9dee)