Point LangChain at Claude on the Gateway
LangChain is where a lot of production Claude work actually lives — chains, agents, retrieval pipelines. Pointing it at the AI Prime Tech gateway is mostly a matter of one base-URL argument, and there are two clean routes depending on which wire format you want.
The ChatAnthropic route
Install langchain-anthropic and construct ChatAnthropic with the model, your key, and base_url set to the gateway host root. The Anthropic SDK underneath appends /v1/messages itself, so you pass the root and nothing more.
base_url here is an alias for anthropic_api_url, which is why both names appear in examples around the web. Either keyword reaches the same setting; base_url is just the friendlier spelling.
Under the hood ChatAnthropic wraps the official Anthropic SDK, so any base-URL behaviour you have seen in the raw SDK carries over unchanged. That is reassuring for a gateway, because it means you are relying on the same well-trodden path the SDK uses rather than a LangChain-specific quirk. Relying on the SDK's own base-URL handling means your gateway setup rests on well-tested ground. You inherit the same behaviour every Anthropic SDK user depends on, rather than a fragile LangChain-only path.
Configure it from the environment
If you would rather not hard-code anything, set ANTHROPIC_API_KEY and ANTHROPIC_API_URL in the environment. ChatAnthropic reads both, so a bare ChatAnthropic(model=...) call picks up the gateway automatically.
Some setups also honour ANTHROPIC_BASE_URL as a fallback. Keeping the endpoint in the environment is the cleaner pattern for deployments where the same code runs against different gateways per stage.
The environment route also keeps your gateway choice out of the code entirely, which is handy when the same LangChain app needs to point at the gateway in production and at a local endpoint in development. You change an env value rather than a line of source, and the application picks it up on restart. Keeping the endpoint in the environment is the pattern that scales best across deployment stages. Dev, staging, and production differ by a value, not a code branch, which keeps your application logic identical everywhere.
The ChatOpenAI alternative
If you prefer to speak the gateway's OpenAI-compatible surface, use ChatOpenAI from langchain-openai instead and set base_url to the gateway with /v1 on the end. Note the difference: this route wants /v1, where ChatAnthropic wanted the bare root.
That distinction is the single most common LangChain mistake with a gateway. The Anthropic class adds the version path for you; the OpenAI class expects you to include /v1 yourself.
Reach for this route when your codebase is already standardised on ChatOpenAI and you want Claude to slot into that shape with minimal change. It is also the natural choice if the gateway happens to serve Claude better over its OpenAI-compatible surface than its native one for your particular use. Pick the class that matches your codebase and the gateway slots in with the least disruption. Both classes reach the same Claude models behind the gateway.
Use it in chains and agents
Once constructed, the model object plugs into the rest of LangChain unchanged — pipe it into chains, hand it to an agent executor, or wrap it with structured output. Nothing downstream needs to know it is pointed at a gateway.
Tool calling flows through as well, so LangChain agents that bind tools to the model work against Claude on the gateway exactly as they would against the default endpoint.
This is the real payoff of using a gateway through LangChain: the abstraction holds, so retrieval chains, output parsers, and agent executors you have already written keep working. You are only changing where the model object points, not how the rest of your pipeline is built. Because the abstraction holds, the work you have already invested in your pipeline carries straight over. Only the model object's destination changes.
Pick the right model
Use claude-sonnet-4-5 for most chain and agent work and claude-opus-4-8 for the hardest reasoning steps. Because the model is just a string, you can switch by changing one argument or one environment value.
For mixed pipelines you can even construct two model objects — a fast one for routine steps and a strong one for the critical step — both pointed at the same gateway with the same key.
Routing per step like this is where a multi-model gateway earns its place: one endpoint and one key serve both objects, so the only thing that differs between them is the model string. You get fine-grained model control without juggling separate credentials or endpoints. Per-step model routing through one key and one endpoint is multi-model control at its most practical. The model string is the only thing that varies between objects.
# pip install langchain-anthropic
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(
model="claude-sonnet-4-5",
base_url="https://aiprimetech.io", # root; SDK adds /v1/messages
api_key="<your gateway key>",
)
# Or via env:
# ANTHROPIC_API_KEY=<key>
# ANTHROPIC_API_URL=https://aiprimetech.io (or ANTHROPIC_BASE_URL fallback)
#
# OpenAI route instead:
# from langchain_openai import ChatOpenAI
# ChatOpenAI(base_url="https://aiprimetech.io/v1", ...) # /v1 here
Frequently asked questions
How do I point LangChain at Claude on a gateway?
Use ChatAnthropic with base_url={SITE} (host root); the SDK appends /v1/messages. Or set ANTHROPIC_API_URL in the environment.
Is base_url the same as anthropic_api_url?
Yes — base_url is an alias for anthropic_api_url in ChatAnthropic. Either keyword sets the same endpoint.
What about the ChatOpenAI route?
Use ChatOpenAI(base_url={SITE}/v1) for the OpenAI-compatible surface. Note this route includes /v1, unlike ChatAnthropic.
Which env vars does ChatAnthropic read?
ANTHROPIC_API_KEY and ANTHROPIC_API_URL, with ANTHROPIC_BASE_URL as a fallback in some setups.
Get an API key — no Anthropic account or waitlist required.
Get your API keyAI Prime Tech is an independent API gateway. It is not affiliated with, endorsed by, or a reseller of Anthropic. Claude and related model names are trademarks of their respective owners.