LangChain's ChatOpenAI class accepts a custom base_url, which is all you need to route your chains and agents through OpenDunes. Model slugs follow the provider/model format used across the OpenDunes catalog.
pip install langchain-openai
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="anthropic/claude-opus-4.8",
openai_api_key=os.environ["OPENDUNES_API_KEY"],
openai_api_base="https://opendunes.com/api/v1",
)
response = llm.invoke("What is the capital of Algeria?")
print(response.content)
import os
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
llm = ChatOpenAI(
model="google/gemini-2.5-pro",
openai_api_key=os.environ["OPENDUNES_API_KEY"],
openai_api_base="https://opendunes.com/api/v1",
streaming=True,
)
for chunk in llm.stream([HumanMessage(content="Tell me about Algiers in two sentences.")]):
print(chunk.content, end="", flush=True)
import os
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(
model="meta-llama/llama-4-maverick",
openai_api_key=os.environ["OPENDUNES_API_KEY"],
openai_api_base="https://opendunes.com/api/v1",
)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant. Answer concisely."),
("human", "{question}"),
])
chain = prompt | llm
result = chain.invoke({"question": "How do I top up my OpenDunes balance?"})
print(result.content)
npm install @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "anthropic/claude-sonnet-5",
apiKey: process.env.OPENDUNES_API_KEY,
configuration: {
baseURL: "https://opendunes.com/api/v1",
},
});
const response = await llm.invoke("What is the capital of Algeria?");
console.log(response.content);
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "openai/gpt-5.4",
apiKey: process.env.OPENDUNES_API_KEY,
configuration: {
baseURL: "https://opendunes.com/api/v1",
},
streaming: true,
});
const stream = await llm.stream("Write a haiku about the Atlas Mountains.");
for await (const chunk of stream) {
process.stdout.write(chunk.content as string);
}
- Use
openai_api_base (Python) or configuration.baseURL (JS) — not base_url directly on the constructor — to avoid LangChain's built-in OpenAI base URL validation.
- OpenDunes model slugs contain a slash (
provider/model). Pass the full slug as the model argument.
- Browse available models at /models or query
GET /api/models.