Fosowl/agenticSeek · error · Exception

HTTP request failed: {str(e)}

Error message

HTTP request failed: {str(e)}

What it means

lm_studio_fn wraps any requests.exceptions.RequestException that is not a Timeout or ConnectionError into a generic 'HTTP request failed: <details>' Exception. This means the HTTP call to the local LM Studio server failed for a reason other than timeout or connection refusal (e.g. protocol error, too many redirects, SSL issue). The original exception is chained via 'from e' so the cause is preserved in the traceback.

Source

Thrown at sources/llm_provider.py:412

            if verbose:
                print("Response from LM Studio:", result)
            choices = result.get("choices", [])
            if not choices:
                raise Exception(f"No choices in LM Studio response: {result}")

            message = choices[0].get("message", {})
            content = message.get("content", "")
            if not content:
                raise Exception(f"Empty content in LM Studio response: {result}")
            return content

        except requests.exceptions.Timeout:
            raise Exception("LM Studio request timed out - check if server is responsive")
        except requests.exceptions.ConnectionError:
            raise Exception(f"Cannot connect to LM Studio at {route_start} - check if server is running")
        except requests.exceptions.RequestException as e:
            raise Exception(f"HTTP request failed: {str(e)}") from e
        except Exception as e:
            if "LM Studio" in str(e):
                raise  # Re-raise our custom exceptions
            raise Exception(f"Unexpected error: {str(e)}") from e

    def openrouter_fn(self, history, verbose=False):
        """
        Use OpenRouter API to generate text.
        """
        client = OpenAI(api_key=self.api_key, base_url="https://openrouter.ai/api/v1")
        if self.is_local:
            # This case should ideally not be reached if unsafe_providers is set correctly
            # and is_local is False in config for openrouter
            raise Exception("OpenRouter is not available for local use. Change config.ini")
        try:
            response = client.chat.completions.create(
                model=self.model,
                messages=history,

View on GitHub (pinned to ae57a23577)

Solutions

  1. Check the LM Studio server URL in config.ini is a well-formed http://host:port endpoint
  2. Verify the LM Studio server is running and serving on the expected port (curl the /v1/models endpoint)
  3. Disable any HTTP(S)_PROXY environment variables for localhost (set NO_PROXY=127.0.0.1,localhost)
  4. Read the chained cause in the traceback for the exact requests error and address it
  5. Upgrade requests if the error indicates a protocol/encoding bug

Example fix

// before
route = "localhost:1234/v1"  # missing scheme -> InvalidSchema (RequestException)
// after
route = "http://localhost:1234/v1"
Defensive patterns

Strategy: try-catch

Validate before calling

import requests
def lm_studio_reachable(url):
    try:
        r = requests.get(url.rstrip('/').rsplit('/chat/completions',1)[0] + '/models', timeout=5)
        return r.ok
    except requests.exceptions.RequestException:
        return False

Try / catch

try:
    out = provider.lm_studio_fn(history)
except Exception as e:
    cause = e.__cause__
    if isinstance(cause, requests.exceptions.RequestException):
        log.warning("LM Studio HTTP failure: %s", cause)
    raise

Prevention

When it happens

Trigger: Calling lm_studio_fn while the POST to the LM Studio server raises a requests RequestException subclass other than Timeout/ConnectionError — e.g. invalid URL scheme in the route, chunked encoding error, too many redirects, or a proxy misconfiguration raising requests exceptions.

Common situations: config.ini route set to a malformed URL (missing http://, trailing bad port); a corporate proxy intercepting localhost traffic; requests library incompatibility with the local server's response; server returning a broken stream mid-transfer.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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