Tool setup
LangChain Integration Guide
Point LangChain's ChatOpenAI to SeaLink for chat, tool calling, and RAG with OpenAI-compatible chat models. Python and JS/TS both supported.
Key Concept
LangChain's ChatOpenAI supports a custom base_url. ChatOpenAI-based chat, streaming, tool-calling, and RAG examples can use the same SeaLink connection settings; exact capability support depends on the model and LangChain version.
Python
from langchain_openai import ChatOpenAIllm = ChatOpenAI(base_url="https://test.sealink.io/v1",api_key="sk-sealink-your-key",model="gpt-4o-mini",)response = llm.invoke("Hello, SeaLink.")print(response.content)
from langchain_openai import ChatOpenAIllm = ChatOpenAI(base_url="https://test.sealink.io/v1",api_key="sk-sealink-your-key",model="gpt-4o-mini",streaming=True,)for chunk in llm.stream("Write a short poem about Singapore."):print(chunk.content, end="")
from langchain_openai import ChatOpenAIfrom langchain_core.tools import tool@tooldef multiply(a: int, b: int) -> int:"""Multiply two numbers."""return a * bllm = ChatOpenAI(base_url="https://test.sealink.io/v1",api_key="sk-sealink-your-key",model="gpt-4o-mini",).bind_tools([multiply])response = llm.invoke("What is 17 times 42?")print(response.tool_calls)
JavaScript / TypeScript
import { ChatOpenAI } from "@langchain/openai";const llm = new ChatOpenAI({configuration: {baseURL: "https://test.sealink.io/v1",apiKey: process.env.SEALINK_API_KEY,},model: "gpt-4o-mini",});const response = await llm.invoke("Hello, SeaLink.");console.log(response.content);
Installation
Python install
pip install langchain langchain-openaiThe langchain-openai package includes ChatOpenAI with built-in base_url support.
JS/TS install
npm install @langchain/openai @langchain/coreRequires Node.js ≥ 18.
Common Issues
ImportError: No module named 'langchain_openai'
You need the langchain-openai package. Run: pip install langchain-openai. Note: pip install langchain alone doesn't include OpenAI integration.
Empty or malformed model output
Verify the model ID is correct. Some models need additional LangChain configuration; test with a general chat model first to confirm connectivity.
Streaming doesn't work
In Python, streaming=True only affects .stream() — .invoke() won't stream. In JS/TS, ensure streaming: true is set.