xtekky/gpt4free · error · MissingAuthError

DeepSeekAuth: Authorization token required. Please ensure HA

Error message

DeepSeekAuth: Authorization token required. Please ensure HAR file contains authorization header.

What it means

MissingAuthError raised in DeepSeekAuth.create_async_generator after the cookie check passed but no bearer token could be resolved: authorization is taken from the stored headers' "authorization" entry, or from a reused conversation object that carries an authorization attribute. If both are empty the chat-completion request cannot be signed, so the provider aborts before the POST.

Source

Thrown at g4f/Provider/needs_auth/DeepSeek.py:417

                raise MissingAuthError(
                    "DeepSeekAuth: No authentication found. "
                    "Please add a DeepSeek HAR file to har_and_cookies/ directory "
                    "with an authorization token."
                )

        # Initialize conversation if needed
        if conversation is None:
            conversation = JsonConversation(parent_message_id=None)

        # Get auth token from HAR data or conversation
        authorization = None
        if headers:
            authorization = headers.get("authorization")
        elif hasattr(conversation, "authorization"):
            authorization = conversation.authorization

        if not authorization:
            raise MissingAuthError(
                "DeepSeekAuth: Authorization token required. "
                "Please ensure HAR file contains authorization header."
            )

        headers = {
            "accept": "*/*",
            "accept-language": "en-US,en;q=0.9",
            "cache-control": "no-cache",
            "content-type": "application/json",
            "origin": cls.url,
            "referer": f"{cls.url}/",
            "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
            "x-app-version": "20241129.1",
            "x-client-locale": "en_US",
            "x-client-platform": "web",
            "x-client-timezone-offset": "-28800",
            "x-client-version": "1.7.0",
            "authorization": authorization,

View on GitHub (pinned to 973504e177)

Solutions

  1. Re-capture the HAR while actually sending a chat completion so the authorization: Bearer ... request header is included.
  2. When persisting conversations for reuse, store the authorization token on the conversation object so later calls can resume.
  3. Refresh the HAR periodically — DeepSeek bearer tokens expire faster than cookies.
  4. Update g4f to the latest version in case the token endpoint changed.

Example fix

# before
# HAR contains cookies only -> MissingAuthError: Authorization token required

# after
# in DevTools: capture the POST to /chat/v1/completion and export that HAR
# headers now include: authorization: Bearer <token>
resp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

from g4f.requests import get_headers
from g4f.Provider.needs_auth.DeepSeek import DeepSeek

def deepseek_token_present():
    return bool(get_headers(DeepSeek.cookie_domain).get("authorization"))

Try / catch

try:
    resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs)
except MissingAuthError as e:
    if "Authorization token required" in str(e):
        refresh_har_with_token()

Prevention

When it happens

Trigger: Authenticating with a HAR that has cookies but no authorization header, or resuming with a conversation object that was created without capturing its authorization field. Distinct from error 132: this fires when cookies exist but the token specifically is absent.

Common situations: Partial HAR exports (cookies only); DeepSeek session token expired and dropped from storage; conversation persistence that serializes ids but not the token; auth flow changed by DeepSeek so the header never appears.

Related errors


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