xtekky/gpt4free · critical · RateLimitError

The Qwen provider reached the limit Cloudflare.

Error message

The Qwen provider reached the limit Cloudflare.

What it means

Raised as RateLimitError when get_args_from_nodriver fails entirely (raises before the retry loop runs), meaning the browser-based bootstrap against chat.qwen.ai could not complete — typically because Aliyun WAF/Cloudflare blocked the browser itself. The message says 'Cloudflare' but per raise_for_status it is usually the Aliyun WAF ('aliyun_waf_aa') interstitial.

Source

Thrown at g4f/Provider/Qwen.py:730

                except (aiohttp.ClientResponseError, RuntimeError) as e:
                    is_rate_limit = (
                        isinstance(e, aiohttp.ClientResponseError) and e.status == 429
                    ) or ("RateLimited" in str(e))
                    if is_rate_limit:
                        debug.log(
                            f"[Qwen] WARNING: Rate limit detected (attempt {attempt + 1}/5). Invalidating current midtoken."
                        )
                        cls._midtoken = None
                        cls._midtoken_uses = 0
                        conversation = None
                        await asyncio.sleep(2)
                        continue
                    else:
                        raise e
            raise RateLimitError(
                "The Qwen provider reached the request limit after 5 attempts."
            )
        raise RateLimitError("The Qwen provider reached the limit Cloudflare.")

View on GitHub (pinned to 973504e177)

Solutions

  1. Verify Chrome launches under nodriver in your environment (install/update the browser, allow the sandbox).
  2. Use a residential proxy so the browser bootstrap is not WAF-blocked.
  3. Avoid concurrent first-calls; let one bootstrap complete and reuse the harvested args.
  4. Update g4f; bootstrap/WAF handling is patched frequently.

Example fix

# before
await asyncio.gather(*[Qwen.create_async_generator(model, m) for m in msgs])

# after - warm up once, then serialize
await Qwen.create_async_generator(model, [{'role':'user','content':'hi'}])  # bootstrap
for m in msgs:
    await Qwen.create_async_generator(model, m)
Defensive patterns

Strategy: validation

Validate before calling

import shutil

def qwen_bootstrap_possible() -> bool:
    """nodriver needs a Chrome/Chromium binary."""
    return any(shutil.which(b) for b in ('google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser'))

Type guard

def is_waf_bootstrap_failure(exc: Exception) -> bool:
    from g4f.errors import RateLimitError
    return isinstance(exc, RateLimitError) and 'Cloudflare' in str(exc)

Try / catch

from g4f.errors import RateLimitError
try:
    r = await Qwen.create_async_generator(model, msgs)
except RateLimitError as e:
    if 'Cloudflare' in str(e):
        r = await Qwen.create_async_generator(model, msgs, proxy=residential_proxy)  # fresh IP, new bootstrap
    else:
        raise

Prevention

When it happens

Trigger: The nodriver Chrome bootstrap failing: WAF challenge page served to the browser, nodriver/Chrome launch failure in the environment (missing browser, sandbox restrictions), or the callback timing out waiting for the baxia module.

Common situations: Docker/CI without a usable Chrome or with sandbox flags blocking launch; datacenter IP hard-blocked by Aliyun WAF; parallel Qwen calls racing browser bootstraps; outdated Chrome binary vs challenge requirements.

Related errors


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