xtekky/gpt4free · error · NoValidHarFileError

No valid Blackbox session found. Please log in to Blackbox A

Error message

No valid Blackbox session found. Please log in to Blackbox AI in your browser first.

What it means

Raised as NoValidHarFileError by g4f/Provider/needs_auth/BlackboxPro.py when the provider cannot obtain a Blackbox session: the cached cls.session_data is empty and the GET to https://www.blackbox.ai/api/auth/session (made with cookies from get_cookies(cls.cookie_domain, False)) returned an empty/falsey JSON body. In practice this means no usable Blackbox login cookies or HAR file exist, so the /api/auth/session endpoint reported no authenticated user.

Source

Thrown at g4f/Provider/needs_auth/BlackboxPro.py:2723

                    "title": "",
                }

            # Get session data from HAR files
            cls.session_data = cls._find_session_in_har_files() or cls.session_data

            if not cls.session_data:
                async with session.get(
                    "https://www.blackbox.ai/api/auth/session",
                    cookies=get_cookies(cls.cookie_domain, False),
                ) as resp:
                    resp.raise_for_status()
                    cls.session_data = await resp.json()

            # Check if we have a valid session
            if not cls.session_data:
                # No valid session found, raise an error
                debug.log("BlackboxPro: No valid session found in HAR files")
                raise NoValidHarFileError(
                    "No valid Blackbox session found. Please log in to Blackbox AI in your browser first."
                )

            debug.log(
                f"BlackboxPro: Using session from cookies / HAR file (email: {cls.session_data['user'].get('email', 'unknown')})"
            )

            # Check subscription status
            subscription_status = {
                "status": "FREE",
                "customerId": None,
                "isTrialSubscription": False,
                "lastChecked": None,
            }
            if cls.session_data.get("user", {}).get("email"):
                subscription_status = await cls.check_subscription(
                    cls.session_data["user"]["email"]
                )

View on GitHub (pinned to 973504e177)

Solutions

  1. Log in to Blackbox AI (blackbox.ai) in your browser, then export the session cookies / a HAR file into g4f's har_and_cookies directory so get_cookies(cls.cookie_domain) returns valid auth cookies.
  2. Verify the exported HAR actually contains a successful request to /api/auth/session with a non-empty JSON body containing a user object.
  3. Re-export cookies if they are old — Blackbox sessions expire.
  4. Retry after confirming the cookie_domain matches the domain you logged into (e.g. no www vs bare-domain mismatch).

Example fix

# before
response = await client.chat.completions.create(model="", provider=BlackboxPro, messages=msgs)
# NoValidHarFileError: No valid Blackbox session found...

# after
# 1. log in to blackbox.ai in your browser
# 2. copy the exported har/cookies file into <g4f>/har_and_cookies/
response = await client.chat.completions.create(model="", provider=BlackboxPro, messages=msgs)
Defensive patterns

Strategy: try-catch

Validate before calling

from g4f.requests import get_cookies
from g4f.Provider.needs_auth.BlackboxPro import BlackboxPro

def blackbox_session_available():
    return bool(BlackboxPro.session_data) or bool(get_cookies(BlackboxPro.cookie_domain, False))

Try / catch

try:
    result = await client.chat.completions.create(model="", provider=BlackboxPro, messages=msgs)
except NoValidHarFileError:
    prompt_user_to_import_har("blackbox.ai")
except Exception:
    raise

Prevention

When it happens

Trigger: Calling BlackboxPro.create_async_generator (directly or via g4f client) with cls.session_data unset, no blackbox.ai cookies in the cookie jar / HAR files, or cookies belonging to a logged-out session so that the auth/session response is empty. resp.raise_for_status() passes (HTTP 200) but the body is empty.

Common situations: Fresh install with no Blackbox HAR file in har_and_cookies/; user never logged in to blackbox.ai; exported cookies from an incognito/logged-out profile; Blackbox changed its session payload shape so the parsed JSON is empty.

Related errors


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