SDKs and frameworks
LangChain
Point langchain-openai's base_url at TokRouter and use any gateway model inside LangChain.
LangChain's OpenAI integration accepts a custom base_url — point it at the gateway.
pip install langchain-openaiimport os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-5.4-mini",
api_key=os.environ["TOKROUTER_API_KEY"],
base_url="https://api.tokrouter.dev/v1",
)
print(llm.invoke("Explain RAG in one sentence").content)Mixing vendors in one chain
planner = ChatOpenAI(
model="claude-opus-5-5",
api_key=os.environ["TOKROUTER_API_KEY"],
base_url="https://api.tokrouter.dev/v1",
)
worker = ChatOpenAI(
model="deepseek-v4-flash",
api_key=os.environ["TOKROUTER_API_KEY"],
base_url="https://api.tokrouter.dev/v1",
)
plan = planner.invoke("Split 'refactor the login module' into three steps; output only the list").content
print(worker.invoke(f"Write the implementation notes for step one:\n{plan}").content)Streaming and tools
stream() and bind_tools() use the same OpenAI protocol fields, and the gateway behaves identically.
Tool-use support varies by model — see Tool calling.