{"record":{"id":"eece14736a06590a","repo":"BerriAI/litellm","slug":"langflow-returned-a-non-json-response-e","errorCode":null,"errorMessage":"LangFlow returned a non-JSON response: {e}","messagePattern":"LangFlow returned a non-JSON response: (.+?)","errorType":"http","errorClass":"LangFlowError","httpStatus":null,"severity":"error","filePath":"litellm/llms/langflow/chat/transformation.py","lineNumber":233,"sourceCode":"\n    def transform_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: ModelResponse,\n        logging_obj: LiteLLMLoggingObj,\n        request_data: dict,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        try:\n            response_json: Final = raw_response.json()\n        except Exception as e:\n            raise LangFlowError(\n                message=f\"LangFlow returned a non-JSON response: {e}\",\n                status_code=raw_response.status_code,\n            )\n\n        verbose_logger.debug(\"LangFlow response: %s\", response_json)\n\n        content: Final = self._extract_content_from_response(response_json)\n        if content is None:\n            raise LangFlowError(\n                message=(\n                    \"Could not extract a message from the LangFlow response; \"\n                    \"ensure the flow ends in a Chat Output component\"\n                ),\n                status_code=500,\n            )\n\n        message: Final = Message(content=content, role=\"assistant\")\n        choice: Final = Choices(finish_reason=\"stop\", index=0, message=message)","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/langflow/chat/transformation.py#L215-L251","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log the status code on the raised LangFlowError and enable verbose logging to inspect the actual body","Set api_base to the LangFlow root only (e.g. http://localhost:7860); the transformation appends /api/v1/run/{flow_id} itself","Confirm the instance is up and returns JSON: curl -i http://<host>:7860/api/v1/run/<flow_id>","Verify the LangFlow API key (sent as x-api-key) is valid so you get a JSON error instead of an HTML page"],"exampleFix":"# before: base URL already contains the API path -> HTML 404 page -> non-JSON error\nos.environ[\"LANGFLOW_API_BASE\"] = \"http://localhost:7860/api/v1\"\n\n# after: root base only; transformation builds /api/v1/run/{flow_id}\nos.environ[\"LANGFLOW_API_BASE\"] = \"http://localhost:7860\"","handlingStrategy":"try-catch","validationCode":"import httpx\n\ndef check_langflow_json_endpoint(base: str) -> None:\n    r = httpx.get(f\"{base.rstrip('/')}/health\", timeout=5)  # any endpoint that should answer JSON\n    ct = r.headers.get(\"content-type\", \"\")\n    if \"json\" not in ct:\n        raise RuntimeError(f\"LangFlow at {base} is not serving JSON (content-type={ct!r})\")","typeGuard":null,"tryCatchPattern":"from litellm.llms.langflow.chat.transformation import LangFlowError\n\ntry:\n    resp = litellm.completion(model=\"langflow/<flow_id>\", messages=msgs, api_base=base)\nexcept LangFlowError as e:\n    if \"non-JSON response\" in e.message:\n        log.error(\"LangFlow endpoint returned non-JSON (HTTP %s) — check api_base/proxy/auth\", e.status_code)\n    raise","preventionTips":["Keep api_base as the bare LangFlow root; never include /api/v1/run","Health-check the LangFlow instance (expect JSON content-type) at service startup","Monitor HTTP status codes in LangFlowError so HTML gateway pages surface as alerts, not silent parse failures"],"tags":["langflow","non-json-response","http","url-configuration"],"backgroundTag":"invalid-response-format","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}