xtekky/gpt4free · error · RateLimitError
{data['code']}:{data['details']}
Error message
{data['code']}:{data['details']} What it means
Raised as RateLimitError during Qwen's file registration step: the POST that registers filename/size/type returned success=false with code and details fields (raise_for_status passed, so HTTP was 2xx but the API refused). The embedded 'code:details' string names the upstream reason — commonly quota, file-type, or rate limits.
Source
Thrown at g4f/Provider/Qwen.py:334
file_name = file_name or f"file-{len(data_bytes)}{extension}"
file_size = len(data_bytes)
# Get File Url
async with session.post(
f"{cls.url}/api/v2/files/getstsToken",
json={
"filename": file_name,
"filesize": file_size,
"filetype": file_type,
},
headers=headers,
) as r:
await raise_for_status(r, "Create file failed")
res_data = await r.json()
data = res_data.get("data")
if res_data["success"] is False:
raise RateLimitError(f"{data['code']}:{data['details']}")
file_url = data.get("file_url")
file_id = data.get("file_id")
# Put File into Url
str_date = datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y%m%dT%H%M%SZ"
)
headers_put = get_oss_headers("PUT", str_date, data, file_type)
async with session.put(
file_url.split("?")[0], data=data_bytes, headers=headers_put
) as response:
await raise_for_status(response)
file_class: Literal["default", "vision", "video", "audio", "document"]
_type: Literal["file", "image", "video", "audio"]
show_type: Literal["file", "image", "video", "audio"]
if "image" in file_type:
_type = "image"
View on GitHub (pinned to 973504e177)
Solutions
- Read the embedded code:details — 'rate limit' means wait/retry; quota means clean up uploaded files on chat.qwen.ai or wait for reset.
- Reduce number/size of attachments per request.
- Retry after a delay; the outer loop invalidates state but file quota errors need time.
- Update g4f for current Qwen API behavior.
Example fix
# before
resp = await Qwen.create_async_generator(model, msgs, media=[('big.png', png_bytes), ('big2.png', png2_bytes)])
# after - one attachment, retry on RateLimitError
for attempt in range(3):
try:
resp = await Qwen.create_async_generator(model, msgs, media=[('big.png', png_bytes)])
break
except RateLimitError:
await asyncio.sleep(60) Defensive patterns
Strategy: retry
Validate before calling
from pathlib import Path
def qwen_file_ok(name: str, size: int) -> bool:
return Path(name).suffix.lower() in {'.png','.jpg','.jpeg','.pdf','.txt','.md'} and size <= 20*1024*1024 Try / catch
from g4f.errors import RateLimitError
try:
resp = await Qwen.create_async_generator(model, msgs, media=media)
except RateLimitError as e:
if 'file' in str(e).lower() or ':' in str(e):
await asyncio.sleep(120)
resp = await Qwen.create_async_generator(model, msgs, media=media)
else:
raise Prevention
- Limit attachments per request
- Wait out quota windows instead of immediate retries
- Read embedded code:details to separate quota vs rate-limit
- Clean up uploaded files on chat.qwen.ai periodically
When it happens
Trigger: Calling Qwen with media attachments when chat.qwen.ai's create-file API rejects the registration: free-tier file quota exhausted, too many uploads in a short window, unsupported file type, or invalid/expired cookies making the API refuse instead of 401.
Common situations: Repeated runs uploading the same files (quota accumulates); anonymous cookie jar (generate_cookies) flagged; large batches of media; g4f's OSS upload flow out of sync with API changes.
Related errors
- The Qwen provider reached the request limit after 5 attempts
- Failed to upload file: {res_json}
- Upload failed: {result}
- Response: {resp_json}
- {error["code"]}: {error["details"]}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/832939dd2ef360a4.
Report an issue: GitHub.