LangChain
LangChain can call OdiRouter through OpenAI-compatible chat model integrations. Set the API key, model, and Base URL on the ChatOpenAI client.
Requirements
Section titled “Requirements”| Requirement | Value |
|---|---|
| Package | langchain-openai or the OpenAI integration used by your LangChain version |
| Base URL | https://www.odirouter.ai/v1 |
| API Key | OdiRouter API key |
| Model | An OdiRouter LLM model ID |
Install
Section titled “Install”pip install langchain-openaiConfigure ChatOpenAI
Section titled “Configure ChatOpenAI”import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI( model="gpt-5.5", api_key=os.environ["ODIROUTER_API_KEY"], base_url="https://www.odirouter.ai/v1",)Invoke The Model
Section titled “Invoke The Model”response = llm.invoke("Reply with a one-line LangChain integration test.")
print(response.content)Use In A Chain
Section titled “Use In A Chain”from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([ ("system", "You are a concise engineering assistant."), ("user", "{question}"),])
chain = prompt | llm
result = chain.invoke({"question": "List two integration checks."})
print(result.content)Troubleshooting
Section titled “Troubleshooting”| Symptom | Fix |
|---|---|
| LangChain calls OpenAI directly | Confirm base_url is set on the active ChatOpenAI instance |
401 response | Set ODIROUTER_API_KEY in the process environment |
| Model not found | Copy the model ID from GET https://www.odirouter.ai/v1/models |
| Tool calling fails | Confirm the selected OdiRouter model supports the tool-calling behavior your chain requires |