{"record":{"id":"9dba8f7ac2d8aa5f","repo":"PrefectHQ/fastmcp","slug":"unsupported-image-mime-type-for-openai-content-m","errorCode":null,"errorMessage":"Unsupported image MIME type for OpenAI: {content.mime_type!r}. Supported types: {', '.join(sorted(_OPENAI_IMAGE_MEDIA_TYPES))}","messagePattern":"Unsupported image MIME type for OpenAI: (.+?)\\. Supported types: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/openai.py","lineNumber":69,"sourceCode":"# OpenAI only supports wav and mp3 for input audio\n_OPENAI_AUDIO_FORMATS: dict[str, Literal[\"wav\", \"mp3\"]] = {\n    \"audio/wav\": \"wav\",\n    \"audio/x-wav\": \"wav\",\n    \"audio/mp3\": \"mp3\",\n    \"audio/mpeg\": \"mp3\",\n}\n\n_OPENAI_IMAGE_MEDIA_TYPES: frozenset[str] = frozenset(\n    {\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"}\n)\n\n\ndef _image_content_to_openai_part(\n    content: ImageContent,\n) -> ChatCompletionContentPartImageParam:\n    \"\"\"Convert MCP ImageContent to OpenAI image_url content part.\"\"\"\n    if content.mime_type not in _OPENAI_IMAGE_MEDIA_TYPES:\n        raise ValueError(\n            f\"Unsupported image MIME type for OpenAI: {content.mime_type!r}. \"\n            f\"Supported types: {', '.join(sorted(_OPENAI_IMAGE_MEDIA_TYPES))}\"\n        )\n    data_url = f\"data:{content.mime_type};base64,{content.data}\"\n    return ChatCompletionContentPartImageParam(\n        type=\"image_url\",\n        image_url={\"url\": data_url},\n    )\n\n\ndef _audio_content_to_openai_part(\n    content: AudioContent,\n) -> ChatCompletionContentPartInputAudioParam:\n    \"\"\"Convert MCP AudioContent to OpenAI input_audio content part.\"\"\"\n    audio_format = _OPENAI_AUDIO_FORMATS.get(content.mime_type)\n    if audio_format is None:\n        raise ValueError(\n            f\"Unsupported audio MIME type for OpenAI: {content.mime_type!r}. \"","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py#L51-L87","documentation":"OpenAI's chat completions image input only supports a fixed set of image MIME types (png/jpeg/webp/gif per _OPENAI_IMAGE_MEDIA_TYPES). When converting MCP ImageContent, an unsupported mime_type raises ValueError listing the supported set.","triggerScenarios":"Client.sample() with ImageContent whose mime_type is e.g. 'image/tiff', 'image/bmp', 'image/svg+xml', or missing/nonstandard, routed to the OpenAI sampling handler via _convert_to_openai_messages -> _image_content_to_openai_part.","commonSituations":"Resources returning TIFF/BMP screenshots; SVG images from design tools; mime_type omitted or defaulted to something like application/octet-stream; models/providers (o1, some endpoints) that reject formats the library would otherwise allow.","solutions":["Convert the image to PNG or JPEG before sampling and set mime_type accordingly.","Use a different sampling handler (e.g. the google-genai or anthropic handler) that supports the format.","If the mime_type is missing, set it explicitly to 'image/png' or 'image/jpeg'.","Strip such ImageContent from the message list if it's not essential."],"exampleFix":"// before\nImageContent(type='image', data=raw_tiff_b64, mime_type='image/tiff')\n// after\nImageContent(type='image', data=png_b64, mime_type='image/png')","handlingStrategy":"validation","validationCode":"SUPPORTED = {'image/png', 'image/jpeg', 'image/webp', 'image/gif'}\nfor m in messages:\n    for c in getattr(m, 'content', []):\n        if getattr(c, 'type', None) == 'image' and c.mime_type not in SUPPORTED:\n            raise ValueError(f\"Convert {c.mime_type} to png/jpeg before OpenAI sampling\")","typeGuard":"def is_openai_supported_image(c) -> bool:\n    return getattr(c, 'type', None) == 'image' and c.mime_type in {'image/png','image/jpeg','image/webp','image/gif'}","tryCatchPattern":"try:\n    result = await client.sample(...)\nexcept ValueError as e:\n    if 'Unsupported image MIME type for OpenAI' in str(e):\n        messages = transcode_images_to_png(messages)\n        result = await client.sample(messages=messages, ...)\n    else:\n        raise","preventionTips":["Normalize all images to PNG/JPEG at ingestion time.","Always set an explicit mime_type on ImageContent.","Check target provider format support before routing sampling to OpenAI."],"tags":["openai","sampling","image","mime-type"],"backgroundTag":"unsupported-media-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}