{"record":{"id":"8b275b4b526dde7b","repo":"BoundaryML/baml","slug":"failed-to-fetch-media","errorCode":null,"errorMessage":"Failed to fetch media: {} {}, {}","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":799,"sourceCode":"    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}\n\n/// A naive implementation of the data URL parser, returning the (mime_type, base64)\n/// if parsing succeeds. Specifically, we only support specifying a single mime-type (so\n/// fields like 'charset' will be ignored) and only base64 data URLs.\n///\n/// See: https://fetch.spec.whatwg.org/#data-urls\nfn as_base64(maybe_base64_url: &str) -> Option<(&str, &str)> {\n    if let Some(data_url) = maybe_base64_url.strip_prefix(\"data:\") {\n        if let Some((mime_type, base64)) = data_url.split_once(\";base64,\") {\n            return Some((mime_type, base64));\n        }","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L781-L817","documentation":"HTTP-level failure while fetching remote media for an LLM call: the request for the media URL returned a non-success status (or failed to be issued). The message includes the status code and reason so the caller can distinguish 404s, auth failures, and transport errors. It fires in the media-to-base64 conversion path when a media entry is a URL rather than inline base64.","triggerScenarios":"fetch_with_proxy got a response whose status is not success (404, 403, 500, etc.) while downloading a media URL.","commonSituations":"Expired or revoked pre-signed S3/GCS URLs (403/404); URL behind authentication; deleted assets; rate limiting (429); wrong host producing 404.","solutions":["Check the status code and body in the error message — fix the root cause (usually 403/404 means regenerate the signed URL or fix the path)","Confirm the URL is publicly accessible or that credentials are passed appropriately","Re-upload the asset and update the URL","Fall back to sending base64 data instead of a URL"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const res = await fetch(mediaUrl, { method: 'HEAD' });\nif (!res.ok) throw new Error(`Media URL returned ${res.status}: ${mediaUrl}`);","typeGuard":null,"tryCatchPattern":"try {\n  await runBamlFn();\n} catch (e) {\n  if (/Failed to fetch media: \\d+/.test(String(e.message))) {\n    const status = parseInt(e.message.match(/Failed to fetch media: (\\d+)/)?.[1], 10);\n    if (status === 429) await sleep(backoff);\n    else console.error('Fix media URL; non-retryable status', status);\n  }\n  throw e;\n}","preventionTips":["Monitor signed-URL expiry (403s) and rotate credentials","HEAD-check media URLs in CI before shipping configs","Treat 429 with backoff; treat 403/404 as URL problems, not transient"],"tags":["http","network","baml"],"backgroundTag":"http-error-response","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"}