LangChain
LangChain's ChatOpenAI takes a base URL, so it talks to OpenCheap as it would to OpenAI. Pass the key yourself: ChatOpenAI otherwise looks for OPENAI_API_KEY.
What you need
- Base URL
https://api.opencheap.si/v1 - API keyA
kl_live_…key from the console, kept inOPENCHEAP_API_KEY. - ModelAn id from Models, for example
claude-sonnet-5.
pip install langchain-openaiChat and streaming
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="claude-sonnet-5",
base_url="https://api.opencheap.si/v1",
api_key=os.environ["OPENCHEAP_API_KEY"],
)
print(llm.invoke("Say hello in five words.").content)
for chunk in llm.stream("Count from 1 to 5."):
print(chunk.content, end="", flush=True)Tool calls
from langchain_core.tools import tool
@tool
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"Sunny in {city}"
msg = llm.bind_tools([get_weather]).invoke("What's the weather in Paris?")
print(msg.tool_calls)msg.tool_calls holds the call to get_weather with city set to Paris. The same llm goes into chains, agents and LangGraph wherever a chat model is expected.
What was checked
Run on October 28, 2026 with langchain-openai 1.7.2 and langchain-core 1.7.0 on claude-sonnet-5: invoke, stream and bind_tools as above; the tool call came back with city set to Paris. LangGraph was not run.