xtekky/gpt4free · error · ValueError

Failed to get access token

Error message

Failed to get access token: {e}, refresh your cookies / log in into {cls.domain}

What it means

Raised as ValueError by Reka.get_access_token when the request to {url}/bff/auth/access_token fails or its JSON lacks 'accessToken'. Any exception (network error, non-200, JSON decode error, missing key) is wrapped in this message telling you to refresh cookies or log in again.

Solutions

  1. Log in to Reka again in the browser to refresh appSession, then retry
  2. Pass api_key directly so no token exchange is needed
  3. Check the proxy setting (cls.proxy) if the auth request itself is failing

Example fix

# before
response = client.chat.completions.create(model='reka-core', messages=msgs)  # Failed to get access token

# after
response = client.chat.completions.create(model='reka-core', messages=msgs, api_key=os.environ['REKA_API_KEY'])
Defensive patterns

Strategy: fallback

Try / catch

try:
    result = ...create(...)
except ValueError as e:
    if 'Failed to get access token' in str(e):
        result = ...create(..., api_key=os.environ['REKA_API_KEY'])
    else:
        raise

Prevention

When it happens

Trigger: Reka auth endpoint rejects the appSession cookie (expired/revoked), the request fails through the proxy, or the response body is not the expected JSON — the except Exception catches all of it.

Common situations: appSession cookie expired since login, Reka changed its BFF auth route, proxy blocking the auth request, rate-limited token endpoint.

Related errors


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

Appendix: source

Thrown at g4f/Provider/needs_auth/Reka.py:169

            "sec-ch-ua-platform": '"macOS"',
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
        }

        try:
            response = requests.get(
                f"{cls.url}/bff/auth/access_token",
                cookies=cls.cookies,
                headers=headers,
                proxies=cls.proxy,
            )

            return response.json()["accessToken"]

        except Exception as e:
            raise ValueError(
                f"Failed to get access token: {e}, refresh your cookies / log in into {cls.domain}"
            )

View on GitHub (pinned to 973504e177)