# How are you capping spend on LangChain / LangGraph agents in production?

**URL:** <https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917>\
**Category:** Agent Server\
**Created:** [October 27, 2026, 6:13pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917 "2026-10-27T18:13:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blakk](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@Blakk](https://forum.langchain.com/u/Blakk)\
**Post date:** [October 27, 2026, 6:13pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917/1 "2026-10-27T18:13:02Z")

</div>

I keep seeing the same failure: an agent hits a retry loop or a tool error, keeps calling the model, and nothing stops it until the bill arrives. Callbacks and token counters inside the process help, but they die with the process and they trust the agent to stop itself.

I built a small proxy, Valta, that sits outside the agent. You point ChatOpenAI at it and use a virtual key instead of your OpenAI key. Before each call it checks your per-run, daily and monthly caps. If the call would go over, it returns a 402 and nothing reaches OpenAI. If it can’t decide, it also sends nothing.

It looks like this:

```python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-4.1",
    base_url="https://valta.co/v1",
    api_key="vk_live_...", # virtual key, not your OpenAI key
    max_tokens=500, # set this, it's used to estimate cost
    default_headers={"X-Valta-Run-Id": run_id}, # groups calls into one run
)

```

Limits to know about:

- Non-streaming only for now (streaming returns a 400).
- Chat Completions only, not the Responses API, so if your langchain-openai version uses Responses, turn that off.
- The per-run cap is keyed on the run id header, so a loop that sends a fresh id each time only gets caught by the daily and monthly caps.

I’m looking for 5 people running LangChain or LangGraph agents who want to try this on a real workload. I’ll set it up with you myself, it’s free, and what I want back is honest feedback on where it breaks.

If you’ve had a runaway bill or you’re worried about one, reply with your setup (framework, rough monthly spend, what went wrong) and I’ll reply to everyone.

And a question for everyone: where do you enforce limits today, in the agent, in a gateway like LiteLLM, or just with provider-side budgets?

Debo, solo founder. [Valta | Hard spend limits for AI agents](http://valta.co/?utm_source=langchain)

---

<div class="post-metadata">

**Author:** ![discourse\_ai\_spam](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@discourse\_ai\_spam](https://forum.langchain.com/u/discourse_ai_spam)\
**Post date:** [October 27, 2026, 6:13pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917/2 "2026-10-27T18:13:04Z")

</div>

Unlisted on October 27, 2026, 6:13pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/system/32/1_2.png) [@system](https://forum.langchain.com/u/system)\
**Post date:** [October 28, 2026, 3:59pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917/3 "2026-10-28T15:59:43Z")

</div>

Listed on October 28, 2026, 3:59pm UTC



---

<div class="post-metadata">

**Author:** ![virse\_ai](https://avatars.discourse-cdn.com/v4/letter/v/85f322/32.png) [@virse\_ai](https://forum.langchain.com/u/virse_ai)\
**Post date:** [November 2, 2026, 3:40pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917/4 "2026-11-02T15:40:28Z")

</div>

I enforce the cap in the graph, before the model call, not by asking the model to stop. A call-count limit such as recursion\_limit or ModelCallLimitMiddleware stops a retry loop, but it does not cap dollars, so I also keep a running token estimate and skip the model node once that run would go over. An in-process counter dies with the process and does not see a second worker, so a provider monthly budget is the backstop, not the only control. A gateway helps when several apps share one key, but the graph still needs its own stop so one stuck run cannot spend the whole daily budget.

---

<div class="post-metadata">

**Author:** ![Blakk](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@Blakk](https://forum.langchain.com/u/Blakk)\
**Post date:** [November 2, 2026, 5:42pm UTC](https://forum.langchain.com/t/how-are-you-capping-spend-on-langchain-langgraph-agents-in-production/4917/5 "2026-11-02T17:42:28Z")

</div>

Thanks for sharing this — very clear explanation.

You’re right that in-graph controls (recursion\_limit, ModelCallLimitMiddleware + running token estimate) are necessary. The problem I keep seeing is that those controls still live inside the same process as the agent. If the process crashes, gets stuck, or a second worker starts, the counters disappear and the only real backstop left is the provider’s monthly budget.

That’s why I moved the hard dollar/run/day/month caps outside the agent entirely (the proxy approach). The agent can be as broken or loop-happy as it wants — the call never reaches OpenAI if it would break the limit how you’re handling the case where multiple concurrent graph runs share the same OpenAI key? Do you still rely mainly on the provider budget as the final safety net, or have you added something at the gateway level too?
