xtekky/gpt4free · error · RateLimitError

{message}: {model}

Error message

{message}: {model}

What it means

Raised by raise_gemini_error() after mapping a Gemini error code (extracted from the response) through GEMINI_ERROR_MESSAGES. Codes 1037 and 1060 raise RateLimitError; every other code raises ResponseError. The message combines the human-readable code description with the model name, so the caller knows which model and which failure class is involved.

Solutions

  1. Match the message text against the code table in GEMINI_ERROR_MESSAGES to identify the exact code
  2. For 1037/1060 (RateLimitError): back off and retry after the quota window resets
  3. For other codes: fix the underlying cause (prompt content for safety codes, model name for not-found codes)
  4. Switch model or provider if the code indicates a permanent rejection
Defensive patterns

Strategy: retry

Try / catch

from g4f.errors import RateLimitError, ResponseError
try:
    result = await provider.create_async(model, messages)
except RateLimitError as e:
    # codes 1037/1060: quota window
    await asyncio.sleep(60)
    result = await provider.create_async(model, messages)
except ResponseError as e:
    # non-rate code: inspect message, do not blind-retry
    raise

Prevention

When it happens

Trigger: Calling a Gemini-based provider and receiving a response containing a structured error code (via extract_gemini_error_code) — e.g. quota/recursion (1037, 1060) or safety/policy rejection codes — triggering raise_gemini_error.

Common situations: Hitting Gemini free-tier quota limits, safety filters rejecting the prompt, model deprecation, or invalid model names routed through the Gemini API surface.

Related errors


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

Appendix: source

Thrown at g4f/Provider/needs_auth/gemini_utils.py:265

    if not isinstance(value, list):
        return None
    if value and value[0] == "wrb.fr":
        code = get_nested_value(value, [5, 2, 0, 1, 0])
        if isinstance(code, int):
            return code
    for item in value:
        code = extract_gemini_error_code(item)
        if code is not None:
            return code
    return None


def raise_gemini_error(code: int, model: str) -> None:
    message = GEMINI_ERROR_MESSAGES.get(
        code, f"Gemini rejected the request with error code {code}"
    )
    if code in (1037, 1060):
        raise RateLimitError(f"{message}: {model}")
    raise ResponseError(f"{message}: {model}")

View on GitHub (pinned to 973504e177)