Fosowl/agenticSeek · error · APIError

API error occurred: {str(e)}

Error message

API error occurred: {str(e)}

What it means

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.

Source

Thrown at sources/llm_provider.py:506

        message = '\n---\n'.join([f"{msg['role']}: {msg['content']}" for msg in history])

        try:
            api = DeepSeekAPI(self.api_key)
            chat_id = api.create_chat_session()
            for chunk in api.chat_completion(chat_id, message):
                if chunk['type'] == 'text':
                    thought += chunk['content']
            return thought
        except AuthenticationError as e:
            raise AuthenticationError("Authentication failed. Please check your token.") from e
        except RateLimitError as e:
            raise RateLimitError("Rate limit exceeded. Please wait before making more requests.") from e
        except CloudflareError as e:
            raise CloudflareError(f"Cloudflare protection encountered: {str(e)}") from e
        except NetworkError as e:
            raise NetworkError("Network error occurred. Check your internet connection.") from e
        except APIError as e:
            raise APIError(f"API error occurred: {str(e)}") from e
        return None

    def litellm_fn(self, history, verbose=False):
        """
        Use LiteLLM AI gateway for completion.
        Routes to 100+ providers (OpenAI, Anthropic, Azure, Bedrock,
        Vertex AI, Groq, Together, Ollama, etc.) based on model prefix.
        See https://docs.litellm.ai/docs/providers
        """
        try:
            import litellm
        except ImportError as e:
            raise ImportError("litellm is not installed. Install with: pip install litellm") from e

        if self.is_local:
            raise Exception("LiteLLM is not available for local use. Change config.ini")

        api_key = os.getenv("LITELLM_API_KEY", None)

View on GitHub (pinned to ae57a23577)

Solutions

  1. Read the chained original message (str(e)) for the real cause
  2. Update the dsk package — protocol drift between library and live site is the usual culprit
  3. Retry after a short delay if the endpoint is having an outage
  4. Switch to an official provider backend (litellm_fn or others) for reliability

Example fix

// before
try:
    thought = provider.dsk_deepseek(history)
except APIError as e:
    print(e)
// after
try:
    thought = provider.dsk_deepseek(history)
except APIError as e:
    logger.warning('dsk failed: %s — falling back', e)
    thought = provider.litellm_fn(history)
Defensive patterns

Strategy: try-catch

Validate before calling

import dsk
print(dsk.__version__)  # verify reasonably recent vs live site changes

Type guard

def is_api_error(e: BaseException) -> bool:
    return isinstance(e, APIError) and not isinstance(e, (AuthenticationError, RateLimitError, CloudflareError, NetworkError))

Try / catch

try:
    thought = provider.dsk_deepseek(history)
except APIError as e:
    logger.error('dsk API failed: %s (cause: %s)', e, e.__cause__)
    thought = None  # or fall back to another provider

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/ebd0684ac5bf2113. Report an issue: GitHub.