xtekky/gpt4free · error · ModelNotFoundError

Model is not supported: {model} in: {cls.__name__} task: {ta

Error message

Model is not supported: {model} in: {cls.__name__} task: {task}

What it means

Raised inside HuggingFaceMedia's generate() loop when a mapped provider's returned "task" field (e.g. text-to-image, text-to-video) is not in the provider class's supported tasks set. ModelNotFoundError with the task appended: the model exists on the router, but this g4f provider cannot handle the task type it is served under.

Source

Thrown at g4f/Provider/needs_auth/hf/HuggingFaceMedia.py:184

        async def generate(extra_body: dict, aspect_ratio: str = None):
            last_response = None
            for provider_key, provider in provider_mapping.items():
                if selected_provider is not None and selected_provider != provider_key:
                    continue
                provider_info = ProviderInfo(
                    **{
                        **cls.get_dict(),
                        "label": f"HuggingFace ({provider_key})",
                        "url": f"{cls.url}/{model}",
                    }
                )

                base_url = f"https://router.huggingface.co/{provider_key}"
                task = provider["task"]
                provider_id = provider["providerId"]
                if task not in cls.tasks:
                    raise ModelNotFoundError(
                        f"Model is not supported: {model} in: {cls.__name__} task: {task}"
                    )

                if aspect_ratio is None:
                    aspect_ratio = "1:1" if task == "text-to-image" else "16:9"
                extra_body_image = use_aspect_ratio(
                    {
                        **extra_body,
                        "height": height,
                        "width": width,
                    },
                    aspect_ratio,
                )
                extra_body_video = {}
                if task == "text-to-video" and provider_key != "novita":
                    extra_body_video = {
                        "num_inference_steps": 20,
                        "resolution": resolution,

View on GitHub (pinned to 973504e177)

Solutions

  1. Read the task in the message — use a model/provider combination whose task matches what you want
  2. Update g4f to gain support for newly added router task types
  3. Select the provider explicitly via 'model:provider_key' syntax to skip incompatible entries
  4. Choose a different model that is served under a supported task

Example fix

# before
model = 'some-model'  # only served as text-to-video
# after
model = 'some-model:hf-inference'  # pick a provider entry with a supported task
Defensive patterns

Strategy: validation

Validate before calling

mapping = await HuggingFaceMedia.get_mapping(model, api_key)
tasks = {p['task'] for p in mapping.values()}
if not tasks & set(HuggingFaceMedia.tasks):
    raise ValueError(f'{model} only served under tasks {tasks}')

Try / catch

from g4f.errors import ModelNotFoundError
try:
    ...
except ModelNotFoundError as e:
    if 'task:' in str(e):
        model = pick_model_for_task(HuggingFaceMedia.get_models(), wanted_task)
        ...

Prevention

When it happens

Trigger: A provider entry in the router mapping reports a task (e.g. text-to-video on a model you called as an image model, or a new task type) that HuggingFaceMedia.tasks does not include.

Common situations: Calling an image model whose only provider serves a different task; HuggingFace adds a new task label (e.g. image-to-video) unsupported by the installed g4f version.

Related errors


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