xtekky/gpt4free · error · RateLimitError
The Qwen provider reached the request limit after 5 attempts
Error message
The Qwen provider reached the request limit after 5 attempts.
What it means
Raised as RateLimitError when Qwen's internal retry loop (5 attempts, 2s sleeps, midtoken invalidation each time) still encounters rate-limit failures — every attempt was a 429 ClientResponseError or a RuntimeError containing 'RateLimited'. The provider gives up rather than loop forever; only ~10s of backoff has elapsed, so the underlying limit is still in force.
Source
Thrown at g4f/Provider/Qwen.py:727
yield Usage.from_dict(usage)
return
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
- Wait minutes-to-hours before retrying (quota windows), not seconds — the 5x2s internal backoff is far too short for hard limits.
- Change egress IP / rotate proxy so the IP-based component resets.
- Reduce request frequency and concurrency to stay under the free tier.
- Update g4f; retry cadence and identity handling are tuned upstream.
Example fix
# before
for i in range(100):
r = await Qwen.create_async_generator(model, msgs[i])
# after
from g4f.errors import RateLimitError
for i in range(100):
while True:
try:
r = await Qwen.create_async_generator(model, msgs[i])
break
except RateLimitError:
await asyncio.sleep(600) # wait out the quota window Defensive patterns
Strategy: retry
Type guard
def is_qwen_rate_limit(exc: Exception) -> bool:
from g4f.errors import RateLimitError
return isinstance(exc, RateLimitError) and 'request limit after 5 attempts' in str(exc) Try / catch
from g4f.errors import RateLimitError
try:
r = await Qwen.create_async_generator(model, msgs)
except RateLimitError as e:
if 'after 5 attempts' in str(e):
await asyncio.sleep(600) # quota window, not 2s
r = await Qwen.create_async_generator(model, msgs)
else:
raise Prevention
- Wait minutes-to-hours after this error; internal 5x2s backoff is insufficient
- Rotate proxy IP to reset IP-based throttling
- Throttle your own request rate below the free tier
- Don't retry in a tight loop — you re-exhaust all 5 attempts instantly
When it happens
Trigger: Sustained 429s from chat.qwen.ai: free-tier hourly/daily quota exhausted, IP-based throttling, or bursts of requests from one cookie identity across all 5 attempts.
Common situations: Bots hammering Qwen anonymously; quota already spent before this call; shared/datacenter IP throttled; retrying immediately after this error without waiting, re-entering the same loop.
Related errors
- {data['code']}:{data['details']}
- Response: {resp_json}
- {error["code"]}: {error["details"]}
- The Qwen provider reached the limit Cloudflare.
- {chunk_text}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/6c393b84c1d6ba04.
Report an issue: GitHub.