{"record":{"id":"37510528339e7f30","repo":"langchain-ai/langchain","slug":"failed-to-reach-base-url-api-while-trying-to-ren","errorCode":null,"errorMessage":"Failed to reach {base_url} API while trying to render your graph. Status code: {response.status_code}.\n\n{error_msg_suffix}","messagePattern":"Failed to reach (.+?) API while trying to render your graph\\. Status code: (.+?)\\.\n\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/graph_mermaid.py","lineNumber":484,"sourceCode":"\n                return img_bytes\n\n            # If we get a server error (5xx), retry\n            if (\n                requests.codes.internal_server_error <= response.status_code\n                and attempt < max_retries\n            ):\n                # Exponential backoff with jitter\n                sleep_time = retry_delay * (2**attempt) * (0.5 + 0.5 * random.random())  # noqa: S311 not used for crypto\n                time.sleep(sleep_time)\n                continue\n\n            # For other status codes, fail immediately\n            msg = (\n                f\"Failed to reach {base_url} API while trying to render \"\n                f\"your graph. Status code: {response.status_code}.\\n\\n\"\n            ) + error_msg_suffix\n            raise ValueError(msg)\n\n        except (requests.RequestException, requests.Timeout) as e:\n            if attempt < max_retries:\n                # Exponential backoff with jitter\n                sleep_time = retry_delay * (2**attempt) * (0.5 + 0.5 * random.random())  # noqa: S311 not used for crypto\n                time.sleep(sleep_time)\n            else:\n                msg = (\n                    f\"Failed to reach {base_url} API while trying to render \"\n                    f\"your graph after {max_retries} retries. \"\n                ) + error_msg_suffix\n                raise ValueError(msg) from e\n\n    # This should not be reached, but just in case\n    msg = (\n        f\"Failed to reach {base_url} API while trying to render \"\n        f\"your graph after {max_retries} retries. \"\n    ) + error_msg_suffix","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/graph_mermaid.py#L466-L502","documentation":"When rendering via the Mermaid.INK API, a non-retryable HTTP response (anything outside the retried status set) makes _render_mermaid_using_api raise ValueError with the status code and a help suffix. It means the request reached the server but the server rejected or failed it — most often invalid Mermaid syntax (4xx) or a server-side failure (5xx).","triggerScenarios":"draw_mermaid_png() with malformed Mermaid syntax produced from an exotic graph, a background_color the API rejects, or a self-hosted base_url that errors; the response status falls in the fail-immediately branch.","commonSituations":"Graphs with special characters in node labels generating invalid Mermaid; corporate proxies returning 403/407; mermaid.ink outages returning 5xx; custom base_url misconfiguration.","solutions":["Inspect the status code: 4xx usually means bad syntax — print the Mermaid syntax (graph.draw_mermaid()) and test it at mermaid.live","Simplify/escape node labels (remove quotes, braces, parentheses) and retry","If behind a proxy, pass proxies={...} to draw_mermaid_png or set HTTPS_PROXY","For 5xx from the public API, self-host mermaid.ink and pass base_url, or raise max_retries"],"exampleFix":"# before\nimg = graph.draw_mermaid_png()\n# after (diagnose syntax first)\nprint(graph.draw_mermaid())  # paste into https://mermaid.live to validate\nimg = graph.draw_mermaid_png(max_retries=3)","handlingStrategy":"retry","validationCode":"syntax = graph.draw_mermaid()\n# cheap sanity check before spending an API call\nassert \"graph\" in syntax or \"flowchart\" in syntax or syntax.startswith((\"sequenceDiagram\", \"stateDiagram\"))","typeGuard":null,"tryCatchPattern":"try:\n    img = draw_mermaid_png(syntax)\nexcept ValueError as e:\n    if \"Status code: 4\" in str(e):\n        print(graph.draw_mermaid())  # inspect/fix syntax\n    else:\n        raise","preventionTips":["Validate generated Mermaid syntax visually at mermaid.live when a new graph shape fails","Keep node labels free of quotes/braces/parentheses that break Mermaid","Pass proxies when behind corporate egress filters"],"tags":["graph","mermaid","network","http","valueerror"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}