Use rawroute with LangChain. Swap base_url in ChatOpenAI or ChatAnthropic.
LangChain and LangGraph agents execute dozens of LLM steps per task, multiplying token spend and 429/529 exposure. Pointing ChatOpenAI to https://api.rawroute.dev/v1 or ChatAnthropic to https://api.rawroute.dev cuts token costs 50–70% below official rates while preserving structured outputs, tool calling, and streaming.
Quick setup for LangChain
- Install langchain-openai or langchain-anthropic as usual.
- Pass base_url="https://api.rawroute.dev/v1" (OpenAI) or anthropic_api_url="https://api.rawroute.dev" (Anthropic).
- Keep all existing LangGraph chains, .with_structured_output(), and tool bindings unchanged.
import os
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
gpt = ChatOpenAI(
model="gpt-6.2-astra",
base_url="https://api.rawroute.dev/v1",
api_key=os.environ["RAWROUTE_API_KEY"],
max_retries=3,
)
claude = ChatAnthropic(
model="claude-sonnet-5-5",
anthropic_api_url="https://api.rawroute.dev",
api_key=os.environ["RAWROUTE_API_KEY"],
)Recommended models for LangChain
| Model | Model ID | Official | OpenRouter +5.5% | rawroute (0%) | Providers |
|---|---|---|---|---|---|
| GPT-6.2 Astra | gpt-6.2-astra | $8.44 / $42.20 | $2.40 / $12.00 | 4 | |
| Claude Sonnet 5.5 | claude-sonnet-5-5 | $2.11 / $10.55 | $1.00 / $5.00 | 4 | |
| Gemini 4 Argon | gemini-4-argon | $2.11 / $10.55 | $1.00 / $5.00 | 4 | |
| GPT-6.2 Sol | gpt-6.2-sol | $2.11 / $10.55 | $0.60 / $3.00 | 3 |
When NOT to use rawroute
- — Keep LangSmith tracing enabled if you want step-by-step LangGraph visual traces alongside rawroute billing logs.
FAQ
Does with_structured_output() work with rawroute in LangChain?
Yes. Both JSON schema mode and native tool-calling structured outputs work identically to official vendor endpoints.