無制限 Claude で LangChain を構築する

無制限 Claude で LangChain を構築する

LangChain のチェーンとエージェントは、1つのリクエストを多数のモデル呼び出しに展開します——検索、推論ステップ、ツールループ。この増幅がトークン課金を予測しにくくし、まさにこのケースこそ定額・無制限の Claude プランが解決のために作られたものです。

One base_url, no meter

Construct ChatAnthropic with your key and base_url set to the unlimited gateway's host root; the SDK appends /v1/messages. From that point every call your chains make draws from the flat-rate plan.

base_url is an alias for anthropic_api_url, so either keyword works. With unlimited behind it, you stop counting how many calls a chain makes per invocation.

That last point quietly changes how you build. On metered access developers obsess over call counts and cache aggressively to keep costs down; with unlimited you can let a chain make the calls it naturally needs and optimise for correctness first, knowing the cost is fixed regardless. Optimising for correctness before cost is a freedom metered access rarely lets you enjoy. You let the chain make the calls it genuinely needs, rather than caching aggressively just to keep a bill down.

Configure from the environment

Set ANTHROPIC_API_KEY and ANTHROPIC_API_URL in the environment and a bare ChatAnthropic(model=...) picks up the unlimited gateway automatically. ANTHROPIC_BASE_URL works as a fallback in some setups.

This is handy for the kind of long-running services where LangChain often lives. A scheduled job or a server endpoint can run as much Claude traffic as it needs without the env ever pointing at a metered account.

It is especially valuable for background workers and batch jobs, which generate steady traffic with nobody watching the spend. Pointing those at an unlimited gateway through the environment means a queue that drains overnight costs the same whether it processes ten items or ten thousand. Background workers and overnight batches are where a flat rate quietly removes the most anxiety. A queue that drains overnight costs the same whatever its size, so you schedule it without a second thought.

The ChatOpenAI variant

Prefer the OpenAI-compatible surface? Use ChatOpenAI with base_url set to the gateway plus /v1. Remember the asymmetry: ChatOpenAI wants /v1 in the URL, while ChatAnthropic wants the bare root.

Either route lands on the same unlimited plan. Pick whichever matches the rest of your stack; the flat-rate billing is identical regardless of which class you build.

If you are migrating an existing OpenAI-based LangChain app onto Claude, this route lets you keep your code shape and just repoint it at the unlimited gateway. The model gets stronger and the cost gets predictable in the same change, with no rewrite of your chain logic. A repoint rather than a rewrite is the gentlest possible migration onto Claude. The model gets stronger and the cost gets predictable in one change, with no rework of your chain logic.

Why fan-out wants flat-rate

A retrieval-augmented chain might call the model once to plan, several times to reason over chunks, and again to synthesise — one user request, many model calls. An agent loop multiplies that further with every tool round-trip.

On metered pricing that fan-out makes per-request cost genuinely unpredictable. On unlimited it disappears as a concern: you let chains and agents take as many steps as the task needs for one fixed price.

The unpredictability is the real problem metered billing creates here, because the same user request can cost wildly different amounts depending on how many chunks it touches or how long an agent loops. Flat-rate unlimited replaces that variance with a single known number, which makes the whole pipeline easier to budget and reason about. Replacing cost variance with a single known number makes the whole pipeline easier to plan. Budgeting an unpredictable fan-out becomes a non-issue, since the figure no longer moves with traffic.

Mix models freely

Build a claude-sonnet-4-5 object for routine steps and a claude-opus-4-8 object for the hard step, both on the same key. On unlimited there is no penalty for routing the critical step to the stronger model every time.

Because model choice no longer trades off against cost, you design pipelines purely around quality — strong where it matters, fast where it does not — and the bill stays flat.

On metered access teams often downgrade the model on hot paths purely to save money, accepting weaker output as the price of affordability. Unlimited removes that compromise: you put the strong model wherever it improves the result and never have to weaken a step to control spend. Putting the strong model wherever it helps, with no penalty, is the design freedom unlimited buys. You never weaken a step purely to control spend.

# 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

FAQ

無制限 Claude で LangChain を動かせますか?
はい——base_url={SITE}(ルート)の ChatAnthropic、または ANTHROPIC_API_URL を設定します。すべてのチェーンとエージェント呼び出しが定額プランから引かれます。

なぜ LangChain に無制限が向いているのですか?
チェーンとエージェントは1つのリクエストを多数のモデル呼び出しに展開し、トークン課金を予測しにくくします。定額・無制限ならそれが固定になります。

ChatAnthropic と ChatOpenAI、どちらの URL?
ChatAnthropic は素のルート、ChatOpenAI は {SITE}/v1 を使います。どちらも同じ無制限プランに到達します。

トークン上限はありますか?
プラン期間中はトークン上限なし。ゲートウェイの応答性を保つフェアユースのレート制限のみです。

Start using Claude in minutes

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

Get your API key