DEV Community

Akarshan Gandotra
Akarshan Gandotra

Posted on Edited on

Consent Covers What an Agent Touches, Not What It Spends

In the first post I argued that an agent should start every session with nothing and borrow access from its user. In the second, that access should be checked on every call, not granted per tool.

Both posts are about what an agent can touch. Readers in the comments pointed at what they leave out. heyvaldemar put it in one line: consent covers the tools, not the spend. Kevin Hall gave the answer: spend fits the same rule as access.

This post is about that.

Every call was allowed. The bill wasn't.

Picture an agent asked to summarize a ticket backlog overnight. Every call it makes is inside its grants: read tickets, call the model, write a summary. Somewhere around ticket 400 it starts retrying a malformed response, and each retry re-sends the whole context. Nothing it does is forbidden. In the morning, the access log is clean and the model bill is not.

Or picture a prompt injection that doesn't try to steal anything. It just asks the agent to "be thorough" and re-read every attachment ten times. OWASP calls this unbounded consumption and lists denial of wallet as one of its harms. Every permission check passes, because nothing is being accessed that shouldn't be.

Access control answers "may it?" Spending needs a different question: "how much?"

Today the budget belongs to the agent

In most setups, the model gateway sees one credential: the agent's. Quotas and token budgets are keyed on that, so every user of the agent draws from the same pool. One person's runaway session can spend the allowance for everyone, and nobody can say afterwards whose session spent what.

That's the same mistake as the service account in the first post, applied to money. The agent holds a standing budget that no user agreed to and that isn't bound to any user.

A budget is a grant

So treat spend like everything else the agent borrows. The user lends a budget for the session, the same way they lend access:

Run this with up to 200,000 tokens.

And it follows the same rules:

Access grant Budget grant
Covers What the agent can touch How much it can spend
Lent by The user, per request The user, per session
Never more than What the user has right now What the user, or their team, has left
Capped by The template's ceiling The template's per-session limit
Subagents get A subset of the parent's access A slice of the parent's remaining budget
Ends With the session With the session, and unspent budget doesn't carry over

The subagent row is the one that matters most. A parent with 50,000 tokens left can't start five subagents with 50,000 each. It hands out slices, and the slices add up to what it has. "Inherit down, never up" works for money too.

A session budget lent from the team's allowance, with the parent's last 50,000 tokens split into slices for its subagents

Enforce it where the money is spent

A line in the system prompt asking the agent to be economical is not a limit. As Kevin put it, a promise in the prompt is not an enforcement point. The cap has to live where the spending happens: the model gateway, and any tool that costs money per call.

That runs into a practical problem heyvaldemar described in a follow-up: the model gateway usually never sees the person, only the agent. The least invasive fix I can see is to mint the agent's credential for the model gateway per session, with the gateway as its only audience and the session id inside. The gateway keys the budget on the session, and IAM answers which person the session belongs to. That doesn't add a second token to every call.

Make the ceiling hard

There's a catch that makes most token budgets soft. You only know how many tokens a request used after the response comes back, so the request that crosses the limit is served, and only the next one is refused. "Up to N" quietly becomes "N plus one request".

You can close that gap:

  1. Count the input before the call. You know what you're about to send.
  2. Cap the output to what's left. Set the request's maximum output to the remaining budget minus the input.
  3. Reserve, then settle. Hold the worst case before the call and charge the actual usage after it, like a card pre-authorization. That keeps parallel subagents from all spending the same remainder at once.

Reserve, then settle: the gateway checks what the session has left, caps the output, reserves the worst case and settles the actual usage

As a sketch, not a library:

def call_model(session, request):
    budget = iam.budget_for(session)          # what's left of this session's grant
    input_tokens = count_tokens(request)      # known before the call
    max_out = min(request.max_tokens, budget.remaining - input_tokens)
    if max_out <= 0:
        raise BudgetExhausted(session)        # stop, and ask the user for more

    hold = budget.reserve(input_tokens + max_out)
    try:
        response = model.create(request, max_tokens=max_out)
    except Exception:
        hold.release()
        raise
    hold.settle(response.usage)               # charge what was used, free the rest
    return response
Enter fullscreen mode Exit fullscreen mode

One caveat: this only holds if your count matches what the provider bills. Tool definitions, cached prompts and reasoning tokens all count somewhere, and your counter has to agree with the invoice.

When the budget runs out, ask

When a session hits its limit, the agent stops and asks, the same way it asks for access:

Finishing the last 40 tickets needs about 60,000 more tokens. Allow?

Wireframe: the session budget runs out, and the agent asks for 60,000 more tokens for this session only

The prompt shows the amount, not just "allow more spending?", for the same reason the second post argued for showing the actual call. People can judge a number. Bypass mode shouldn't approve more budget on its own, and an organization should be able to cap how much a user can top up.

What you get

  • A runaway loop stops at a known cost, not at the end of the month.
  • A prompt injection can't drain the shared pool, because there isn't one. Each session spends its own grant.
  • Spend has a name on it. Every token belongs to a session, and every session belongs to a person, which makes chargeback and audit simple.

Access says what an agent may touch. A budget says how much it may spend doing it. Both are things the user lends, and neither should outlive the session.

Top comments (3)

Collapse
 
max_quimby profile image
Max Quimby •

The clean-access-log-and-a-blown-bill scenario is painfully accurate — every call was permitted, and "permitted" was never the right question for spend.

The subagent row is the one that matters most, like you said, and I think it's also the hardest to actually enforce. "Inherit down, never up" is easy to state and annoying to implement, because the moment subagents run in parallel you need the parent's remaining budget to be a single decrementing ledger they all draw from atomically — otherwise five children each "see" the parent's 50k and you're back to overspend by race condition. Did you end up with a central accounting service, or something the parent enforces locally?

The other half nobody budgets for is attribution. Keying quota on the agent's one credential doesn't just risk overspend, it destroys the audit — you can't answer "whose session spent what" after the fact. Treating budget as a lent grant fixes the enforcement and the forensics at once, which is the part I'd sell hardest. Nice series.

Collapse
 
aiapikey profile image
HAOHAOnovai •

Consent scoped to resources is the right model, and it has a blind spot that is easy to miss: reading one large document can be expensive without touching anything new. A 200k-token context at $3/M is $0.60 of input per call. A thousand calls a day from a grant that only says "may read this document" is $600 a day, and nothing in the grant changed.

The fix is to make spend a first-class axis of the grant rather than a consequence of the resource: a per-call token budget and a daily cost ceiling attached to the same object that carries the scope. Then exceeding it is a consent event, not a billing surprise.

Collapse
 
keybark profile image
KeyBark •

Good piece. Two things I'd add:

  1. Reasoning tokens eat the cap first. In OpenAI's reasoning guide, max_output_tokens limits reasoning plus visible output together, and a call can end "incomplete" (reason max_output_tokens) before any visible text, while you still pay for the input and reasoning. So with "cap the output to what's left", a nearly spent session can pay for calls that return nothing. I'd stop and ask once the remainder is below a sensible floor, rather than send a tiny cap. (developers.openai.com/api/docs/gui...)

  2. A backstop below the gateway. The session ledger only holds if the agent can't reach the provider any other way, so the provider key stays in the gateway. Then set a provider-side ceiling for when the gateway has a bug: an OpenAI project spend limit with "Enforce a hard limit" on, an Anthropic workspace spend limit, or an OpenRouter workspace budget. That last one fails with a 403 that names the budget, so it's easy to tell apart from a rate-limit 429 (openrouter.ai/docs/api_reference/l...).