{"record":{"id":"4f461eb36977e1b4","repo":"Fosowl/agenticSeek","slug":"authentication-failed-please-check-your-token","errorCode":null,"errorMessage":"Authentication failed. Please check your token.","messagePattern":"Authentication failed\\. Please check your token\\.","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":498,"sourceCode":"            DeepSeekAPI,\n            AuthenticationError,\n            RateLimitError,\n            NetworkError,\n            CloudflareError,\n            APIError\n        )\n        thought = \"\"\n        message = '\\n---\\n'.join([f\"{msg['role']}: {msg['content']}\" for msg in history])\n\n        try:\n            api = DeepSeekAPI(self.api_key)\n            chat_id = api.create_chat_session()\n            for chunk in api.chat_completion(chat_id, message):\n                if chunk['type'] == 'text':\n                    thought += chunk['content']\n            return thought\n        except AuthenticationError as e:\n            raise AuthenticationError(\"Authentication failed. Please check your token.\") from e\n        except RateLimitError as e:\n            raise RateLimitError(\"Rate limit exceeded. Please wait before making more requests.\") from e\n        except CloudflareError as e:\n            raise CloudflareError(f\"Cloudflare protection encountered: {str(e)}\") from e\n        except NetworkError as e:\n            raise NetworkError(\"Network error occurred. Check your internet connection.\") from e\n        except APIError as e:\n            raise APIError(f\"API error occurred: {str(e)}\") from e\n        return None\n\n    def litellm_fn(self, history, verbose=False):\n        \"\"\"\n        Use LiteLLM AI gateway for completion.\n        Routes to 100+ providers (OpenAI, Anthropic, Azure, Bedrock,\n        Vertex AI, Groq, Together, Ollama, etc.) based on model prefix.\n        See https://docs.litellm.ai/docs/providers\n        \"\"\"\n        try:","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L480-L516","documentation":"dsk_deepseek (using the unofficial xtekky/deepseek4free API) catches AuthenticationError from the session/chat calls and re-raises it with a fixed message: 'Authentication failed. Please check your token.' This means the DSK_DEEPSEEK_API_KEY/token was rejected by the DeepSeek backend.","triggerScenarios":"Calling dsk_deepseek when api.create_chat_session() or api.chat_completion raises AuthenticationError — i.e. the token in DSK_DEEPSEEK_API_KEY is missing, expired, revoked, or malformed.","commonSituations":"DSK_DEEPSEEK_API_KEY not set in .env (load_dotenv didn't find it); token expired on the unofficial free API; DeepSeek changed its auth flow breaking the unofficial library; token copied with whitespace/quotes.","solutions":["Set a valid DSK_DEEPSEEK_API_KEY in your .env and confirm load_dotenv() loads it (print os.getenv to verify)","Regenerate the token from the deepseek4free source if it expired","Strip quotes/whitespace around the token value in .env","Update/reinstall the deepseek4free package in case DeepSeek changed its auth scheme","Catch AuthenticationError in your code and prompt the user to fix their token"],"exampleFix":"// before (.env)\nDSK_DEEPSEEK_API_KEY=\"' abc123 '\"\n// after (.env)\nDSK_DEEPSEEK_API_KEY=abc123","handlingStrategy":"try-catch","validationCode":"import os\ndef deepseek_token_ready():\n    tok = os.getenv('DSK_DEEPSEEK_API_KEY')\n    return bool(tok and tok.strip() == tok and tok not in ('', 'None'))","typeGuard":null,"tryCatchPattern":"try:\n    out = provider.dsk_deepseek(history)\nexcept AuthenticationError:\n    log.error('DeepSeek token rejected - refresh DSK_DEEPSEEK_API_KEY in .env')\n    # prompt user / reconfigure before retrying","preventionTips":["Set DSK_DEEPSEEK_API_KEY in .env and verify load_dotenv() picks it up","Avoid quotes/whitespace around token values","Refresh tokens proactively; unofficial free tokens expire","Keep deepseek4free updated for auth-flow changes","Validate token presence at application startup"],"tags":["authentication","deepseek","token"],"backgroundTag":"authentication-failed","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}