xtekky/gpt4free · error · MissingAuthError

DeepSeekAuth: No authentication found. Please add a DeepSeek

Error message

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

What it means

MissingAuthError raised in DeepSeekAuth.create_async_generator when no cookies were passed explicitly and the fallback cookie jar lookup yields no (cookies + authorization header) pair. The message points at the remedy: import a DeepSeek HAR file containing an authorization token into har_and_cookies/.

Source

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

            cookies: Optional cookies
            proxy: Optional proxy
            conversation: JsonConversation object for continuing sessions
            web_search: Enable web search
            media: List of (file_bytes, filename) tuples for file upload
        """
        if not model:
            model = cls.default_model

        # Try to get auth from HAR file first
        if cookies is None:
            cookies = get_cookies(cls.cookie_domain, False)
            headers = get_headers(cls.cookie_domain)
            if cookies and headers.get("authorization"):
                debug.log(
                    f"DeepSeekAuth: Using {len(cookies)} cookies and {len(headers)} headers from cookie jar"
                )
            else:
                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(

View on GitHub (pinned to 973504e177)

Solutions

  1. Log in to chat.deepseek.com, record a HAR of a chat request, and save it under <g4f>/har_and_cookies/.
  2. Verify the HAR contains the authorization request header (inspect any /chat_session or completion request in DevTools' Network tab).
  3. Or pass cookies explicitly to create_async_generator if you manage sessions yourself.
  4. Update g4f if DeepSeek changed endpoints and the importer no longer extracts the token.

Example fix

# before
resp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs)
# MissingAuthError: ... add a DeepSeek HAR file ...

# after
# 1. browser DevTools -> Network -> send one chat on chat.deepseek.com
# 2. save HAR to ./har_and_cookies/deepseek.har
resp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

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

def deepseek_provider_ready():
    cookies = get_cookies(DeepSeek.cookie_domain, False)
    headers = get_headers(DeepSeek.cookie_domain)
    return bool(cookies and headers.get("authorization"))

if not deepseek_provider_ready():
    raise SystemExit("Import a DeepSeek HAR with authorization into har_and_cookies/")

Try / catch

try:
    resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs)
except MissingAuthError as e:
    if "HAR file" in str(e):
        guide_user_to_import_har()

Prevention

When it happens

Trigger: Invoking the DeepSeek provider without a cookies argument, with no HAR/cookie import present, or with an import whose headers lack "authorization". The nested condition requires both cookies and the auth header; missing either raises.

Common situations: First-time use of the authenticated DeepSeek provider; HAR file placed in the wrong directory; HAR captured before login so no bearer token; token-bearing request filtered out during export.

Understand the failure class

Related errors


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