{"record":{"id":"11458a1e8a046a0c","repo":"BoundaryML/baml","slug":"baml-internal-error-openai-responses-content-part-must-be-an","errorCode":null,"errorMessage":"BAML internal error (openai-responses): content part must be an object","messagePattern":"BAML internal error \\(openai-responses\\): content part must be an object","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs","lineNumber":211,"sourceCode":"                            \"data:{};base64,{}\",\n                            media.mime_type_as_ok()?,\n                            b64_media.base64\n                        ),\n                        \"filename\": \"document.pdf\"\n                    })),\n                },\n                baml_types::BamlMediaType::Video => {\n                    anyhow::bail!(\n                        \"BAML internal error (openai-responses): video is not yet supported by OpenAI Responses API\"\n                    );\n                }\n            }\n        }\n        ChatMessagePart::WithMeta(inner_part, metadata) => {\n            let mut content = responses_content_part(inner_part, role, allowed_metadata)?;\n            {\n                let content_object = content.as_object_mut().ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"BAML internal error (openai-responses): content part must be an object\"\n                    )\n                })?;\n                for (key, value) in metadata {\n                    if allowed_metadata.is_allowed(key) {\n                        content_object.insert(key.clone(), value.clone());\n                    }\n                }\n            }\n            Ok(content)\n        }\n    }\n}\n\nimpl ProviderStrategy {\n    fn get_endpoint(&self, base_url: &str, is_completion: bool) -> String {\n        match self {\n            ProviderStrategy::ResponsesApi => format!(\"{base_url}/responses\"),","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs#L193-L229","documentation":"When applying provider metadata to a Responses API content part, BAML expects the serialized part to be a JSON object. If the recursive responses_content_part call produced a non-object (string/array), as_object_mut fails and this internal invariant error is raised. It indicates a bug or unexpected shape in content-part serialization, not user input per se.","triggerScenarios":"A ChatMessagePart::WithMeta whose inner part serializes to a non-object JSON value, so metadata insertion via as_object_mut fails while building the Responses API request body.","commonSituations":"BAML internal bug after changes to content-part serialization; custom metadata attached to a part whose converted form is a plain string. Users hit this only through the library producing an invalid intermediate shape.","solutions":["Upgrade or downgrade BAML to a version where Responses API content-part serialization returns JSON objects","Remove custom metadata attached to content parts and retry","Report the failing prompt/client config to BAML as an internal bug with a repro","Fall back to the chat completions provider strategy"],"exampleFix":"// before: metadata on a part that serializes to a string\n{{part.with_meta(provider_metadata: {cache_control: ...})}}\n// after: use a part type that serializes to an object, or drop metadata\n{{part}}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch client.call(prompt).await {\n    Err(e) if e.to_string().contains(\"content part must be an object\") => {\n        // retry without provider metadata, or report BAML bug\n    }\n    other => other?,\n}","preventionTips":["Only attach metadata supported by the current BAML version","Test prompts with metadata on a staging client before production","Report persistent occurrences to BAML with the exact prompt and client config"],"tags":["openai","responses-api","internal-bug","json-shape"],"backgroundTag":"internal-invariant-violation","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"}