Budget limits for LangChain and LangGraph agents

Last updated 24 November 2026

LangGraph agents loop until they decide they are done, and a tool error or a confused model can keep them going. Recursion limits count steps, not dollars. Xpenvo gives each run a hard dollar limit and checks it before every model call, without changing your graph.

1. Make a budget and a key

Create a free account, make a budget (for example $20 a day) and an agent key for it under Agent keys. The key starts with xpv_ and is shown once. You keep your own provider key and keep paying your provider directly; Xpenvo never stores it.

2. Point the model client at Xpenvo

import os, uuid
from langchain_openai import ChatOpenAI

run_id = str(uuid.uuid4())  # one id per agent run
llm = ChatOpenAI(
    model="gpt-5-mini",
    base_url="https://agents.xpenvo.com/v1",
    default_headers={
        "X-Xpenvo-Key": os.environ["XPENVO_KEY"],
        "X-Xpenvo-Run": run_id,
    },
)

For Claude, use ChatAnthropic(base_url="https://agents.xpenvo.com", default_headers=…) the same way. Everything else in your graph stays as it is.

3. Give each run a limit

Set a per-run limit on the budget, for example $2 a run. The run id header groups every call of one run, and once that run has spent its limit, the next call is refused with a 402 that your graph sees as a normal model error. The Runs tab shows each run step by step, with cost, without prompts or answers.

Questions

How do I stop a LangGraph agent from spending too much?

Send its model calls through Xpenvo Agents with an X-Xpenvo-Run header per run, and set a per-run dollar limit on the budget. Each call is checked before it is sent.

Does this replace the recursion limit?

No, keep it. A recursion limit counts steps; Xpenvo limits dollars, per run, per agent and per end customer.

More: full setup guide · model prices · tested guarantees · security. Questions? [email protected]