BroadRouter
Get started

Build LangGraph agents on BroadNet Inference

Updated

Install langgraph and langchain-openai, then create ChatOpenAI with model set to a BroadNet ID such as broadnet/glm-5.3, base_url set to https://inference.broadnet.ai/v1 and api_key set to your BroadNet key. Bind your tools to it and use it in a StateGraph node, or pass it to langchain's create_agent. Use GLM 5.3 or Qwen3.8 27B, the models BroadNet lists with tools.

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 say ChatOpenAI moves to the Responses API when you use OpenAI built-in tools, conversation state or the reasoning parameter. Leave those out and don’t set use_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_tokens to 2,000 or more on the model. In our test, langchain-openai 1.8 sent it as max_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_url must end in /v1. Check the model ID, with the broadnet/ prefix. Paid models need a top-up; the $5 credit covers only broadnet/gemma-4-26b-a4b and the two Transcribe models.
  • The agent never calls a tool. Switch to broadnet/glm-5.3 or broadnet/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_retries to ChatOpenAI and see errors and retries.

Questions

Does LangGraph need its own BroadNet integration?

No. LangGraph runs whatever chat model your nodes call. Use LangChain's ChatOpenAI with base_url set to https://inference.broadnet.ai/v1, and every node that calls the model goes to BroadNet over chat completions.

Should I use create_react_agent or create_agent?

In LangGraph 1.2, create_react_agent from langgraph.prebuilt still works but prints a deprecation warning that points to create_agent in the langchain package. Both worked against our mock server with a BroadNet-style model ID.

Which BroadNet model should a LangGraph agent use?

GLM 5.3 (broadnet/glm-5.3) or Qwen3.8 27B (broadnet/qwen3.8-27b). An agent loop depends on tool calls, and BroadNet lists tools for these two models only.

Why is the max_tokens I set sent as max_completion_tokens?

langchain-openai 1.8 renames max_tokens to max_completion_tokens in the request. BroadNet's API reference describes max_tokens. If an output limit seems to be ignored, check the request your app actually sends.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity