xtekky/gpt4free · error · ValueError

Invalid image format (from mime file type).

Error message

Invalid image format (from mime file type).

What it means

Error "Invalid image format (from mime file type)." thrown in xtekky/gpt4free.

Source

Thrown at g4f/image/__init__.py:243

    """
    Checks if the given data URI represents an image.

    Args:
        data_uri (str): The data URI to check.

    Raises:
        ValueError: If the data URI is invalid or the image format is not allowed.
    """
    if data_uri.startswith("https:") or data_uri.startswith("http:"):
        return True
    # Check if the data URI starts with 'data:image' and contains an image format (e.g., jpeg, png, gif)
    if not re.match(r"data:image/(\w+);base64,", data_uri):
        raise ValueError(f"Invalid data URI image. {data_uri[:10]}...")
    # Extract the image format from the data URI
    image_format = re.match(r"data:image/(\w+);base64,", data_uri).group(1).lower()
    # Check if the image format is one of the allowed formats (jpg, jpeg, png, gif)
    if image_format not in EXTENSIONS_MAP and image_format != "svg+xml":
        raise ValueError("Invalid image format (from mime file type).")
    return True


def is_accepted_format(binary_data: bytes) -> str:
    """
    Checks if the given binary data represents an image with an accepted format.

    Args:
        binary_data (bytes): The binary data to check.

    Raises:
        ValueError: If the image format is not allowed.
    """
    if binary_data.startswith(b"\xFF\xD8\xFF"):
        return "image/jpeg"
    elif binary_data.startswith(b"\x89PNG\r\n\x1a\n"):
        return "image/png"
    elif binary_data.startswith(b"GIF87a") or binary_data.startswith(b"GIF89a"):

View on GitHub (pinned to 973504e177)

Solutions

  1. Provide an image with a recognized mime type (png, jpeg, gif, webp).
  2. Check that the file content is a valid image.

When it happens

Trigger: Thrown at g4f/image/__init__.py:243 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/6f2b1c138e024b16. Report an issue: GitHub.