# LangChain

> Point LangChain's ChatOpenAI, ChatAnthropic or ChatGoogleGenerativeAI at this gateway with one base URL (Python / JS)

Source: https://qd.zsopc.com/en/docs/integrations/langchain

> All three [LangChain](https://docs.langchain.com) 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-openai` 1.8.0, `langchain-anthropic` 1.7.10 and `langchain-google-genai` 4.5.0, and JS `@langchain/openai` 1.8.4 and `@langchain/anthropic` 1.6.5.

## Get an API key

Create one at [qd.zsopc.com/dashboard/keys](https://qd.zsopc.com/dashboard/keys). The examples read it from an environment variable:

```bash
export PLATFORM_API_KEY="sk-gpushare-xxx"
```

## Python

```bash
pip install -U langchain-openai langchain-anthropic langchain-google-genai
```

### ChatOpenAI (OpenAI protocol, reaches every text model)

```python
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`, pass `use_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 to `True` or `False`. Which models support `/v1/responses`: see the [compatibility matrix](../reference/compatibility-matrix.md).
- Instead of `base_url` you can also set the `OPENAI_BASE_URL` environment variable.

### ChatAnthropic (Anthropic protocol)

```python
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)

```python
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

```bash
npm install @langchain/openai @langchain/anthropic
```

```ts
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](../guides/tool-calling.md).

## 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](../reference/models.md) 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](https://qd.zsopc.com/dashboard/billing) |

Full error reference: [Error codes](../reference/errors.md).

## Related pages

- [OpenAI SDK](../sdks/openai-sdk.md) / [Anthropic SDK](../sdks/anthropic-sdk.md) / [Gemini SDK](../sdks/gemini-sdk.md) — full examples for the three SDKs
- [LiteLLM](./litellm.md) — a unified calling layer and proxy
- [Vercel AI SDK](./vercel-ai-sdk.md) — TypeScript app framework
