{"record":{"id":"50bfccd91a59a077","repo":"BoundaryML/baml","slug":"failed-to-fetch-media-bytes-e","errorCode":null,"errorMessage":"Failed to fetch media bytes: {e:?}","messagePattern":"Failed to fetch media bytes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/traits/mod.rs","lineNumber":788,"sourceCode":"        }\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(),\n            media_url.url,\n            response.text().await.unwrap_or_default(),\n        ))\n    }\n}","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L770-L806","documentation":"Error while collecting response body bytes in media fetching: the HTTP request for a media URL succeeded at the transport level, but reading the response body stream failed (connection reset mid-body, timeout, or decoding error). The debug-formatted reqwest error in {e:?} carries the transport specifics; this fires from the base64-encoding path used when media is supplied as a remote URL.","triggerScenarios":"Connection dropped or timed out mid-body while streaming the media response; server closed the connection before sending the full payload.","commonSituations":"Large media files over flaky connections; server-side timeouts on big downloads; interrupted proxies; transient network issues.","solutions":["Retry the fetch — this is often transient","Reduce media file size before uploading/serving it","Use a base64 data URL instead of a remote URL to avoid the network read","Increase any configured HTTP timeouts"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runBamlFn();\n} catch (e) {\n  if (/Failed to fetch media bytes/.test(String(e.message)) && retries < 3) {\n    return runBamlFn(retries + 1); // transient mid-body network failure\n  }\n  throw e;\n}","preventionTips":["Serve smaller media files to reduce mid-transfer failures","Use base64 data URLs when the media is already in memory","Ensure stable networking/proxy configuration between host and media server"],"tags":["network","http","baml"],"backgroundTag":"network-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"}