{"record":{"id":"4976a147c726ac24","repo":"BoundaryML/baml","slug":"baml-internal-error-openai-image-file-should-have-been","errorCode":null,"errorMessage":"BAML internal error (openai): image file should have been resolved, not processed directly.","messagePattern":"BAML internal error \\(openai\\): image file should have been resolved, not processed directly\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs","lineNumber":795,"sourceCode":"            BamlMediaType::Image => {\n                let type_value = \"image_url\";\n                let payload_key = \"image_url\";\n                content.insert(\"type\".into(), json!(type_value));\n\n                match &media.content {\n                    BamlMediaContent::Url(url_content) => {\n                        content.insert(payload_key.into(), json!({ \"url\": url_content.url }));\n                    }\n                    BamlMediaContent::Base64(b64_media) => {\n                        content.insert(\n                            payload_key.into(),\n                            json!({\n                                \"url\": format!(\"data:{};base64,{}\", media.mime_type_as_ok()?, b64_media.base64)\n                            }),\n                        );\n                    }\n                    BamlMediaContent::File(_) => {\n                        anyhow::bail!(\"BAML internal error (openai): image file should have been resolved, not processed directly.\");\n                    }\n                }\n            }\n            BamlMediaType::Audio => {\n                let type_value = \"input_audio\";\n                let payload_key = \"input_audio\";\n                content.insert(\"type\".into(), json!(type_value));\n\n                match &media.content {\n                    BamlMediaContent::Base64(b64_media) => {\n                        let mime_type_str = media.mime_type_as_ok()?;\n                        // remove \"audio/\" from the start of the mime type if it exists\n                        let mime_type_str = mime_type_str\n                            .strip_prefix(\"audio/\")\n                            .unwrap_or(mime_type_str.as_str());\n\n                        // note: openai only supports mp3/wav for audio input\n                        // but we can still send other formats and allow openai to handle","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs#L777-L813","documentation":"In to_media_message, image media must already have been resolved to base64 (BamlMediaContent::Base64) before provider conversion. Encountering BamlMediaContent::File means a file-backed image reached the OpenAI client unresolved, so it bails with this internal error.","triggerScenarios":"An image media whose content is still a File reference (not resolved to Base64) when building the OpenAI chat completions request body.","commonSituations":"Passing a local file path as image media in a context where BAML's media resolution stage did not run (custom/programmatic media construction, SDK usage building BamlImage from file manually).","solutions":["Resolve the image to base64 before handing it to the client (use BAML media resolution APIs: .to_base64 / force_to_base64)","Pass a URL or base64 data source instead of a raw file reference","If using the BAML runtime normally, report as a bug — files should be resolved automatically"],"exampleFix":"// before (Rust/SDK)\nlet media = BamlImage::from_file(\"cat.png\"); // unresolved file\n// after\nlet media = BamlImage::from_file(\"cat.png\").to_base64()?; // resolved","handlingStrategy":"validation","validationCode":"// before calling the client with an image\nif (image.content.kind === \"file\") {\n  image = await image.to_base64();\n}","typeGuard":"fn is_base64_image(m: &BamlMedia) -> bool {\n    matches!(m.content, BamlMediaContent::Base64(_))\n}","tryCatchPattern":null,"preventionTips":["Always call to_base64/force_to_base64 on file-backed media in SDK code","Let the BAML runtime resolve media automatically instead of hand-building media objects","Unit-test media pipelines for unresolved File content"],"tags":["openai","image","media-resolution","internal-state"],"backgroundTag":"invalid-state-transition","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"}