LangChain
Connecting LangChain in Python and JS through ChatOpenAI with the gateway base URL.
LangChain connects through the standard ChatOpenAI class — set the gateway
base URL, your key and a model ID.
Quick start
pip install langchain-openai
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://llmbox.cc/v1",
api_key="$LLMBOX_API_KEY",
model="openai/gpt-5.6-sol",
)
print(llm.invoke("Hello!").content)
Take the model ID from the model catalog; switching models means
changing the model string, the rest of your chains and agents stays the same.
Streaming and tools
llm.stream(...) returns the answer in chunks, and llm.bind_tools([...])
(bindTools in JS) enables function calling — the gateway passes your tools to
the model as is, and tool_calls come back in the usual LangChain shape.
How it works
ChatOpenAIsends requests to/v1/chat/completions; recent versions of@langchain/openaiswitch some models to/v1/responseson their own — the gateway supports both.- Usage and tokens of every request show up in the cabinet.
OpenAIEmbeddingscalls/v1/embeddingswith an embedding model from the catalog. For models outside the OpenAI family, passcheck_embedding_ctx_length=Falseso LangChain sends text rather than OpenAI vocabulary tokens.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
404 model_not_found | The model ID has a typo — check GET/v1/models. |
401 invalid_api_key | Wrong or revoked key. |
404 model_not_found on embeddings | OpenAIEmbeddings is set to a text model — use an embedding model from the catalog. |