xtekky/gpt4free · warning · ValueError

Prompt cannot be empty.

Error message

Prompt cannot be empty.

What it means

Raised as ValueError by the Video provider when format_media_prompt(messages, prompt) truncates/normalizes to an empty string (encode to 100 bytes, decode, strip). If the user messages contain no usable text and no explicit prompt was given, there is nothing to search videos with.

Source

Thrown at g4f/Provider/needs_auth/Video.py:157

    @classmethod
    async def create_async_generator(
        cls, model: str, messages: Messages, prompt: str = None, **kwargs
    ) -> AsyncResult:
        if not model:
            model = cls.default_model
        if model not in cls.video_models:
            raise ValueError(
                f"Model '{model}' is not supported by {cls.__name__}. Supported models: {cls.models}"
            )
        yield ProviderInfo(**cls.get_dict(), model=model)
        prompt = (
            format_media_prompt(messages, prompt)
            .encode()[:100]
            .decode("utf-8", "ignore")
            .strip()
        )
        if not prompt:
            raise ValueError("Prompt cannot be empty.")
        prompt = await RequestConfig.translate_prompt(prompt)
        response = await RequestConfig.get_response(prompt, model == "search")
        if response:
            yield Reasoning(label=f"Found {len(response.urls)} Video(s)", status="")
            yield response
            return
        raise RuntimeError("Failed to find any videos for the prompt.")

View on GitHub (pinned to 973504e177)

Solutions

  1. Pass a non-empty prompt argument describing the desired video
  2. Ensure the user message contains actual text content, not just attachments

Example fix

# before
response = client.chat.completions.create(model='search', messages=[{'role':'user','content':''}], provider=g4f.Provider.Video)

# after
response = client.chat.completions.create(model='search', messages=[{'role':'user','content':''}], prompt='ocean waves at sunset', provider=g4f.Provider.Video)
Defensive patterns

Strategy: validation

Validate before calling

from g4f.Provider.helper import format_media_prompt
if not (prompt or format_media_prompt(messages, None)).strip():
    raise ValueError('Provide a text prompt for video search')

Type guard

def has_video_prompt(messages, prompt: str | None) -> bool:
    text = prompt or ' '.join(m.get('content', '') for m in messages if isinstance(m.get('content'), str))
    return bool(text.strip())

Try / catch

try:
    result = ...create(..., provider=g4f.Provider.Video)
except ValueError as e:
    if 'empty' in str(e):
        skip_video_enrichment()
    else:
        raise

Prevention

When it happens

Trigger: Messages consist solely of media/empty content, or the first 100 bytes decode to whitespace only, and no prompt argument was passed.

Common situations: Sending image-only messages to a video search provider, prompt argument accidentally empty string, whitespace-only user content.

Related errors


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