BerriAI/litellm · error · LangGraphError

{response.read()}

Error message

{response.read()}

What it means

On the synchronous streaming path, LangGraphConfig POSTs to {api_base}/runs/stream and any non-200 response is turned into LangGraphError whose message is the raw response body (str(response.read())). The status code and body come from the LangGraph server itself, so they carry the real failure reason (auth, unknown graph, payload validation).

Source

Thrown at litellm/llms/langgraph/chat/transformation.py:312

        )
        from litellm.utils import CustomStreamWrapper

        if client is None or not isinstance(client, HTTPHandler):
            client = _get_httpx_client(params={})

        verbose_logger.debug("Making sync streaming request to: %s", api_base)

        # Make streaming request
        response: Final = client.post(
            api_base,
            headers=headers,
            data=json.dumps(data),
            stream=True,
            logging_obj=logging_obj,
        )

        if response.status_code != 200:
            raise LangGraphError(status_code=response.status_code, message=str(response.read()))

        # Create iterator for SSE stream
        completion_stream: Final = self.get_streaming_response(model=model, raw_response=response)

        streaming_response: Final = CustomStreamWrapper(
            completion_stream=completion_stream,
            model=model,
            custom_llm_provider=custom_llm_provider,
            logging_obj=logging_obj,
        )

        # LOGGING
        logging_obj.post_call(
            input=messages,
            api_key="",
            original_response="first stream response received",
            additional_args={"complete_input_dict": data},
        )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Inspect e.status_code and e.message (the server's response body) for the concrete reason
  2. 401/403: set the correct API key (api_key kwarg or provider env var)
  3. 404: fix api_base so it is the LangGraph API root (it appends /runs/stream itself)
  4. 422: verify the assistant/graph identifier in the model name exists on the server
  5. Reproduce outside litellm: curl -X POST {api_base}/runs/wait -H 'Content-Type: application/json' -d '{...}'

Example fix

# before: api_base points at a UI route, streaming POST returns 404
litellm.completion(model="langgraph/agent", api_base="https://host/ui", stream=True, messages=[...])

# after
try:
    litellm.completion(model="langgraph/agent", api_base="https://host", stream=True, messages=[...])
except litellm.llms.langgraph.chat.transformation.LangGraphError as e:
    log.error("langgraph stream failed: %s %s", e.status_code, e.message)
Defensive patterns

Strategy: try-catch

Validate before calling

import httpx

def langgraph_stream_reachable(base: str, api_key: str | None) -> None:
    r = httpx.post(
        f"{base.rstrip('/')}/runs/wait",
        headers={"Authorization": f"Bearer {api_key}"} if api_key else {},
        json={"assistant_id": "agent", "input": {"messages": []}},
        timeout=10,
    )
    if r.status_code in (401, 403, 404):
        raise RuntimeError(f"LangGraph server rejected probe: {r.status_code} {r.text[:200]}")

Try / catch

try:
    stream = litellm.completion(model="langgraph/agent", stream=True, messages=msgs, api_base=base)
except Exception as e:
    status = getattr(e, "status_code", None)
    if status and 500 <= status < 600 and attempt < MAX_RETRIES:
        time.sleep(2 ** attempt)  # transient server error: retry with backoff
        continue
    log.error("LangGraph stream failed: HTTP %s body=%s", status, getattr(e, "message", e))
    raise

Prevention

When it happens

Trigger: litellm.completion(..., stream=True) against a langgraph model where the server answers non-200: 404 when api_base is not a LangGraph API server, 401/403 with a missing/invalid API key, 422 when the payload names a graph/assistant that does not exist, 409 on thread conflicts, 5xx on server crashes.

Common situations: Pointing at a LangGraph Platform/Agent Server deployment with the wrong path prefix; expired API key; assistant/graph not yet deployed; local dev server not running the expected graph.

Related errors


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