llmboxDocumentationSign in
Integrations · LangChain

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

  • ChatOpenAI sends requests to /v1/chat/completions; recent versions of @langchain/openai switch some models to /v1/responses on their own — the gateway supports both.
  • Usage and tokens of every request show up in the cabinet.
  • OpenAIEmbeddings calls /v1/embeddings with an embedding model from the catalog. For models outside the OpenAI family, pass check_embedding_ctx_length=False so LangChain sends text rather than OpenAI vocabulary tokens.

Troubleshooting

SymptomCause and fix
404 model_not_foundThe model ID has a typo — check GET/v1/models.
401 invalid_api_keyWrong or revoked key.
404 model_not_found on embeddingsOpenAIEmbeddings is set to a text model — use an embedding model from the catalog.