{"record":{"id":"97fd8929f9f9934e","repo":"BoundaryML/baml","slug":"requested-media-of-mime-type-but-fetched-from-url-please","errorCode":null,"errorMessage":"Requested media of MIME type '{}' but fetched '{}' from URL {}. Please ensure the URL points to the correct file or update the mime_type in BAML.","messagePattern":"Requested media of MIME type '(.+?)' but fetched '(.+?)' from URL (.+?)\\. Please ensure the URL points to the correct file or update the mime_type in BAML\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/traits/mod.rs","lineNumber":712,"sourceCode":"                    None\n                }\n            } else {\n                match part.media_type {\n                    BamlMediaType::Pdf => Some(\"application/pdf\".to_string()),\n                    _ => None,\n                }\n            };\n\n            if let Some(expected) = &expected_mime_type {\n                // we accept subtype matches (e.g. image/jpeg starts_with image/)\n                let mismatch = if expected.contains('/') {\n                    &inferred_mime_type != expected\n                } else {\n                    !inferred_mime_type.starts_with(expected)\n                };\n\n                if mismatch {\n                    anyhow::bail!(\n                        \"Requested media of MIME type '{}' but fetched '{}' from URL {}. Please ensure the URL points to the correct file or update the mime_type in BAML.\",\n                        expected,\n                        inferred_mime_type,\n                        media_url.url\n                    );\n                }\n            }\n\n            Ok(BamlMedia::base64(\n                part.media_type,\n                if render_settings.as_shell_commands {\n                    format!(\"$(curl -L '{}' | base64)\", media_url.url)\n                } else {\n                    base64\n                },\n                Some(part.mime_type.clone().unwrap_or(inferred_mime_type)),\n            ))\n        }","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L694-L730","documentation":"BAML validates that the MIME type it infers from fetched media matches the mime_type declared in the BAML schema. When a URL download's inferred type differs from the expected type (e.g. image declared but server returns HTML), process_media bails to prevent sending the wrong content to the model.","triggerScenarios":"process_media_urls downloads a URL for media whose declared mime_type (exact match for images, prefix match otherwise) differs from the inferred type from response bytes.","commonSituations":"URL points to an HTML login/error page instead of the image; CDN serves a generic content type; file was replaced or moved; mime_type in BAML file outdated after re-uploading a different format.","solutions":["Fix the URL so it actually serves the declared media type (curl -I to check Content-Type)","Update the mime_type in the BAML file to match what the URL serves","If using a proxy/CDN, ensure it passes through correct Content-Type headers","Download the file locally and send base64 with an explicit data: URL prefix instead"],"exampleFix":"// before\nimage my_img\n  url \"https://example.com/report.pdf\"\n// after\nimage my_img\n  url \"https://example.com/photo.jpg\"","handlingStrategy":"validation","validationCode":"async function assertUrlServes(url, expectedPrefix) {\n  const res = await fetch(url, { method: 'HEAD' });\n  const ct = res.headers.get('content-type') || '';\n  if (!res.ok || !ct.startsWith(expectedPrefix)) throw new Error(`URL ${url} serves '${ct}', expected '${expectedPrefix}'`);\n}\nawait assertUrlServes(mediaUrl, 'image/');","typeGuard":null,"tryCatchPattern":"try {\n  await runBamlFn();\n} catch (e) {\n  if (/Requested media of MIME type/.test(String(e.message))) {\n    console.warn(`Media content mismatch at: ${e.message.match(/from URL (\\S+)/)?.[1]}`);\n  }\n  throw e;\n}","preventionTips":["curl -I the media URLs and confirm Content-Type matches the BAML mime_type","Re-check mime_type declarations after re-uploading assets","Avoid URLs that redirect to HTML pages (logins, error pages)"],"tags":["media","mime-type","http","baml"],"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-14T05:17:10.506Z"}