# One LangChain integration for every model family

> Markdown mirror of https://router.one/integrations/langchain for AI assistants and crawlers. Router One is an OpenAI-compatible LLM API gateway.
> Last updated: 2026-08-24

LangChain apps usually hardwire one provider class per model family. Because Router One is OpenAI-compatible, a single ChatOpenAI configuration reaches GPT, Claude, Gemini, and DeepSeek family models — swap the model string, keep the code. Every chain and agent step gets a per-request cost trace on the gateway side, without adding callbacks.

## Configure LangChain to use the Router One base URL

Pass the base URL and key to ChatOpenAI (Python) or ChatOpenAI from @langchain/openai (JS/TS):

`langchain_example.py`

```bash
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.router.one/v1",
    api_key="sk-your-router-one-key",
    model="<model-id-from-/models>",
)

print(llm.invoke("Hello!").content)
```

## Which model ID should LangChain send?

Copy the exact model ID from the /models page — IDs are case-sensitive, and the page lists each model's context window, capabilities, and current per-token rates. Create a dedicated API key per tool with its own maxSpend cap, so one runaway tool can't affect other workloads.

## Verify the LangChain call in your request trace

After your first request, open Dashboard → Logs to see its full trace: model, tokens, cost, latency, and status code. From here every LangChain call has a ledger and a trail instead of being a black box.

## FAQ

### Do I still need langchain-anthropic or other provider packages?

Not for models routed through the gateway — ChatOpenAI with the Router One base URL covers every chat-capable model in the catalog. Change the model string to switch families.

### Which models can LangChain use through the gateway?

Any chat-capable model in the catalog — GPT, Claude, Gemini, Grok, DeepSeek, GLM, MiniMax, and Doubao families. The /models page is the source of truth for model IDs and per-token rates.

### Does this work from Mainland China?

Yes. The gateway is reachable from Mainland China without a VPN, and the configuration is identical to the global setup.

### How do I debug a 401/403/429?

Open Dashboard → Logs first to see whether requests reached the gateway and with what status, then walk the error-codes reference to check env vars, key status, and limits.

## See also

- All integration guides: https://router.one/integrations
- Debug 401/403/429 in LangChain: https://router.one/llm-api-error-codes
- Vercel AI SDK setup: https://router.one/integrations/vercel-ai-sdk
- OpenAI SDK setup: https://router.one/integrations/openai-sdk
- What the gateway layer does: https://router.one/llm-api-gateway
- OpenAI-compatible API: https://router.one/openai-compatible-api
- API docs: https://router.one/docs
- Canonical page: https://router.one/integrations/langchain
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
