Refund Issued, Customer Never Told: What a Dollar Limit Does to an Agent Mid-Task

Bedrock Gateway stops requests once a spend limit is hit. Agents work in tasks, not requests. A walkthrough, a simulation, and the admission check to add.


A bar chart of one hypothetical agent task's cumulative spend across ten model calls against a remaining limit of $1.90. Calls one to six complete, with call six overshooting the limit by ten cents; call seven is refused and calls eight to ten never run. The return label at call three and the refund at call six happened; the customer email at call nine never does

It’s 4:40 pm. A support agent picks up a ticket: damaged order, customer wants a refund. The agent runs under the support team’s IAM role, which has a $20 daily limit on model spend, and $18.10 of it is gone. The task needs ten model calls. It makes six.

This scene is hypothetical. The agent, its costs and its budget are invented. The control it runs into is real: AWS announced Amazon Bedrock Gateway in gated preview at re:Invent on December 1, and it’s a good feature. It’s also enforced per request, while agents spend money and cause side effects per task. The gap between those two units is where this post lives.

What AWS shipped

From the announcement and AWS’s launch post:

  • Every model request is tied to a user or application, through IAM or an identity provider such as Okta or Microsoft Entra ID.
  • Administrators set a dollar spending limit per user, group or IAM role. “Once a limit is reached, requests stop before they reach a model.”
  • Limit changes are recorded in CloudTrail, and each response shows how much budget is left.
  • When a limit is hit, “Bedrock can alert the administrator or stop all Bedrock spend in the associated account.”
  • One gateway can span multiple AWS accounts and also front models outside Bedrock. For agents built on AgentCore, teams can see estimated cost per agent and per session.

AWS’s own pitch is that companies “typically build or buy a model gateway” to get this. Having one built into Bedrock is welcome. Now walk the task.

The walkthrough

CallWhat the agent doesCostTask totalGateway
1Read the ticket$0.24$0.24allowed
2Look up the order$0.27$0.51allowed
3Create a return label$0.31$0.82allowed
4Check the refund policy$0.35$1.17allowed
5Verify the damage photos$0.39$1.56allowed
6Issue the refund$0.44$2.00allowed
7Draft the customer emailrefused
8Check the draft against policynever runs
9Send the email, close the ticketnever runs
10Write the case summarynever runs

Each call costs a little more than the one before, because the context grows with every step. Bold rows change something outside the agent.

Three things happened that nobody designed.

The limit was crossed by a request it allowed. At call 6 the agent had spent $1.56 of the $1.90 left, so the request went through. Its response cost $0.44 and took the day $0.10 past the limit. Output length isn’t known until the model finishes, so a check that runs before a request can’t stop the request that crosses the line. Unless the gateway reserves against max_tokens up front, which the announcement doesn’t say, expect each identity to overshoot by up to one call.

The refund happened. The email didn’t. The customer has been refunded and doesn’t know it. The ticket is open, assigned to an agent that can’t make another model call until the limit resets. From the outside, this looks like an agent that’s working on it.

Midnight is a retry trigger. When the limit resets, what does the agent do with the ticket? If it resumes from a checkpoint, fine. If it restarts the task from call 1, it’ll reach call 6 again and issue a second refund, unless the refund tool takes an idempotency key. A budget reset is a restart, and everything I found about restarting agents mid-task applies.

None of this is a Bedrock Gateway bug. A per-request limit is the right primitive for a gateway, which sees requests and nothing else. The task is the agent’s concept, so protecting the task is the agent platform’s job.

How often does it happen?

One stranded task is an anecdote. To get a rate, I simulated the same shape: one identity with a $20 daily limit, tasks of ten calls with side effects at calls 3, 6 and 9, costs drawn from a seeded distribution that grows with each step. The agent works tasks back to back until the gateway refuses it, every day for 1,000 days. Synthetic, illustrative numbers; the script is at the end.

daily limit $20.00, 10 calls per task, side effects at steps [3, 6, 9]

gateway-only
  tasks finished per day               2.98
  tasks stranded with side effects     0.76
  spend on unfinished tasks          $ 2.48
  spend past the limit               $ 0.41
  budget left unused                 $ 0.00
admission
  tasks finished per day               2.50
  tasks stranded with side effects     0.00
  spend on unfinished tasks          $ 0.01
  spend past the limit               $ 0.00
  budget left unused                 $ 4.83

admission rule: start a task only if remaining budget >= p95 task cost ($7.90)

With the gateway alone, the last task of most days ends half-done: 760 stranded tasks in 1,000 days for a single identity, each with at least one side effect applied. That’s the nature of a hard limit hit by work that doesn’t fit inside it. The day’s final task is the one that runs out, and it runs out wherever it happens to be. Scale that by the number of roles and users you put limits on.

The fix is an admission check

The second policy adds one line before each task: don’t start a task the remaining budget can’t finish. Estimate the cost from history (here, the 95th percentile of past task totals, $7.90), compare it with what’s left, and if it doesn’t fit, stop for the day before call 1 rather than at call 7.

Stranded tasks went from 760 to 1 over 1,000 days. The one was a task that cost more than its 95th percentile. It isn’t free: the agent finished 16% fewer tasks and left about $4.83 a day unspent, because it refused tasks that might have fit. That’s the honest trade. You’re buying “never half-done” with some throughput, the same way load shedding buys a healthy service by refusing work at the door instead of failing it in the middle.

