LangChain Integration
LangChain provides a standard interface for building applications with LLMs.
Python
Installation
pip install langchain langchain-openaiUsage
from langchain_openai import ChatOpenAI
chat = ChatOpenAI(
model="anthropic/claude-opus-4.5",
temperature=0.7,
openai_api_key="your-langmart-api-key",
openai_api_base="https://api.langmart.ai/v1",
)
response = chat.invoke("Tell me a fun fact about space.")
print(response.content)With Message Types
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is the capital of France?"),
]
response = chat.invoke(messages)
print(response.content)JavaScript / TypeScript
Installation
npm install @langchain/openai @langchain/coreUsage
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
const chat = new ChatOpenAI(
{
model: "openai/gpt-5.2",
temperature: 0.8,
apiKey: "your-langmart-api-key",
},
{
baseURL: "https://api.langmart.ai/v1",
}
);
const response = await chat.invoke([
new SystemMessage("You are a helpful assistant."),
new HumanMessage("Hello, how are you?"),
]);
console.log(response.content);Streaming
from langchain_openai import ChatOpenAI
chat = ChatOpenAI(
model="openai/gpt-5.2",
streaming=True,
openai_api_key="your-langmart-api-key",
openai_api_base="https://api.langmart.ai/v1",
)
for chunk in chat.stream("Write a haiku about coding"):
print(chunk.content, end="", flush=True)With Chains
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
chat = ChatOpenAI(
model="anthropic/claude-opus-4.5",
openai_api_key="your-langmart-api-key",
openai_api_base="https://api.langmart.ai/v1",
)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a {role}."),
("human", "{input}"),
])
chain = prompt | chat
response = chain.invoke({"role": "poet", "input": "Write about the moon"})
print(response.content)