LangChain Integration
LangChain connects to KOPRouter through the OpenAI-compatible ChatOpenAI — swap the Base URL and API key.
- LangChain installed
- A KOPRouter API key (prefixed with
sk-)
Python
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://koprouter.kopglobal.com/v1",
api_key="sk-...",
model="MODEL_ID",
)
resp = llm.invoke("Hello!")
print(resp.content)
Streaming
for chunk in llm.stream("Introduce yourself"):
print(chunk.content, end="", flush=True)
If your network cannot reach KOPRouter directly (e.g. mainland China), configure a VPN or proxy first. LangChain (Python) reads the HTTPS_PROXY / HTTP_PROXY environment variables — see Network & Proxy for how to set them.