The base_url Is the Whole Integration: LangChain Through a Gateway A developer demonstrated that pointing LangChain's ChatOpenAI constructor at a gateway base_url (nRouter at api.nrouter.ai/v1) with a virtual key routes all chain traffic through the gateway without changing prompts, memory, or LCEL pipelines. The setup adds server-side guardrails (PII redaction, prompt-injection filtering, keyword blocks), per-call routing policies via nrouter_auto, nrouter_optimize, nrouter_cost_band and nrouter_fallbacks, and per-response cost and trace headers (x-nr-request-cost, x-nr-request-id, x-nr-model). OpenAIEmbeddings can use the same endpoint so indexed documents are screened before embedding. Every LangChain app has a connection point, and it's smaller than you think. It's the ChatOpenAI constructor. Model name, key, done — that object decides which provider takes every call your chain makes, what a retry looks like, and what evidence exists afterwards. ChatOpenAI takes a base url. Point it at a gateway — here, nRouter at https://api.nrouter.ai/v1 https://api.nrouter.ai/v1 — with a virtual key, and the chain's traffic runs through the gateway. Here's the part that matters: nothing else changes. python from langchain openai import ChatOpenAI llm = ChatOpenAI model="nrouter/auto", api key="sk-nrouter-...", base url="https://api.nrouter.ai/v1", temperature=0.2, timeout=60, max retries=2, model kwargs={"nrouter cache": True}, Prompt templates: unchanged. Memory: unchanged. The LCEL pipe you composed — prompt | llm | StrOutputParser — unchanged, streaming included. JavaScript is the same shape with @langchain/openai. So what does the endpoint buy you, if the code doesn't change? Guardrails that live outside your repos. Prompts get screened server-side before a provider sees them: PII detection and redaction, prompt-injection filtering, keyword blocks. A blocked call comes back as a plain openai.BadRequestError , so the error handling you already wrote catches it. Rate limits surface as RateLimitError . No new exception taxonomy to learn. Routing as a per-call decision. With nrouter/auto in the model slot, model kwargs carries the policy per call: nrouter optimize : quality , balanced or cost nrouter cost band : low , mid or high under cost optimisation nrouter fallbacks : the models to try when the first choice can't take the call A triage chain and a drafting chain can share a codebase and still make different trade-offs, because the policy travels with the request. A receipt on every response. Priced responses return the exact list rate in the x-nr-request-cost header — flat list price, zero token markup — alongside x-nr-request-id for tracing and x-nr-model for what actually served the call. Token usage is in response metadata as usual, so the two reconcile without a billing export. Embeddings on the same endpoint. OpenAIEmbeddings takes the same base url. The documents you index are untrusted text by definition; screening them before embedding is the half of the integration most teams forget. The framework is the composition layer. The endpoint is the control layer. Keeping those jobs separate is the whole trick — full setup for Python and JavaScript is in the guide: https://nrouter.ai/docs/frameworks/langchain https://nrouter.ai/docs/frameworks/langchain The chain doesn't change. The endpoint does.