{"record":{"id":"f7ef5f2b0833e033","repo":"Fosowl/agenticSeek","slug":"deepseek-api-error-str-e","errorCode":null,"errorMessage":"Deepseek API error: {str(e)}","messagePattern":"Deepseek API error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":347,"sourceCode":"    def deepseek_fn(self, history, verbose=False):\n        \"\"\"\n        Use deepseek api to generate text.\n        \"\"\"\n        client = OpenAI(api_key=self.api_key, base_url=\"https://api.deepseek.com\")\n        if self.is_local:\n            raise Exception(\"Deepseek (API) is not available for local use. Change config.ini\")\n        try:\n            response = client.chat.completions.create(\n                model=self.model,\n                messages=history,\n                stream=False\n            )\n            thought = response.choices[0].message.content\n            if verbose:\n                print(thought)\n            return thought\n        except Exception as e:\n            raise Exception(f\"Deepseek API error: {str(e)}\") from e\n\n    def lm_studio_fn(self, history, verbose=False):\n        \"\"\"\n        Use local lm-studio server to generate text.\n        \"\"\"\n        if self.in_docker:\n            # Extract scheme, host, and port from server_address\n            port = \"1234\"  # default\n            addr = self.server_address\n            if \"://\" not in addr:\n                addr = f\"http://{addr}\"\n            parsed_addr = urlparse(addr)\n            if parsed_addr.port:\n                port = str(parsed_addr.port)\n            hostname = parsed_addr.hostname or \"localhost\"\n            scheme = parsed_addr.scheme or \"http\"\n            # For localhost/127.0.0.1, redirect to Docker internal URL so containers\n            # can reach the host machine; for all other hosts use the configured address","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L329-L365","documentation":"deepseek_fn wraps any failure from its chat.completions.create call into 'Deepseek API error: {str(e)}', re-raised with the original as __cause__. The OpenAI-compatible client against api.deepseek.com can fail on auth, bad model names, insufficient balance, rate limits, or network issues.","triggerScenarios":"client.chat.completions.create raises: invalid api_key (401), unknown self.model for Deepseek, insufficient Deepseek account balance (402), 429 rate limit, timeouts/connection errors.","commonSituations":"Deepseek account out of credits; model set to a Together/OpenAI name not served by Deepseek; key left as placeholder; network blocked to api.deepseek.com.","solutions":["Inspect the chained cause message for the precise HTTP status from Deepseek","Verify api_key in config.ini is a valid Deepseek key with positive balance","Set self.model to a Deepseek-supported model ('deepseek-chat' or 'deepseek-reasoner')","Retry with backoff on 429/5xx; check Deepseek status page for incidents","Confirm outbound HTTPS to api.deepseek.com is allowed"],"exampleFix":"// before\nresult = provider.deepseek_fn(history)\n// after\ntry:\n    result = provider.deepseek_fn(history)\nexcept Exception as e:\n    logging.error(f\"Deepseek failed: {e}\")\n    if \"402\" in str(e.__cause__):\n        top_up_deepseek_balance()\n    raise","handlingStrategy":"try-catch","validationCode":"def validate_deepseek(provider):\n    assert provider.api_key and provider.api_key.startswith(\"sk-\"), \"Deepseek API key missing/placeholder\"\n    assert provider.model in (\"deepseek-chat\", \"deepseek-reasoner\"), f\"'{provider.model}' is not a Deepseek API model\"","typeGuard":"def is_deepseek_model(model: str) -> bool:\n    return model in {\"deepseek-chat\", \"deepseek-reasoner\"}","tryCatchPattern":"try:\n    thought = provider.deepseek_fn(history)\nexcept Exception as e:\n    cause = str(e.__cause__)\n    if \"402\" in cause:\n        raise RuntimeError(\"Deepseek balance exhausted — top up account\") from e\n    if \"429\" in cause:\n        retry_with_backoff()\n    else:\n        raise","preventionTips":["Monitor Deepseek account balance; 402 is the top production failure","Only pass Deepseek-native model names to the deepseek provider","Log __cause__ so the real status code isn't lost","Alert on repeated failures — often account or quota issues, not code bugs"],"tags":["api","network","deepseek","error-wrapping"],"backgroundTag":"llm-api-request-failed","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}