xtekky/gpt4free · error · ImportError

MarkItDown is not installed. Please install it with `pip ins

Error message

MarkItDown is not installed. Please install it with `pip install markitdown`.

What it means

ImportError from MarkItDown when media was provided but the optional markitdown package isn't installed (has_markitdown is False, which also sets working=False). The dependency check deliberately comes after the media check so callers get the most specific error first.

Source

Thrown at g4f/Provider/audio/MarkItDown.py:28

except ImportError:
    has_markitdown = False

from ...typing import AsyncResult, Messages, MediaListType
from ...tools.files import get_tempfile
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin


class MarkItDown(AsyncGeneratorProvider, ProviderModelMixin):
    working = has_markitdown

    @classmethod
    async def create_async_generator(
        cls, model: str, messages: Messages, media: MediaListType = None, **kwargs
    ) -> AsyncResult:
        if media is None:
            raise ValueError("MarkItDown requires media to be provided.")
        if not has_markitdown:
            raise ImportError(
                "MarkItDown is not installed. Please install it with `pip install markitdown`."
            )
        md = MaItDo()
        for file, filename in media:
            text = None
            try:
                if isinstance(file, str) and file.startswith(("http://", "https://")):
                    result = md.convert_url(file)
                else:
                    result = md.convert(
                        file,
                        stream_info=StreamInfo(filename=filename) if filename else None,
                    )
                if asyncio.iscoroutine(result.text_content):
                    text = await result.text_content
                else:
                    text = result.text_content
            except TypeError:

View on GitHub (pinned to 973504e177)

Solutions

  1. pip install markitdown
  2. Add markitdown to the deployment's dependency list if document conversion is used
  3. Check provider.working / has_markitdown before routing requests to MarkItDown
  4. Update g4f in case the import shim was fixed upstream

Example fix

# before
# ImportError: MarkItDown is not installed
resp = await client.chat.completions.create(model='MarkItDown', messages=msgs, media=media)

# after (shell)
# pip install markitdown
Defensive patterns

Strategy: validation

Validate before calling

from g4f.Provider.audio.MarkItDown import has_markitdown

if not has_markitdown:
    raise RuntimeError('run: pip install markitdown')  # fail fast with actionable msg

Try / catch

try:
    ...  # MarkItDown call with media
except ImportError as e:
    if 'markitdown' in str(e):
        disable_markitdown_feature()

Prevention

When it happens

Trigger: Calling MarkItDown with media on an environment where 'pip install markitdown' was never run; note the source also hints at a typo risk — the constructor used is MaItDo(), which must resolve to the MarkItDown class.

Common situations: Base g4f install without document-conversion extras; slim containers; new machines provisioned from a partial requirements list.

Related errors


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