{"record":{"id":"ebd0684ac5bf2113","repo":"Fosowl/agenticSeek","slug":"api-error-occurred-str-e","errorCode":null,"errorMessage":"API error occurred: {str(e)}","messagePattern":"API error occurred: (.+?)","errorType":"exception","errorClass":"APIError","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":506,"sourceCode":"        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:\n            import litellm\n        except ImportError as e:\n            raise ImportError(\"litellm is not installed. Install with: pip install litellm\") from e\n\n        if self.is_local:\n            raise Exception(\"LiteLLM is not available for local use. Change config.ini\")\n\n        api_key = os.getenv(\"LITELLM_API_KEY\", None)","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L488-L524","documentation":"dsk_deepseek catches dsk's generic APIError and re-raises it with an 'API error occurred' prefix plus the original message. This is the catch-all for server-side or protocol errors from the free DeepSeek endpoint that are not auth, rate-limit, Cloudflare, or network failures.","triggerScenarios":"Calling LLMProvider.dsk_deepseek(history) when the dsk library raises APIError — e.g. unexpected response shape from chat_completion, HTTP 5xx from the endpoint, or malformed streaming payload.","commonSituations":"The unofficial endpoint changed its response format after a site update; server-side outage of the free API; dsk package version drifted from the live site's protocol.","solutions":["Read the chained original message (str(e)) for the real cause","Update the dsk package — protocol drift between library and live site is the usual culprit","Retry after a short delay if the endpoint is having an outage","Switch to an official provider backend (litellm_fn or others) for reliability"],"exampleFix":"// before\ntry:\n    thought = provider.dsk_deepseek(history)\nexcept APIError as e:\n    print(e)\n// after\ntry:\n    thought = provider.dsk_deepseek(history)\nexcept APIError as e:\n    logger.warning('dsk failed: %s — falling back', e)\n    thought = provider.litellm_fn(history)","handlingStrategy":"try-catch","validationCode":"import dsk\nprint(dsk.__version__)  # verify reasonably recent vs live site changes","typeGuard":"def is_api_error(e: BaseException) -> bool:\n    return isinstance(e, APIError) and not isinstance(e, (AuthenticationError, RateLimitError, CloudflareError, NetworkError))","tryCatchPattern":"try:\n    thought = provider.dsk_deepseek(history)\nexcept APIError as e:\n    logger.error('dsk API failed: %s (cause: %s)', e, e.__cause__)\n    thought = None  # or fall back to another provider","preventionTips":["Pin and regularly update the dsk package; the unofficial protocol drifts","Log the exception cause chain, since the wrapper message is generic","Prefer official providers for production workloads","Alert on repeated APIError bursts (endpoint outage signal)"],"tags":["api-error","unofficial-api","server-error","deepseek"],"backgroundTag":"upstream-api-error","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}