The pieces you need are already in the launch:

  • Read the remaining budget from every response. AWS says each one carries it. That’s the input to the admission check, and it means the agent doesn’t need a separate billing query.
  • Estimate per task type, not per call. You need a history of what each kind of task costs end to end. If you’re building on AgentCore, the per-session cost estimate is that history. Otherwise, tag spend with a task ID and compute it yourself.
  • Use a high percentile, not the mean. The mean admits half the tasks that will run long.

And then make the stranding survivable

Admission control makes stranding rare, not impossible. For the remainder:

  1. Handle the refusal as its own error. A budget refusal isn’t a transient failure to retry with backoff; retrying it just hammers a closed door. Catch it, checkpoint the task, and hand it to a human queue with the side effects so far listed.
  2. Move irreversible side effects late, and pair them. Issue the refund and send the confirmation in adjacent steps, or one tool call. Where you can’t, give each side effect a compensating action, the saga pattern, so a stranded task can be unwound.
  3. Mind the blast radius of “stop all spend in the account”. If one role’s runaway agent can trigger an account-wide stop, every other workload in that account stops with it. Account layout now decides which agents can starve which. Put agents with different owners in different accounts, or confirm that the stop you configure is the per-identity one.

It’s the same lesson as where a kill switch should live: stopping the requests isn’t the same as stopping cleanly. A budget is a kill switch that fires on a schedule you didn’t choose.

What I’d ask AWS during the preview

  • Is a request admitted on the current spend and charged after, or reserved against max_tokens? That decides the overshoot.
  • What error does a refused request return, and is it distinct from throttling?
  • Is the remaining budget a machine-readable field the agent can act on, and does it account for requests in flight?
  • Can a limit be scoped to an agent session or task, not just a user, group or role?

The script

Standard library only, seeded. Save it as budget.py and run it with python3 to get the numbers above.

"""What a per-user dollar limit does to a multi-step agent task.
Synthetic, seeded, stdlib only. The agent, its costs and its budget are invented.
"""
import random

DAILY_LIMIT = 20.00          # dollars per user per day, enforced by the gateway
STEPS = 10                   # model calls per task
SIDE_EFFECT_STEPS = {3, 6, 9}  # steps that change something outside the agent
DAYS = 1000


def step_cost(rng, i):
    # Cost grows with the step number because the context grows with every call.
    return rng.lognormvariate(-1.6, 0.5) * (1 + 0.3 * i)


def task_costs(rng):
    return [step_cost(rng, i) for i in range(1, STEPS + 1)]


def simulate(policy, seed=11):
    rng = random.Random(seed)
    stranded = finished = 0
    wasted = overshoot = unused = 0.0
    history = [sum(task_costs(random.Random(s))) for s in range(200)]   # past task totals
    p95 = sorted(history)[int(0.95 * len(history))]
    for _ in range(DAYS):
        spent = 0.0
        while True:
            costs = task_costs(rng)
            if policy == "admission" and DAILY_LIMIT - spent < p95:
                break                                  # don't start what you can't afford to finish
            done, effects, task_spend = 0, 0, 0.0
            for i, c in enumerate(costs, start=1):
                if spent >= DAILY_LIMIT:               # gateway: checked before the request...
                    break
                spent += c                             # ...charged after the response
                task_spend += c
                done = i
                effects += i in SIDE_EFFECT_STEPS
            if done == STEPS:
                finished += 1
            else:
                if effects:
                    stranded += 1
                wasted += task_spend
                break                                  # budget is gone for today
        overshoot += max(0.0, spent - DAILY_LIMIT)
        unused += max(0.0, DAILY_LIMIT - spent)
    return finished / DAYS, stranded / DAYS, wasted / DAYS, overshoot / DAYS, unused / DAYS, p95


print(f"daily limit ${DAILY_LIMIT:.2f}, {STEPS} calls per task, side effects at steps {sorted(SIDE_EFFECT_STEPS)}\n")
for policy in ("gateway-only", "admission"):
    fin, strand, waste, over, unused, p95 = simulate(policy)
    print(f"{policy}")
    print(f"  tasks finished per day             {fin:6.2f}")
    print(f"  tasks stranded with side effects   {strand:6.2f}")
    print(f"  spend on unfinished tasks          ${waste:5.2f}")
    print(f"  spend past the limit               ${over:5.2f}")
    print(f"  budget left unused                 ${unused:5.2f}")
print(f"\nadmission rule: start a task only if remaining budget >= p95 task cost (${p95:.2f})")

Frequently asked questions

What is Amazon Bedrock Gateway?

A managed model gateway built into Amazon Bedrock, announced in gated preview on December 1, 2026. It ties every model request to a user or application through AWS IAM or an existing identity provider such as Okta or Microsoft Entra ID, lets administrators set a dollar spending limit per user, group or IAM role, and stops requests before they reach a model once the limit is reached. Changes to limits are recorded in AWS CloudTrail, and each response shows how much budget is left.

What happens to an AI agent when it hits a spend limit mid-task?

The model call that would continue the task is refused, but the side effects the agent already caused remain. In a seeded simulation of a ten-call support task with side effects at calls 3, 6 and 9 and a $20 daily limit, request-level enforcement alone left 0.76 tasks per day stranded part-way, with side effects applied and the task unfinished.

How do you stop an agent from starting a task it can't afford to finish?

Add admission control in front of the task. Before starting, compare the remaining budget with a high percentile of what this kind of task has cost before, and don't start if it won't fit. In the simulation, admitting a task only when the remaining budget covered the 95th-percentile task cost cut stranded tasks from 760 to 1 over 1,000 days, at the price of 16% fewer tasks finished and about $4.83 a day of budget left unspent.

Comments