{"record":{"id":"bc04d1006ac1490f","repo":"BoundaryML/baml","slug":"baml-internal-error-openai-audio-url-has-no-extension-and-no","errorCode":null,"errorMessage":"BAML internal error (openai): audio url has no extension and no mime type","messagePattern":"BAML internal error \\(openai\\): audio url has no extension and no mime type","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs","lineNumber":838,"sourceCode":"                            payload_key.into(),\n                            json!({\n                                \"data\": b64_media.base64,\n                                \"format\": format_str\n                            }),\n                        );\n                    }\n                    BamlMediaContent::Url(url_content) => {\n                        // note: openai only supports mp3/wav for audio input\n                        // but we can still send other formats and allow openai to handle\n                        // the conversion\n                        let extension = url_content.url.split('.').next_back();\n\n                        // use mime type if it exists otherwise use extension, otherwise error.\n                        let extension = match media.mime_type.as_deref() {\n                            Some(mime) => mime,\n                            None => match extension {\n                                Some(ext) => ext,\n                                None => anyhow::bail!(\"BAML internal error (openai): audio url has no extension and no mime type\"),\n                            },\n                        };\n\n                        let format_str = match extension {\n                            \"mpeg\" => \"mp3\",\n                            other => other,\n                        };\n                        content.insert(\n                            payload_key.into(),\n                            json!({ \"data\": url_content.url, \"format\": format_str }),\n                        );\n                    }\n                    BamlMediaContent::File(_) => {\n                        anyhow::bail!(\n                            \"BAML internal error (openai): audio file should have been resolved to base64, not processed directly.\"\n                        );\n                    }\n                }","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs#L820-L856","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set the mime_type explicitly on the audio media block (e.g. audio/mpeg)","Use a URL that includes the audio extension (.mp3, .wav)","Prefetch the audio and pass it as base64 media instead of a URL","If the URL lacks an extension but you know the format, switch to base64 with the correct mime type"],"exampleFix":"// before\naudio { url \"https://cdn.example.com/track?token=abc\" }\n// after\naudio { url \"https://cdn.example.com/track.mp3\" } // or set mime_type \"audio/mpeg\"","handlingStrategy":"validation","validationCode":"// verify format derivability before sending audio-by-url\nconst ext = url.split(\".\").pop()?.split(\"?\")[0];\nif (!mimeType && !/^(mp3|wav|m4a|mpeg)$/.test(ext ?? \"\")) {\n  throw new Error(\"Audio URL needs an extension or an explicit mime_type\");\n}","typeGuard":"function hasAudioFormat(m: { url: string; mime_type?: string }): boolean {\n  return !!m.mime_type || /\\.(mp3|wav|m4a)(\\?|$)/.test(m.url);\n}","tryCatchPattern":null,"preventionTips":["Always set mime_type on audio media when URLs are extension-less (CDNs, signed URLs)","Prefer base64 audio for dynamically generated URLs","Keep query-string-only URLs out of audio media blocks"],"tags":["openai","audio","mime-type","url-format"],"backgroundTag":"missing-required-argument","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"}