{"record":{"id":"494feb6f120acf13","repo":"xtekky/gpt4free","slug":"deepseekauth-authorization-token-required-please","errorCode":null,"errorMessage":"DeepSeekAuth: Authorization token required. Please ensure HAR file contains authorization header.","messagePattern":"DeepSeekAuth: Authorization token required\\. Please ensure HAR file contains authorization header\\.","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/DeepSeek.py","lineNumber":417,"sourceCode":"                raise MissingAuthError(\n                    \"DeepSeekAuth: No authentication found. \"\n                    \"Please add a DeepSeek HAR file to har_and_cookies/ directory \"\n                    \"with an authorization token.\"\n                )\n\n        # Initialize conversation if needed\n        if conversation is None:\n            conversation = JsonConversation(parent_message_id=None)\n\n        # Get auth token from HAR data or conversation\n        authorization = None\n        if headers:\n            authorization = headers.get(\"authorization\")\n        elif hasattr(conversation, \"authorization\"):\n            authorization = conversation.authorization\n\n        if not authorization:\n            raise MissingAuthError(\n                \"DeepSeekAuth: Authorization token required. \"\n                \"Please ensure HAR file contains authorization header.\"\n            )\n\n        headers = {\n            \"accept\": \"*/*\",\n            \"accept-language\": \"en-US,en;q=0.9\",\n            \"cache-control\": \"no-cache\",\n            \"content-type\": \"application/json\",\n            \"origin\": cls.url,\n            \"referer\": f\"{cls.url}/\",\n            \"user-agent\": \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36\",\n            \"x-app-version\": \"20241129.1\",\n            \"x-client-locale\": \"en_US\",\n            \"x-client-platform\": \"web\",\n            \"x-client-timezone-offset\": \"-28800\",\n            \"x-client-version\": \"1.7.0\",\n            \"authorization\": authorization,","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/DeepSeek.py#L399-L435","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-capture the HAR while actually sending a chat completion so the authorization: Bearer ... request header is included.","When persisting conversations for reuse, store the authorization token on the conversation object so later calls can resume.","Refresh the HAR periodically — DeepSeek bearer tokens expire faster than cookies.","Update g4f to the latest version in case the token endpoint changed."],"exampleFix":"# before\n# HAR contains cookies only -> MissingAuthError: Authorization token required\n\n# after\n# in DevTools: capture the POST to /chat/v1/completion and export that HAR\n# headers now include: authorization: Bearer <token>\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs)","handlingStrategy":"validation","validationCode":"from g4f.requests import get_headers\nfrom g4f.Provider.needs_auth.DeepSeek import DeepSeek\n\ndef deepseek_token_present():\n    return bool(get_headers(DeepSeek.cookie_domain).get(\"authorization\"))","typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs)\nexcept MissingAuthError as e:\n    if \"Authorization token required\" in str(e):\n        refresh_har_with_token()","preventionTips":["Capture the HAR during an actual chat completion so the Bearer header is recorded.","Persist the authorization token on conversation objects you reuse.","Re-export HARs on a schedule; bearer tokens outlive cookies by little."],"tags":["authentication","bearer-token","deepseek","har-file"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}