{"record":{"id":"fb5a96ea0236c14b","repo":"BoundaryML/baml","slug":"baml-internal-error-openai-pdf-file-should-have-been","errorCode":null,"errorMessage":"BAML internal error (openai): Pdf file should have been resolved to base64 before this stage.","messagePattern":"BAML internal error \\(openai\\): Pdf file should have been resolved to base64 before this stage\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs","lineNumber":886,"sourceCode":"                            json!({\n                                \"type\": \"input_file\",\n                                \"file_url\": url_content.url,\n                                \"filename\": \"document.pdf\"\n                            }),\n                        );\n                    }\n                    BamlMediaContent::Base64(b64_media) => {\n                        content.insert(\n                            payload_key.into(),\n                            json!({\n                                \"filename\": \"document.pdf\",\n                                \"file_data\": format!(\"data:{};base64,{}\", media.mime_type_as_ok()?, b64_media.base64)\n                            }),\n                        );\n                    }\n                    BamlMediaContent::File(media_file) => {\n                        // For files, we need to resolve them to base64 first\n                        anyhow::bail!(\n                            \"BAML internal error (openai): Pdf file should have been resolved to base64 before this stage.\"\n                        );\n                    }\n                }\n            }\n            BamlMediaType::Video => {\n                // OpenAI video is only supported on the Realtime API (/v1/realtime), not on chat completions\n                anyhow::bail!(\n                    \"Video input is only supported on OpenAI's Realtime API (/v1/realtime), not on chat completions. \\\n                    Consider extracting frames from the video as images instead. \\\n                    See: https://platform.openai.com/docs/guides/realtime\"\n                );\n            }\n        }\n        Ok(content)\n    }\n\n    fn role_to_message(","sourceCodeStart":868,"sourceCodeEnd":904,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs#L868-L904","documentation":"PDF media must be resolved to base64 before reaching the OpenAI provider converter. A BamlMediaContent::File variant in to_media_message means resolution was skipped, so BAML bails. The unused media_file binding underlines it is an unexpected state.","triggerScenarios":"PDF media whose content is still File (not Base64) when the OpenAI chat completions request body is built.","commonSituations":"SDK users constructing BamlMedia::file without converting to base64, or embedding a PDF file path in a prompt where the automatic media-resolution stage did not execute.","solutions":["Convert the PDF to base64 before invoking the client (use BAML's media base64 resolution)","Pass the PDF as base64 data rather than a file reference","If produced by the normal BAML runtime, file a bug with a repro"],"exampleFix":"// before\nlet pdf = BamlMedia::file(\"doc.pdf\");\n// after\nlet pdf = BamlMedia::file(\"doc.pdf\").to_base64()?;","handlingStrategy":"validation","validationCode":"// resolve PDFs before invoking an openai client\nif (pdf.content.kind === \"file\") {\n  pdf = await pdf.to_base64();\n}","typeGuard":"fn pdf_resolved(m: &BamlMedia) -> bool {\n    matches!(m.content, BamlMediaContent::Base64(_))\n}","tryCatchPattern":null,"preventionTips":["Embed PDFs as base64 in prompts or resolve files through BAML's media APIs","Assert media is Base64-resolved in integration tests before provider calls","Avoid hand-constructing BamlMedia::file in SDK code"],"tags":["openai","pdf","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"}