LangChain
LangChain's OpenAI integrations accept a custom base URL, so the gateway drops in with no framework-specific glue: use ChatOpenAI (or OpenAIEmbeddings) pointed at /v1 with a virtual key, and request models by their catalog alias.
Python
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://aam.example.com/v1",
api_key="sk-your-virtual-key",
model="fast", # a catalog alias
)
print(llm.invoke("hello").content)
Embeddings for RAG pipelines route through the same governed pipeline:
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(
base_url="https://aam.example.com/v1",
api_key="sk-your-virtual-key",
model="embed", # an alias whose deployment supports embeddings
)
JavaScript / TypeScript
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "fast",
apiKey: process.env.AAM_VIRTUAL_KEY,
configuration: { baseURL: "https://aam.example.com/v1" },
});
LangGraph and agents
Agent workloads are where the gateway earns its keep: an agent loop can burn tokens fast and call tools with sensitive arguments. Everything above applies unchanged to LangGraph — the model client is the same ChatOpenAI — and you get, per agent:
- One key per agent. Issue each agent its own virtual key so audit, spend, and containment are attributable — quarantining one agent never touches the others.
- A budget and rate limit on the key as a blast-radius cap for runaway loops: a
KEY-scope budget or RPM limit fails the loop with429instead of a surprise invoice. - Guardrails on tool calls. Tool-call arguments are screened (flag/block, never mutated) — see Guardrails.
- Vendor swap without redeploys. Re-point the alias in the catalog to move all agents to a new model at once.
Model switching in multi-model chains
Register several aliases (fast, smart, local) and instantiate one ChatOpenAI per alias. Which vendor serves each alias is a catalog decision, not a code decision — including load-balanced and failover configurations.
Related
- OpenAI SDK & Codex — the underlying SDK behaviour LangChain inherits.
- Ollama, vLLM & LiteLLM — fully local chains.