{"record":{"id":"07adb62253aa5825","repo":"BoundaryML/baml","slug":"failed-to-fetch-media-e","errorCode":null,"errorMessage":"Failed to fetch media: {e:?}","messagePattern":"Failed to fetch media: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/traits/mod.rs","lineNumber":783,"sourceCode":"            Ok(BamlMedia::base64(\n                part.media_type,\n                media_b64.base64.clone(),\n                mime_type,\n            ))\n        }\n    }\n}\n\nasync fn to_base64_with_inferred_mime_type(\n    ctx: &RuntimeContext,\n    media_url: &MediaUrl,\n) -> Result<(String, String)> {\n    if let Some((mime_type, base64)) = as_base64(media_url.url.as_str()) {\n        return Ok((base64.to_string(), mime_type.to_string()));\n    }\n    let response = match fetch_with_proxy(&media_url.url, ctx.proxy_url()).await {\n        Ok(response) => response,\n        Err(e) => return Err(anyhow::anyhow!(\"Failed to fetch media: {e:?}\")),\n    };\n    if response.status().is_success() {\n        let bytes = match response.bytes().await {\n            Ok(bytes) => bytes,\n            Err(e) => return Err(anyhow::anyhow!(\"Failed to fetch media bytes: {e:?}\")),\n        };\n        let base64 = BASE64_STANDARD.encode(&bytes);\n        // TODO: infer based on file extension?\n        let mime_type = match infer::get(&bytes) {\n            Some(t) => t.mime_type(),\n            None => \"application/octet-stream\",\n        }\n        .to_string();\n        Ok((base64, mime_type))\n    } else {\n        Err(anyhow::anyhow!(\n            \"Failed to fetch media: {} {}, {}\",\n            response.status(),","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L765-L801","documentation":"to_base64_with_inferred_mime_type failed at the network layer while downloading the media URL (fetch_with_proxy returned Err). BAML wraps the underlying reqwest error in this message rather than silently sending empty content.","triggerScenarios":"The media URL is unreachable: DNS failure, connection refused/reset, TLS error, or a configured proxy is down, and the URL is not a base64 data URL.","commonSituations":"Private/internal URLs not reachable from the runtime host; typos in the domain; expired signed URLs (S3/GCS); no internet access or corporate proxy misconfiguration.","solutions":["Verify the URL is reachable (curl it from the same host)","Check for expired pre-signed URLs and regenerate them","If a proxy is configured, verify BAML's proxy setting is correct and the proxy is up","Encode the media as a base64 data URL to skip fetching entirely"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const reachable = await fetch(url, { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!reachable) throw new Error(`Media URL unreachable: ${url}`);","typeGuard":null,"tryCatchPattern":"try {\n  await runBamlFn();\n} catch (e) {\n  if (/Failed to fetch media:/.test(String(e.message)) && attempts < 3) {\n    await sleep(2 ** attempts * 500);\n    return runBamlFn(attempts + 1);\n  }\n  throw e;\n}","preventionTips":["Prefer base64 data URLs for media generated at runtime","Verify signed URLs are not expired before the call","Test URL reachability from the deployment environment (proxy/DNS)"],"tags":["network","http","fetch","baml"],"backgroundTag":"http-request-failed","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"}