A Keyless Model Behind Your LangChain Graph, Step by Step

LangGraph is a popular way to structure multi-step LLM workflows as graphs of nodes and edges, and developers increasingly pair it with a coding agent that writes much of the graph for them. A frequent question is how to keep experiments cheap: every node that calls a paid model costs credit, and graph development involves running the same flow dozens of times while you fix wiring, state and prompts.
This guide shows how to run a LangGraph workflow against any OpenAI-compatible endpoint, using the keyless API on this site as the example. You will configure the chat model, build a small draft-and-review graph, add retries for rate limits, keep prompts portable so you can swap in another provider later, and learn where a free open model is enough and where a stronger commercial model is worth it. It assumes basic Python and a recent version of langchain-openai and langgraph.
Frequently asked questions
What is LangGraph?
It is a library from the LangChain ecosystem for building stateful LLM applications as graphs. Each node is a function that reads and updates shared state, and edges decide which node runs next, including loops and branches.
Can LangChain use a model that is not from OpenAI?
Yes. The ChatOpenAI class accepts a custom base_url, so any server that implements the OpenAI chat completions format can be used, including self-hosted and keyless endpoints.
How does a graph differ from a simple chain?
A chain runs steps in a fixed order. A graph can loop back, branch on conditions and keep state across steps, which suits review cycles, agents and workflows that retry until a check passes.
Which is better for development: a free model or the production model?
Use a free model to build and debug the graph's structure, then validate prompts and quality on the model you will run in production. Behaviour differs between models, so final testing must happen on the real one.
Does the free endpoint support tool calling for prebuilt agents?
Do not rely on it. Prebuilt ReAct-style agents assume native tool calling. Graphs whose nodes call the model with plain messages and parse the result work with any compatible endpoint.
Do I need an API key for the keyless endpoint?
No. The client library may insist on a non-empty key value, so pass any placeholder string. The server ignores it.
What limits apply when a graph runs many nodes?
Each node call is one request. Per IP the free API allows one request per second with bursts of three, two in parallel and 10,000 requests or 10,000,000 tokens per day, so pace parallel branches accordingly.
Step by step
- Install the packages — Install langchain-openai and langgraph, and pin their versions in your requirements file.
- Configure ChatOpenAI — Set base_url to the keyless endpoint, model to free-ai, a placeholder api_key, and max_retries for 429 and 503 responses.
- Define state and nodes — Create a state class with messages and a revision counter, then write draft and review node functions.
- Wire the edges — Connect start to draft, draft to review, and add a conditional edge that ends on approval or after three revisions.
- Test and switch providers — Run fixed test inputs, inspect streamed updates, then change environment variables to validate on your production model.
Why develop graphs against a free endpoint
Most of the time spent building a graph goes into plumbing, not prompting: getting state keys right, wiring conditional edges, handling the end of a loop, and making the output parse. During that phase, the quality of the model barely matters. What matters is that every run is free and fast enough to iterate.
A keyless OpenAI-compatible endpoint fits that phase well. You keep the standard client code you would use in production, switch the base URL and model name, and run the graph as often as you like within the daily limits. When the structure is stable, you point the same code at the model you will ship with.
Structure first, quality later
Separate the two concerns. Prove the graph behaves correctly with any model, then tune prompts for the target model in a second pass.
Cheaper coding-agent loops
When a coding agent writes and runs your graph repeatedly, each test run would otherwise consume paid model calls on top of the agent's own usage.
Configure the chat model
Install the two packages, then create a ChatOpenAI instance with the custom base URL. The model name is free-ai. The OpenAI SDK used underneath sends a normal User-Agent, which matters because the API rejects clients without one.
Keep the configuration in one place, ideally driven by environment variables, so switching provider later is a one-line change rather than a hunt through every node.
Placeholder key
The client requires a key string. Any value works for the keyless endpoint; for a paid provider, set the real key in the environment, never in code.
# pip install -U langchain-openai langgraph
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url=os.getenv("LLM_BASE_URL", "https://api.apifreekeyanthropic.com/v1"),
api_key=os.getenv("LLM_API_KEY", "none"),
model=os.getenv("LLM_MODEL", "free-ai"),
temperature=0.3,
max_tokens=800,
max_retries=4, # retries 429 and 5xx with backoff
timeout=120,
)
print(llm.invoke("Say hello in five words.").content)
Build a small draft-and-review graph
A good first graph has two nodes and a loop: one node drafts an answer, another reviews it against a checklist, and a conditional edge sends the draft back for revision until the reviewer approves or a revision limit is reached. This pattern is useful for documentation, emails and summaries, and it exercises everything that tends to go wrong in graphs: state, branching and termination.
The example uses MessagesState plus a counter, and plain text markers for the reviewer's verdict so it does not depend on tool calling.
Always cap loops
A review loop without a limit can run forever if the reviewer is never satisfied. A revision counter in state is the simplest guard.
Plain markers over tools
Starting the reviewer's reply with APPROVED or REVISE is easy to parse and works on any model, even without function calling.
from langgraph.graph import StateGraph, MessagesState, START, END
from langchain_core.messages import SystemMessage, HumanMessage
class State(MessagesState):
revisions: int
def draft(state: State):
msgs = [SystemMessage("Write a clear answer in under 120 words.")] + state["messages"]
return {"messages": [llm.invoke(msgs)], "revisions": state.get("revisions", 0) + 1}
def review(state: State):
last = state["messages"][-1].content
verdict = llm.invoke([
SystemMessage("Check the text: under 120 words, no jargon, answers the question. "
"Reply APPROVED, or REVISE: followed by one concrete fix."),
HumanMessage(last),
])
return {"messages": [HumanMessage(verdict.content)]}
def route(state: State):
text = state["messages"][-1].content
if text.startswith("APPROVED") or state["revisions"] >= 3:
return END
return "draft"
g = StateGraph(State)
g.add_node("draft", draft)
g.add_node("review", review)
g.add_edge(START, "draft")
g.add_edge("draft", "review")
g.add_conditional_edges("review", route, ["draft", END])
app = g.compile()
result = app.invoke({"messages": [HumanMessage("Explain what a rate limit is.")], "revisions": 0})
for m in result["messages"]:
print(type(m).__name__, ":", m.content[:200])Respect rate limits inside the graph
Graphs can fan out into parallel branches, and each branch calls the model. The free endpoint permits two parallel requests per IP and one request per second with small bursts; beyond that it returns 429 with a Retry-After header. When the server is busy it returns 503, and retrying after two to five seconds is the right response.
The max_retries setting on the client handles occasional 429 and 503 responses with backoff. For graphs with wide fan-out, also limit concurrency, for example by passing {"max_concurrency": 2} in the config when you invoke the compiled graph, so you do not trigger the limits in the first place.
Batch thoughtfully
If a node processes a list, send items sequentially with a short pause rather than all at once. Total time barely changes, and you avoid a wall of 429 responses.

