Home / Learn / Claude in LangChain — Just Add a Key
Claude in LangChain — Just Add a Key — LangChain Guide

Claude in LangChain — Just Add a Key

If you want to build with Claude in LangChain but do not have Anthropic access, a bought key removes the blocker. Buy one from claudeapikey.dev, set it as your ANTHROPIC_API_KEY, point base_url at the service, and your chains run. WELCOME5 covers your first five dollars while you prototype.

Buy a key, start building

You do not need an Anthropic account or an organisation to start a LangChain project on Claude.

The purchased key is a drop-in for an Anthropic key, so every LangChain example you find online works unchanged once you swap in your key and the service base URL.

For someone just learning LangChain, this removes the most frustrating early blocker — getting hold of a usable key at all. You can follow a tutorial start to finish on the day you decide to try it, rather than stalling on provider onboarding before you have written a line of code. Getting unblocked on day one is the difference between trying LangChain and putting it off. A bought key means you start the moment you decide to, with no provider approval standing in the way.

ChatAnthropic with your key

Construct ChatAnthropic with your bought key and base_url set to the service host root; the SDK appends /v1/messages. base_url is an alias for anthropic_api_url, so either keyword works.

That is the whole connection — model, key, base_url. No Anthropic console, no project setup, just the key you purchased pointed at the service.

Because base_url defaults to Anthropic's own host, the bought-key change is literally one extra argument on the constructor you would write anyway. Everything else in a standard ChatAnthropic example stays exactly as published, which is why copied tutorial code works for you with no further edits. A one-argument change to a standard example is about as low-friction as adoption gets. Published tutorial code runs unchanged once you add base_url, so you spend your time learning LangChain rather than fighting setup.

Or configure from the environment

Prefer env vars? Set ANTHROPIC_API_KEY to your bought key and ANTHROPIC_API_URL to the service, then a bare ChatAnthropic(model=...) call picks them up. ANTHROPIC_BASE_URL works as a fallback in some setups.

This keeps the key out of your source, which is the right pattern when you push a prototype to a teammate or a small deployment. The bought key behaves identically whether you pass it directly or through the environment.

It also means the same code can move between your bought key and any other Anthropic-compatible endpoint just by changing two environment values. You are never locked into one source — the purchased key is simply what those variables point at today. Keeping the key in the environment also makes handing a prototype to a teammate clean and safe. The source carries no secret of its own, so it can be shared or committed without a second thought.

Prototype on the free credit

That is plenty to confirm the key, base_url, and model id are all correct before you commit to anything.

Top up only when you are ready to run more. The bought-key model is pay-as-you-go, so there is no subscription and no minimum — you spend exactly what your chains consume.

Five dollars goes a long way while prototyping, where each run is usually a single short chain rather than heavy production traffic. By the time the credit is used up you will know whether the app does what you wanted, and topping up is then a deliberate choice rather than an upfront gamble. By the time the credit runs out you will know whether the app is worth taking further. Prototyping rarely burns much of five dollars.

The ChatOpenAI option

If your code already uses ChatOpenAI, you can keep it: set base_url to the service plus /v1 and pass your bought key. Note that this route includes /v1, where ChatAnthropic uses the bare root.

Either class works with the same purchased key, so you can adopt whichever fits your existing project without buying anything different or onboarding with a provider.

This is the gentlest path if you are moving an existing OpenAI-based prototype onto Claude: swap the base_url and the key, and your chains start running on Claude through your bought key. There is no need to rewrite to ChatAnthropic unless you want the native surface specifically. Swapping base_url and key on existing ChatOpenAI code is the shortest path from OpenAI to Claude. No rewrite to ChatAnthropic is required.

# pip install langchain-anthropic
from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(
    model="claude-sonnet-4-5",
    base_url="https://claudeapikey.dev",          # root; SDK adds /v1/messages
    api_key="<your gateway key>",
)
# Or via env:
#   ANTHROPIC_API_KEY=<key>
#   ANTHROPIC_API_URL=https://claudeapikey.dev   (or ANTHROPIC_BASE_URL fallback)
#
# OpenAI route instead:
#   from langchain_openai import ChatOpenAI
#   ChatOpenAI(base_url="https://claudeapikey.dev/v1", ...)   # /v1 here

Frequently asked questions

Do I need an Anthropic account for LangChain?
No. Buy a key from claudeapikey.dev and use it as ANTHROPIC_API_KEY with base_url={SITE} in ChatAnthropic.

ChatAnthropic or ChatOpenAI URL?
ChatAnthropic uses base_url={SITE} (root); ChatOpenAI uses {SITE}/v1. Both work with the same bought key.

Where does the bought key go?
As api_key in ChatAnthropic or as the ANTHROPIC_API_KEY env var — it behaves like an Anthropic key.

Start using Claude in minutes

Get an API key — no Anthropic account or waitlist required.

Get your API key

Claude API Key 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.