ModelSiteAPI

LangChain

Use ChatOpenAI and ChatAnthropic with ModelSite: the base URLs, why Anthropic needs a Bearer header, and a reasoning-token tip

Status: run against ModelSite with langchain-openai 1.7.2 and langchain-anthropic 1.7.6 on 2026-10-24: both answered correctly.

OpenAI format

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="glm-5.3-flash",
    base_url="https://api.modelsite.ai/v1",
    api_key=os.environ["MODELSITE_API_KEY"],
    max_tokens=400,
)
print(llm.invoke("Reply with the single word: pong").content)   # pong

Anthropic format

ChatAnthropic(api_key=...) sends the key in the x-api-key header, which the platform does not read. We reproduced the resulting 401 missing or invalid authorization header. Send the key as a Bearer header instead.

import os
from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(
    model="glm-5.3-flash",
    base_url="https://api.modelsite.ai",          # no /v1
    api_key="unused",                              # required by the class, not read by ModelSite
    default_headers={"Authorization": f"Bearer {os.environ['MODELSITE_API_KEY']}"},
    max_tokens=400,
)
print(llm.invoke("Reply with the single word: pong").content)

With this form the request succeeded. The reply content comes back as a list that includes a thinking block before the text.

Tip: give reasoning models room

glm-5.3-flash thinks before it answers, and the thinking counts against max_tokens. With max_tokens=20 our OpenAI-format call returned an empty string; with 400 it returned pong. Use a few hundred tokens or more for short answers.

Limits

Streaming, tool calling and embeddings through LangChain were not part of this check. See SDKs, Frameworks and Clients for the other frameworks.

On this page