LangChain
Point LangChain's ChatOpenAI, ChatAnthropic or ChatGoogleGenerativeAI at this gateway with one base URL (Python / JS)
All three LangChain model classes take a custom base URL, so the rest of your code stays as it is. Checked on 2026-11-15 against the official docs and source of Python
langchain-openai1.8.0,langchain-anthropic1.7.10 andlangchain-google-genai4.5.0, and JS@langchain/openai1.8.4 and@langchain/anthropic1.6.5.
Get an API key#
Create one at qd.zsopc.com/dashboard/keys. The examples read it from an environment variable:
export PLATFORM_API_KEY="sk-gpushare-xxx"
Python#
pip install -U langchain-openai langchain-anthropic langchain-google-genai
ChatOpenAI (OpenAI protocol, reaches every text model)#
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-6.1-sol", # claude-sonnet-4-6, deepseek-v4.1-flash and others work too
base_url="https://qd.zsopc.com/v1",
api_key=os.environ["PLATFORM_API_KEY"],
stream_usage=True, # off by default with a custom base_url; adds token usage to streams
)
print(llm.invoke("Introduce yourself in one sentence").content)
- For
/v1/responses, passuse_responses_api=True. Without it LangChain may switch to the Responses API on its own based on the model name or the tools you use, so with a third-party endpoint set it explicitly toTrueorFalse. Which models support/v1/responses: see the compatibility matrix. - Instead of
base_urlyou can also set theOPENAI_BASE_URLenvironment variable.
ChatAnthropic (Anthropic protocol)#
from langchain_anthropic import ChatAnthropic
claude = ChatAnthropic(
model="claude-sonnet-4-6",
base_url="https://qd.zsopc.com", # no /v1 — the SDK adds /v1/messages
api_key=os.environ["PLATFORM_API_KEY"],
)
This platform accepts both x-api-key and Authorization: Bearer on /v1/messages, so every version of the anthropic SDK works as is.
ChatGoogleGenerativeAI (Gemini protocol)#
from langchain_google_genai import ChatGoogleGenerativeAI
gemini = ChatGoogleGenerativeAI(
model="gemini-3.1-pro-low",
base_url="https://qd.zsopc.com",
api_version="v1beta",
api_key=os.environ["PLATFORM_API_KEY"],
)
JavaScript / TypeScript#
npm install @langchain/openai @langchain/anthropic
import { ChatOpenAI } from "@langchain/openai";
import { ChatAnthropic } from "@langchain/anthropic";
const llm = new ChatOpenAI({
model: "gpt-6.1-sol",
apiKey: process.env.PLATFORM_API_KEY,
configuration: { baseURL: "https://qd.zsopc.com/v1" },
});
const claude = new ChatAnthropic({
model: "claude-sonnet-4-6",
apiKey: process.env.PLATFORM_API_KEY,
anthropicApiUrl: "https://qd.zsopc.com", // no /v1
});
console.log((await llm.invoke("Hello")).content);
Which class to use#
- One code path for every vendor:
ChatOpenAI. The gateway translates the protocol for Claude, Gemini and the other non-OpenAI models. - Request parameters that only one vendor's protocol has: that vendor's class.
- Tool calling works on all three protocols; see Tool calling.
Troubleshooting#
| Symptom | What to check |
|---|---|
| 404 | The OpenAI base URL needs /v1; the Anthropic and Gemini ones don't |
401 invalid_api_key | Whether the key was copied in full (76 characters), and whether the environment variable actually reaches the process |
400 model_not_found | Model ID spelling — it must match Models exactly |
| No token usage on streams | Add stream_usage=True to ChatOpenAI |
402 quota_exceeded | Balance exhausted. Every key shares one account balance — top up on the Top up page |
Full error reference: Error codes.
Related pages#
- OpenAI SDK / Anthropic SDK / Gemini SDK — full examples for the three SDKs
- LiteLLM — a unified calling layer and proxy
- Vercel AI SDK — TypeScript app framework