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

Install

pip install langchain-openai langchain-anthropic

Code

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)

Good to know

  • Python: use_responses_api=False keeps 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=True makes 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.

One key for every model here.

Top up from $10, change one URL, and pay only for the tokens you use.