xtekky/gpt4free · error · MissingAuthError
Ollama session cookie is invalid or expired.
Error message
Ollama session cookie is invalid or expired.
What it means
MissingAuthError raised by the Ollama cloud provider while scraping the ollama.com account settings page (to read quota usage): the fetched HTML looks like a sign-in form — the code heuristically detects combinations of a form tag with password/email inputs or auth endpoints (has_sign_in/has_form/has_password/has_email/has_auth_endpoint). Receiving a login page instead of the settings page means the session cookie is missing, invalid, or expired.
Source
Thrown at g4f/Provider/local/Ollama.py:77
or "/auth/signin" in lower
or 'href="/signin"' in lower
or 'href="/login"' in lower
)
has_form = "<form" in lower
has_password = (
'type="password"' in lower or 'name="password"' in lower
)
has_email = 'type="email"' in lower or 'name="email"' in lower
if (
(
has_sign_in
and has_form
and (has_email or has_password or has_auth_endpoint)
)
or (has_form and has_auth_endpoint)
or (has_form and has_password and has_email)
):
raise MissingAuthError(
"Ollama session cookie is invalid or expired."
)
for label in ("Session usage", "Hourly usage", "Weekly usage"):
idx = html.find(label)
if idx == -1:
continue
section = html[idx + len(label) : idx + len(label) + 800]
pct_match = re.search(r"(\d+(?:\.\d+)?)%\s*used", section)
if not pct_match:
width_match = re.search(
r"width:\s*(\d+(?:\.\d+)?)%", section
)
if width_match:
pct_match = width_match
pct = float(pct_match.group(1)) if pct_match else None
reset_match = re.search(
r'data-time=["\']([^"\']+)["\']', section
)View on GitHub (pinned to 973504e177)
Solutions
- Log in to ollama.com in a browser, copy the fresh session cookie, and update the stored credential used by AuthManager (set the Ollama api_key/cookie again).
- Verify the cookie works outside g4f: curl -s -H 'Cookie: <cookie>' https://ollama.com/settings should show the settings page, not a login form.
- If ollama.com changed its markup/flow, update the provider (or g4f) to the new auth/quota surface.
Defensive patterns
Strategy: validation
Validate before calling
import requests
r = requests.get('https://ollama.com/settings', cookies={'session': cookie})
if 'sign in' in r.text.lower() or r.url.endswith('/login'):
raise SystemExit('Ollama session cookie expired — refresh it') Try / catch
try:
quota = await Ollama.get_quota(...)
except MissingAuthError:
# re-prompt user for a fresh ollama.com session cookie
... Prevention
- Verify the session cookie against ollama.com/settings before batch runs.
- Refresh cookies on a schedule — web sessions expire.
- Catch MissingAuthError separately from parse errors so re-auth is unambiguous.
When it happens
Trigger: Calling Ollama methods that scrape ollama.com (quota/settings endpoints) with an api_key/session cookie that ollama.com no longer accepts; the cookie expired (sessions are time-limited); the AuthManager returned a placeholder/empty cookie; or ollama.com changed its auth flow so a valid cookie still redirects to a login page.
Common situations: Using an Ollama web session cookie copied weeks earlier; rotating cookies after password changes/logging out in the browser; ollama.com shipping a redesigned login/settings flow that trips the form heuristics even when authenticated.
Related errors
- Invalid secrets
- No appSession found in cookies for {cls.domain}, log in or p
- Invalid response: {last_msg}
- Failed to obtain Turnstile token for DeepInfra request.
- No response
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/76f2e29e28410f58.
Report an issue: GitHub.