LangChain integration for Leanroute, the agent-native AI gateway. ChatLeanroute routes to 100+ models across 14 providers, with cost per agent run, MCP tools on any model, failover, caching and spend caps.
pip install langchain-leanroute==0.1.0 Copy PIP instructions
ChatLeanroute is LangChain's ChatOpenAI pointed at Leanroute: one key for 100+ models across 14 providers (OpenAI, Anthropic, Google, xAI, DeepSeek, Qwen and more), with failover, caching, spend caps, MCP tools on any model, and cost per agent run. Tools, structured output, streaming, async and LangGraph work unchanged.
pip install langchain-leanroute Create a runtime key (gw_live_*) at leanroute.dev/dashboard/keys and set it:
export LEANROUTE_API_KEY=gw_live_... New accounts get 100 free requests on low-cost models, no card needed.
from langchain_leanroute import ChatLeanroute llm = ChatLeanroute(model="deepseek/deepseek-v4-1-flash") print(llm.invoke("Explain retrieval-augmented generation in one sentence.").content) Model ids use the provider/model form, e.g. anthropic/claude-sonnet-5 or openai/gpt-5.6-terra. Full list: leanroute.dev/docs/models.
Name your agent and give each run an id, and Leanroute groups the calls into runs on the Agent runs page: cost per run, models used, and every tool called.
from langchain_core.tools import tool from langgraph.prebuilt import create_react_agent from langchain_leanroute import ChatLeanroute, new_run_id @tool def get_weather(city: str) -> str: """Return the current temperature for a city.""" return f"{city}: 22°C" def run(task: str) -> str: llm = ChatLeanroute( model="anthropic/claude-sonnet-5", agent_name="weather-agent", session_id=new_run_id(), # one per run ) agent = create_react_agent(llm, tools=[get_weather]) result = agent.invoke({"messages": [("user", task)]}) return result["messages"][-1].content print(run("What's the weather in Singapore?")) agent_name is sent as X-Agent-Name (without it, the API key's name is used) and session_id as X-Agent-Session-Id. Headers are fixed per instance, so create one ChatLeanroute per run. Every request also carries X-Leanroute-Client: langchain-leanroute/ .
Every other ChatOpenAI argument (temperature, max_tokens, timeout, max_retries, ...) passes through.
Both files in this release have provenance metadata.
agents ai-gateway langchain langgraph leanroute llm-gateway openai
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Both files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




