Use /model with LangChain
Point LangChain's ChatOpenAI and ChatAnthropic at /model, in Python and JavaScript.
Checked November 23, 2026
LangChain's OpenAI and Anthropic chat models both work with /model: set the base URL and the key.
Before you start
- A /model API key: create one on the API keys page and add credit on the credits page.
Install
pip install langchain-openai langchain-anthropicnpm install @langchain/openai @langchain/anthropicCode
import os
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
gpt = ChatOpenAI(
model="gpt-6.1-sol",
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
use_responses_api=False, # keep GPT on /v1/chat/completions
stream_usage=True, # token counts in streamed answers too
)
claude = ChatAnthropic(
model="claude-sonnet-5-5",
base_url="https://api.slashmodel.com", # no /v1: the SDK adds it
api_key=os.environ["SLASHMODEL_API_KEY"],
)
print(gpt.invoke("Say hello in French.").text)
print(claude.invoke("Say hello in Spanish.").text)import { ChatAnthropic } from "@langchain/anthropic";
import { ChatOpenAI } from "@langchain/openai";
const gpt = new ChatOpenAI({
model: "gpt-6.1-sol",
apiKey: process.env.SLASHMODEL_API_KEY,
configuration: { baseURL: "https://api.slashmodel.com/v1" },
});
const claude = new ChatAnthropic({
model: "claude-sonnet-5-5",
apiKey: process.env.SLASHMODEL_API_KEY,
anthropicApiUrl: "https://api.slashmodel.com", // no /v1: the SDK adds it
});
console.log((await gpt.invoke("Say hello in French.")).text);
console.log((await claude.invoke("Say hello in Spanish.")).text);Good to know
- Python:
use_responses_api=Falsekeeps GPT on chat completions, which is what this sample was run on. Otherwise LangChain sends GPT-6 requests that carry tools to the Responses API, which /model serves for GPT models, without stored responses. - Python:
stream_usage=Truemakes streamed answers report their token counts. LangChain leaves it off when you set a base URL. - The OpenAI base URL ends in
/v1; the Anthropic one doesn't, because the Anthropic SDK adds it.