Keep prompts portable across providers
Prompts written for one model often depend on its quirks. To make switching easy, keep prompts explicit and short, specify output formats in plain words, and avoid features only one provider has. Store prompts in a separate module or files so they can be reviewed and versioned on their own.
When you move to a commercial provider, change the base URL, key and model through environment variables. If you move to Claude, you can use LangChain's dedicated Anthropic integration or an OpenAI-compatible route if the provider offers one; check Anthropic's current documentation for what is supported. This site is not affiliated with Anthropic and its endpoint does not serve Claude models.
One config object
Create the chat model in a single factory function and import it everywhere. Nodes should never construct their own clients, or a provider switch will miss one and you will discover it only when that branch runs.
- Describe output formats in words and examples, not by relying on provider-specific modes.
- Keep system prompts under a few hundred words; long prompts behave less consistently across models.
- Record which model and prompt version produced each test result.
- Rerun your test inputs after any switch, comparing outputs side by side.
Working with a coding agent on LangGraph code
Coding agents write LangGraph code quickly but tend to mix APIs from different library versions, since the ecosystem has changed a lot. Give the agent the exact versions you have installed and ask it to use current imports such as langgraph.graph.StateGraph. A short procedure note in your repository, describing your graph conventions, saves the agent from rediscovering them in every session.
Let the agent run the graph against the free endpoint while it iterates. Its test runs then cost nothing beyond its own usage, and you can check behaviour from the printed messages. Our article on agents that keep asking permission covers how to let it run these tests without constant confirmations.
Pin library versions
Write exact versions into your requirements file. Graph libraries evolve quickly, and an unpinned upgrade can break imports overnight; see surviving breaking changes in AI dev tools.

Debugging state and edges
Most graph bugs are state bugs: a node returns a key with a typo, a list is overwritten instead of appended, or a conditional edge returns a name that is not a node. Print the state after each step during development, or stream the graph's updates to see exactly what each node returned.
Model behaviour is the second source of bugs. If the reviewer never replies with APPROVED in the exact form you expect, the loop runs until the cap. Log the raw reply, and make your parser tolerant of leading spaces and capitalisation.
Stream updates
Calling app.stream(inputs, stream_mode="updates") yields each node's output as it happens, which makes wiring mistakes obvious.
Freeze inputs for tests
Keep a small set of fixed inputs and expected properties of the output. Rerun them after every structural change.
Where a free model is enough, and where it is not
free-ai is an independent open-weight model of about 35B parameters, with a 32,000-token context and answers up to 16,000 tokens. It handles drafting, summarising, classification and review steps well enough for development and many light production uses. It is text only and stateless; your graph holds all the memory.
For graphs that do deep reasoning across long documents, complex planning or high-stakes decisions, top commercial models are clearly stronger and come with support and service terms that a free endpoint lacks. A common pattern is to keep the free model for cheap nodes such as formatting and first drafts, and route the hard nodes to a paid model; see why a bigger model can use fewer tokens for how to judge that trade-off.
Mixing models in one graph
Nothing stops you from creating two chat model objects, one for the keyless endpoint and one for a paid provider, and passing each to different nodes. Keep a note of which node uses which model, and log it with every run, so quality problems can be traced to the right place. When the paid model is down or your credit is spent, the cheap nodes keep working and you can decide whether the hard nodes should wait or fall back.

Send a first prompt from the chat box on the home page: no key, no account and no card, just your browser.
Read also
- What Is On-Behalf-Of Auth for a Remote MCP Server, and Why Use It?
- One Giant Prompt vs Small Steps: Which Builds Better Apps With AI?
- Why Are So Many 'Free Claude' Videos and Tutorials Misleading?
- Why Do Different AI Models Seem to Have Different Moods?
- Can a Non-Programmer Really Ship an MVP With AI Coding Help?