Set Up LangChain & LangGraph with MonoRouter
Route your LangChain agents and LangGraph workflows through your Claude Pro or Max subscription. Two env vars, zero code changes.
What you need
- •A Claude Pro or Max subscription at claude.ai
- •Python 3.9+ with
pip - •A MonoRouter account — sign up at /signup
- •A MonoRouter API key (
mrk_*) — get one at /keys - •Your Claude subscription connected to MonoRouter — go to /tokens, click
[ + add token ], and run the auto-connect script
Sign up for MonoRouter
Open /signup, enter your email and set a password. Save the six recovery codes — they're your offline fallback if you lose your password; you can also always reset it by email at /forgot-password.
Connect your Claude subscription
From the dashboard, go to /tokens, click [ + add token ], and pick ANTHROPIC. Use the auto-connect tab — it's the fastest.
The modal shows a one-liner like this:
curl -sSL https://api.monorouter.dev/connect.sh | bash -s -- mrc_xxxxxxxxxxxx
Paste it into a terminal. The script runs claude setup-token, which opens a browser window for authorization and creates a long-lived token. When the dashboard flips to connected, you're done.
Install the packages
pip install langchain-anthropic langgraph
langchain-anthropic is the official LangChain integration for Claude. langgraph is optional — install it if you're building stateful agents with tool use.
Set environment variables
Add these to your shell config or .env file:
export ANTHROPIC_BASE_URL="https://api.monorouter.dev" export ANTHROPIC_API_KEY="mrk_your_key_here"
langchain-anthropic package reads these environment variables automatically. No code changes needed.Basic LangChain usage
Simple completion through MonoRouter:
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-sonnet-4-6")
response = llm.invoke("What is MonoRouter?")
print(response.content)The ChatAnthropic class picks up ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment. You can also pass them explicitly:
llm = ChatAnthropic(
model="claude-sonnet-4-6",
anthropic_api_url="https://api.monorouter.dev",
anthropic_api_key="mrk_your_key_here",
)LangGraph agent with tools
Build a tool-calling agent that routes through MonoRouter:
from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"It's sunny in {city}!"
llm = ChatAnthropic(model="claude-sonnet-4-6")
agent = create_react_agent(llm, tools=[get_weather])
result = agent.invoke({
"messages": [{"role": "user", "content": "What's the weather in Tokyo?"}]
})
for msg in result["messages"]:
print(msg.content)Every LLM call the agent makes routes through MonoRouter automatically. You can see each call on your /dashboard.
Streaming
MonoRouter supports streaming out of the box:
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-sonnet-4-6", streaming=True)
for chunk in llm.stream("Explain quantum computing in one paragraph"):
print(chunk.content, end="", flush=True)Available models
Use any of these model IDs with ChatAnthropic:
| Model | ID | Context | Max output |
|---|---|---|---|
| Fable 5 | claude-fable-5 | 1M | 128k |
| Opus 4.8 | claude-opus-4-8 | 1M | 128k |
| Opus 4.7 | claude-opus-4-7 | 1M | 128k |
| Opus 4.6 | claude-opus-4-6 | 1M | 128k |
| Sonnet 5 | claude-sonnet-5 | 1M | 128k |
| Sonnet 4.6 | claude-sonnet-4-6 | 1M | 128k |
| Haiku 4.5 | claude-haiku-4-5-20251001 | 200k | 64k |
Pricing
- •1,500 successful calls are free for the lifetime of your account. Failed calls don't count.
- •After that, paid plans start at $9/month (Hobby, 10,000 calls). Pro is $29/month for unlimited personal use; Team is $99/month for 5 pooled seats. See /billing for the payment flow.
Ready to get started?
Sign up in 30 seconds — no credit card required. 1,500 free API calls included.