xtekky/gpt4free · error · ValueError

Prompt is empty.

Error message

Prompt is empty.

What it means

ValueError from ElevenLabs.create_async_generator when there is no text to synthesize: get_last_message(messages, prompt) returned empty. Like all TTS providers, the audio path requires the source text.

Source

Thrown at g4f/Provider/audio/ElevenLabs.py:65

    model_id = "elevenlabs-tts"
    default_model = "eleven_v3"
    default_voice = "tS45q0QcrDHqHoaWdCDR"
    default_format = "mp3_44100_128"
    default_language = "pt"

    @classmethod
    async def create_async_generator(
        cls,
        model: str,
        messages: Messages,
        prompt: str = None,
        audio: dict = {},
        proxy: str = None,
        **kwargs,
    ) -> AsyncResult:
        prompt = get_last_message(messages, prompt)
        if not prompt:
            raise ValueError("Prompt is empty.")

        voice = audio.get("voice", cls.default_voice)
        model_id = audio.get("model", cls.default_model)
        output_format = audio.get("format", cls.default_format)
        language = audio.get("language", cls.default_language)

        # hcaptcha accessibility cookie — kwarg, then browser cookie store
        cookie_val = kwargs.get("hc_accessibility")
        if not cookie_val:
            cookie_val = get_cookies(
                ".hcaptcha.com", raise_requirements_error=False
            ).get("hc_accessibility")
        if not cookie_val:
            raise RuntimeError(
                "hCaptcha accessibility cookie required: log in at "
                "https://dashboard.hcaptcha.com/signup?type=accessibility "
                'in your browser, or pass hc_accessibility="...".'
            )

View on GitHub (pinned to 973504e177)

Solutions

  1. Pass prompt='text to speak' explicitly
  2. Ensure the last message in messages has non-empty content
  3. Strip and validate text before calling the audio endpoint

Example fix

# before
resp = await client.speech.create(model='ElevenLabs', text='   ')

# after
resp = await client.speech.create(model='ElevenLabs', text=text.strip()) if text.strip() else None
Defensive patterns

Strategy: validation

Validate before calling

text = (prompt or '').strip() or last_message_content(messages)
if not text:
    raise ValueError('ElevenLabs: nothing to synthesize')

Try / catch

except ValueError as e:
    if 'Prompt is empty' in str(e):
        return None  # empty input is expected in optional-TTS flows

Prevention

When it happens

Trigger: Invoking ElevenLabs audio generation with empty messages and no prompt kwarg.

Common situations: Chained pipelines where an upstream step produced empty text; whitespace-only strings; forwarded chat state with no user message.

Related errors


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