LangGraph is LangChain’s library for stateful, multi-step agents built as graphs. It has no model client of its own: your nodes call a LangChain chat model. To run a graph on BroadNet Inference, give it ChatOpenAI from langchain-openai with BroadNet’s base URL. BroadRouter is BroadNet’s own site; this follows the LangGraph and LangChain docs as of LangGraph 1.2.22 and langchain-openai 1.8.
Install
pip install langgraph langchain-openai
export BROADNET_API_KEY='your-broadnet-key'
A tool-calling graph
import os
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.prebuilt import ToolNode, tools_condition
from langgraph.checkpoint.memory import InMemorySaver
@tool
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"21C and sunny in {city}"
tools = [get_weather]
model = ChatOpenAI(
model="broadnet/glm-5.3",
base_url="https://inference.broadnet.ai/v1",
api_key=os.environ["BROADNET_API_KEY"],
).bind_tools(tools)
def call_model(state: MessagesState):
return {"messages": [model.invoke(state["messages"])]}
builder = StateGraph(MessagesState)
builder.add_node("model", call_model)
builder.add_node("tools", ToolNode(tools))
builder.add_edge(START, "model")
builder.add_conditional_edges("model", tools_condition)
builder.add_edge("tools", "model")
graph = builder.compile(checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": "demo-1"}}
result = graph.invoke({"messages": [{"role": "user", "content": "What's the weather in Riyadh?"}]}, config)
print(result["messages"][-1].content)
The model node calls BroadNet. tools_condition sends the graph to the tool node when the reply has tool calls, and the tool result goes back to the model. The checkpointer keeps the conversation per thread_id, so a second invoke with the same config continues it.
Stream tokens from the graph
for chunk, meta in graph.stream(
{"messages": [{"role": "user", "content": "And in Dubai?"}]},
config,
stream_mode="messages",
):
if chunk.content and meta["langgraph_node"] == "model":
print(chunk.content, end="", flush=True)
With stream_mode="messages", ChatOpenAI sends stream: true to BroadNet and LangGraph passes the tokens through.
The prebuilt agent
If you don’t need a custom graph, the prebuilt agent loop takes the same model:
from langchain.agents import create_agent # pip install langchain
agent = create_agent(
ChatOpenAI(model="broadnet/glm-5.3", base_url="https://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"]),
tools=tools,
)
agent.invoke({"messages": [{"role": "user", "content": "Weather in Riyadh?"}]})
create_react_agent from langgraph.prebuilt still runs in LangGraph 1.2.22, but prints a warning that it has moved to langchain.agents.create_agent.
Which model to pick
| Graph | Model |
|---|---|
| Agents with tools, structured output | broadnet/glm-5.3 (1,048,576-token context) |
| Tools plus image input or Arabic text | broadnet/qwen3.8-27b (262,144-token context) |
| Graphs with no tool calls, long documents | broadnet/deepseek-v4.1-flash |
BroadNet’s docs list tools and structured output for GLM 5.3 and Qwen3.8 27B only. DeepSeek V4.1 Flash is the model on the unlimited plans, so it suits summarise-and-route graphs that don’t call tools. Test a tool loop on it before you rely on it. Prices for every model.
Settings that matter
- Stay on chat completions. BroadNet serves
/v1/chat/completions. LangChain’s docs sayChatOpenAImoves to the Responses API when you use OpenAI built-in tools, conversation state or thereasoningparameter. Leave those out and don’t setuse_responses_api=True. - Output limit. Reasoning counts toward the output budget on DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B. Set
max_tokensto 2,000 or more on the model. In our test, langchain-openai 1.8 sent it asmax_completion_tokens. - Parallel branches. Each branch that calls the model is a separate request. A pay-as-you-go key allows 4 requests in flight, and a plan session runs one at a time.
How we tested this
On 2026-11-15 we installed langgraph 1.2.22, langchain-openai 1.8.0 and langchain 1.5.0 in a clean virtual environment. We ran the graph above, the streaming loop and create_agent against a local mock server that speaks BroadNet’s chat-completions shape and returns tool calls. We checked the logged requests. Every call went to /v1/chat/completions with the model ID broadnet/glm-5.3 unchanged, a Bearer key and the tool schema, and the tool result came back as a tool message. We had no BroadNet key, so we did not test real model output.
Troubleshooting
- 401. The key is wrong, expired or out of allowance.
- 404.
base_urlmust end in/v1. Check the model ID, with thebroadnet/prefix. Paid models need a top-up; the $5 credit covers onlybroadnet/gemma-4-26b-a4band the two Transcribe models. - The agent never calls a tool. Switch to
broadnet/glm-5.3orbroadnet/qwen3.8-27b. - Empty answers. The output budget went on reasoning. Raise
max_tokens. Why answers come back empty. - 429. A pay-as-you-go key allows 30 requests a minute. Add
max_retriestoChatOpenAIand see errors and retries.
