{"record":{"id":"436dcd1479f5c7ef","repo":"xtekky/gpt4free","slug":"unsupported-media-type-content-type","errorCode":null,"errorMessage":"Unsupported media type: {content_type}","messagePattern":"Unsupported media type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/image/copy_images.py","lineNumber":90,"sourceCode":"    transcript: str = None,\n    content_type: str = None,\n) -> AsyncIterator:\n    \"\"\"Save media from response to local file and return a response object.\"\"\"\n    if isinstance(response, dict):\n        content_type = response.get(\"mimeType\", content_type or \"audio/mpeg\")\n        transcript = response.get(\"transcript\")\n        response = response.get(\"data\")\n    elif hasattr(response, \"headers\"):\n        content_type = response.headers.get(\"content-type\", content_type)\n    elif not content_type:\n        raise ValueError(\"Response must be a dict or have headers\")\n\n    if isinstance(response, str):\n        response = base64.b64decode(response)\n\n    extension = MEDIA_TYPE_MAP.get(content_type)\n    if extension is None:\n        raise ValueError(f\"Unsupported media type: {content_type}\")\n\n    filename = get_filename(tags, prompt, f\".{extension}\", prompt)\n    if hasattr(response, \"headers\"):\n        filename = update_filename(response, filename)\n    target_path = os.path.join(get_media_dir(), filename)\n    ensure_media_dir()\n\n    with open(target_path, \"wb\") as f:\n        if isinstance(response, bytes):\n            f.write(response)\n        else:\n            if hasattr(response, \"iter_content\"):\n                iter_response = response.iter_content()\n            else:\n                iter_response = response.content.iter_any()\n            async for chunk in iter_response:\n                f.write(chunk)\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/image/copy_images.py#L72-L108","documentation":"Thrown by g4f.image.copy_media() when the resolved content_type (from a dict's 'mimeType', the response's content-type header, or the content_type parameter) has no entry in MEDIA_TYPE_MAP, the extension lookup built from EXTENSIONS_MAP (plus audio/webm). The function refuses to save a file whose extension it cannot determine.","triggerScenarios":"content_type='audio/mp4' or 'video/x-matroska' or an image type with parameters like 'image/png; charset=utf-8' — any string not exactly a key in g4f.image.MEDIA_TYPE_MAP.","commonSituations":"Servers sending unusual or parameterized Content-Type headers; providers returning mimeTypes like 'audio/aac' or 'audio/ogg' that the map does not include; copy-pasting a type with trailing whitespace or quotes.","solutions":["Normalize the type before calling: strip parameters via content_type.split(';')[0].strip() and check membership in g4f.image.MEDIA_TYPE_MAP.","Use one of the mapped types: audio/mpeg, audio/wav, audio/ogg, audio/webm, image/png, image/jpeg, image/webp, video/mp4, etc. (keys of EXTENSIONS_MAP reversed).","If the format is genuinely needed, convert the media to a mapped container first (e.g. pydub for audio)."],"exampleFix":"// before\nawait copy_media(data, content_type=resp.headers['content-type'])  # 'audio/mpeg; charset=binary'\n\n// after\nmime = resp.headers['content-type'].split(';')[0].strip()\nawait copy_media(data, content_type=mime)","handlingStrategy":"validation","validationCode":"from g4f.image.copy_images import MEDIA_TYPE_MAP\n\ndef supported_content_type(ct: str) -> bool:\n    return ct is not None and ct.split(\";\")[0].strip() in MEDIA_TYPE_MAP","typeGuard":null,"tryCatchPattern":"try:\n    await copy_media(data, content_type=ct, prompt=p, tags=t)\nexcept ValueError as e:\n    if \"Unsupported media type\" in str(e):\n        ct = \"application/octet-stream\"  # only if copy_media callers tolerate magic-detection paths\n    raise","preventionTips":["Strip Content-Type parameters ('; charset=...') before passing.","Check membership in g4f.image.MEDIA_TYPE_MAP before calling copy_media."],"tags":["media","content-type","validation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}