LangChain
Chains and agents, European providers.
Point `ChatOpenAI` at our base URL. The LangChain patterns most people use, chains, agents, RAG, structured outputs, all on European infrastructure.
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url=class="s">"https://api.melious.ai/v1",
api_key=class="s">"sk-mel-<YOUR_API_KEY>",
model=class="s">"glm-5.1",
)
response = llm.invoke(class="s">"Name three Hanseatic cities.")
print(response.content)What is LangChain?
How to use LangChain with Melious?
-
Install LangChain
Install
langchainandlangchain-openaifor Chat Completions, pluslangchain-communityandduckduckgo-searchif you want to follow the agent example. We track the OpenAI shape, so LangChain's core OpenAI integration is the right entry point.Shellpip install langchain langchain-openai langchain-community duckduckgo-search export MELIOUS_API_KEY=sk-mel-<YOUR_API_KEY> -
Create an LLM
ChatOpenAItakes the Melious base URL, your key, and a model ID. Wire it into any chain, runnable, or agent. LangChain doesn't know anything's different.Pythonimport os from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url=class="s">"https://api.melious.ai/v1", api_key=os.environ[class="s">"MELIOUS_API_KEY"], model=class="s">"glm-5.1", ) -
Build an agent
Tool-calling agents work unchanged because Melious mirrors OpenAI's
tool_callsschema. Wrap the LLM increate_tool_calling_agent, hand it a list of tools, and go.Pythonfrom langchain.agents import AgentExecutor, create_tool_calling_agent from langchain_core.prompts import ChatPromptTemplate from langchain_community.tools import DuckDuckGoSearchRun tools = [DuckDuckGoSearchRun()] prompt = ChatPromptTemplate.from_messages([ (class="s">"system", class="s">"You are a careful researcher."), (class="s">"human", class="s">"{input}"), (class="s">"placeholder", class="s">"{agent_scratchpad}"), ]) agent = create_tool_calling_agent(llm, tools, prompt) executor = AgentExecutor(agent=agent, tools=tools) executor.invoke({class="s">"input": class="s">"What's the capital of the Hanseatic League?"})
Three steps from here.
Grab a Melious key. Pick your tool. Follow the guide. Same client, now answering from Europe.