xtekky/gpt4free · error · RateLimitError

Ratelimit Exceeded!

Error message

Ratelimit Exceeded!

What it means

RateLimitError raised by the Airforce provider while relaying the upstream OpenAI-compatible stream: it buffers incoming string chunks and checks whether the accumulated text contains 'Ratelimit Exceeded!' — api.airforce signals throttling by streaming that literal string instead of an HTTP 429. Because the check matches on the message appearing mid-stream, the error fires the moment the phrase is complete; partial prefixes of it are held back instead of yielded.

Source

Thrown at g4f/Provider/needs_auth/Airforce.py:32

    active_by_default = True
    use_image_size = True
    default_model = "gpt-4o-mini"

    @classmethod
    async def create_async_generator(
        cls, model: str, messages: Messages = None, **kwargs
    ) -> AsyncResult:
        ratelimit_message = "Ratelimit Exceeded!"
        buffer = ""
        async for chunk in super().create_async_generator(
            model=model, messages=messages, **kwargs
        ):
            if not isinstance(chunk, str):
                yield chunk
                continue
            buffer += chunk
            if ratelimit_message in buffer:
                raise RateLimitError(ratelimit_message)
            if ratelimit_message.startswith(buffer):
                continue
            yield buffer
            buffer = ""

View on GitHub (pinned to 973504e177)

Solutions

  1. Back off and retry after a delay (start ~30–60s) — the throttle is usually time-window based.
  2. Reduce request concurrency/frequency against api.airforce.
  3. Get an api_key from the Airforce panel (login_url https://panel.api.airforce/dashboard) for higher limits.
  4. Catch RateLimitError in your loop and switch to a fallback provider for the duration of the throttle.

Example fix

# before
for chunk in await Airforce.create_async_generator(model=model, messages=messages):
    print(chunk, end="")

# after
from g4f.errors import RateLimitError
try:
    async for chunk in Airforce.create_async_generator(model=model, messages=messages):
        print(chunk, end="")
except RateLimitError:
    await asyncio.sleep(60)  # then retry or fail over
Defensive patterns

Strategy: retry

Try / catch

from g4f.errors import RateLimitError
for attempt in range(5):
    try:
        async for chunk in Airforce.create_async_generator(model=model, messages=messages):
            ...
        break
    except RateLimitError:
        await asyncio.sleep(2 ** attempt * 15)  # exponential backoff, then fail over

Prevention

When it happens

Trigger: Calling any Airforce model after exceeding api.airforce's request-rate or token quota: the HTTP response is 200 and the SSE stream opens normally, but the delta content is the literal 'Ratelimit Exceeded!' string; bursty parallel requests from one IP; free-tier daily caps.

Common situations: Hammering api.airforce in a loop or with concurrent workers; shared/datacenter IPs already throttled; free-tier quota exhaustion mid-session.

Related errors


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