BerriAI/litellm · error · LangFlowError

LangFlow returned a non-JSON response

Error message

LangFlow returned a non-JSON response: {e}

What it means

LangFlowConfig.transform_response calls raw_response.json(); when the LangFlow server returned a body that is not valid JSON (HTML error page, plain text, empty body), the parse exception is wrapped into LangFlowError carrying the underlying parse error and the HTTP status of the response. It almost always means the request hit the wrong endpoint or an intermediary error page, not a JSON API response.

Solutions

  1. Log the status code on the raised LangFlowError and enable verbose logging to inspect the actual body
  2. Set api_base to the LangFlow root only (e.g. http://localhost:7860); the transformation appends /api/v1/run/{flow_id} itself
  3. Confirm the instance is up and returns JSON: curl -i http://<host>:7860/api/v1/run/<flow_id>
  4. Verify the LangFlow API key (sent as x-api-key) is valid so you get a JSON error instead of an HTML page

Example fix

# before: base URL already contains the API path -> HTML 404 page -> non-JSON error
os.environ["LANGFLOW_API_BASE"] = "http://localhost:7860/api/v1"

# after: root base only; transformation builds /api/v1/run/{flow_id}
os.environ["LANGFLOW_API_BASE"] = "http://localhost:7860"
Defensive patterns

Strategy: try-catch

Validate before calling

import httpx

def check_langflow_json_endpoint(base: str) -> None:
    r = httpx.get(f"{base.rstrip('/')}/health", timeout=5)  # any endpoint that should answer JSON
    ct = r.headers.get("content-type", "")
    if "json" not in ct:
        raise RuntimeError(f"LangFlow at {base} is not serving JSON (content-type={ct!r})")

Try / catch

from litellm.llms.langflow.chat.transformation import LangFlowError

try:
    resp = litellm.completion(model="langflow/<flow_id>", messages=msgs, api_base=base)
except LangFlowError as e:
    if "non-JSON response" in e.message:
        log.error("LangFlow endpoint returned non-JSON (HTTP %s) — check api_base/proxy/auth", e.status_code)
    raise

Prevention

When it happens

Trigger: LANGFLOW_API_BASE includes an extra path (e.g. already ends in /api/v1/run) so the built URL 404s with an HTML page; LangFlow is behind a reverse proxy that returns an HTML 502/503; an invalid x-api-key makes the server answer with an HTML auth page; the service on that port is not LangFlow at all.

Common situations: Base URL copied from the browser UI including a path prefix; wrong port (7860 vs custom); server restarting while a request lands; nginx/ingress error page in front of LangFlow.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/eece14736a06590a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/langflow/chat/transformation.py:233

    def transform_response(
        self,
        model: str,
        raw_response: httpx.Response,
        model_response: ModelResponse,
        logging_obj: LiteLLMLoggingObj,
        request_data: dict,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        encoding: Any,
        api_key: str | None = None,
        json_mode: bool | None = None,
    ) -> ModelResponse:
        try:
            response_json: Final = raw_response.json()
        except Exception as e:
            raise LangFlowError(
                message=f"LangFlow returned a non-JSON response: {e}",
                status_code=raw_response.status_code,
            )

        verbose_logger.debug("LangFlow response: %s", response_json)

        content: Final = self._extract_content_from_response(response_json)
        if content is None:
            raise LangFlowError(
                message=(
                    "Could not extract a message from the LangFlow response; "
                    "ensure the flow ends in a Chat Output component"
                ),
                status_code=500,
            )

        message: Final = Message(content=content, role="assistant")
        choice: Final = Choices(finish_reason="stop", index=0, message=message)

View on GitHub (pinned to 77b7c6c40c)