All guides
Updated
Reading
10 min
By
Anlyon Team

How to set one spending limit shared by all your AI agents: scope, units and a concurrency test

A practical setup for a shared impact limit: choose its scope and period, count money in integer minor units or declare your own unit, prove two agents cannot overspend it, and change it safely while actions are pending.

  • impact limits
  • spending limits
  • refunds
  • concurrency
  • declared actions
  • operations

Create one impact limit in the environment your agents' keys belong to, scope it with an optional action name or resource prefix, and count either money in integer minor units or a unit you declare. Every agent, session and key in that scope then draws from the same allowance, reserved immediately before each governed action is dispatched. Prove it with two agent keys racing for the last of the limit: one request runs and the other is refused before it reaches the provider.

This is the hands-on guide. For why a token budget or a per-call threshold cannot do this job, read how AI agents share one refund limit first.

TL;DR

  • A limit is keyed on server-side values: environment, dimension and unit, optional action name, optional resource prefix, and period (day, month or total). A day is the UTC day.
  • Money is integer minor units in one currency. For USD, 1250 is $12.50.
  • An HTTP action you declare counts what its impact.amount expression says. An amount that cannot be evaluated is refused under an applicable limit and runs when no limit applies.
  • A limit admits or refuses an operation whole. Unknown outcomes keep their allowance held.
  • Lowering never releases existing exposure. impact-limits:write is held by no key by default.

What does a limit actually cover?

Write the boundary as one sentence before you write any code: "All governed USD refunds in the production environment share a $500 daily allowance." Then check that each action producing those refunds is governed, meaning it has an adapter or a declaration. An action with neither runs, but no limit counts it.

Desired boundaryConfiguration
All USD refunds in one environmentdimension: 'money', currency: 'usd', no action name
One particular refund actionAdd actionName
Edits to one repository and branchdimension: 'resource_mutations', resourcePrefix: 'github:acme/fixtures@'
Emails sent by any declared or Resend actionA declared unit such as emails
A one-off migration allowanceperiod: 'total', which never resets

The environment is not a parameter. It comes from the operator key that creates the limit, and an agent's key resolves to exactly one environment. A staging environment has its own limits, so a production limit says nothing about staging traffic. A provider call your own code makes with a key held outside Anlyon is outside every limit, which is why the provider credential belongs in the vault. See AI agent secrets management.

Before choosing a resourcePrefix, look at the resource keys your actions really emit. A declared action's resource key is http:<host><path>. A prefix guessed from a display label can match nothing.

How do I create the limits?

Limits are created with an operator key that holds impact-limits:write. No key receives that scope by default, so the agents a limit constrains cannot raise it.

// setup-limits.ts
import { Client } from '@anlyonhq/sdk';

const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

// Money: integer minor units in one currency. 50_000 is $500.00.
await ops.impactLimits.create({
  name: 'Refunds per day',
  dimension: 'money',
  currency: 'usd',
  period: 'day',
  amount: 50_000,
});

// Resource mutations, narrowed to one repository and branch.
await ops.impactLimits.create({
  name: 'Fixture edits',
  dimension: 'resource_mutations',
  resourcePrefix: 'github:acme/fixtures@',
  period: 'day',
  amount: 20,
});

// A unit you declare. It caps every action that declares an impact in `emails`.
await ops.impactLimits.create({
  name: 'Daily emails',
  dimension: 'emails',
  period: 'day',
  amount: 500,
});

Several limits can apply to one operation. A Stripe refund through the stripe.refund adapter counts its amount in money and also one resource mutation, so a mutation limit can refuse a refund that the money limit would admit. Read the refusal reason before assuming which limit spoke.

How do I count money without a unit mistake?

The Stripe refund adapter takes an integer amount in the action's one configured currency. Keep the integer, the currency and the displayed amount together from the agent's input through review to your reports.

Stored integerUSD meaning
500$5.00
1250$12.50
50000$500.00
"$12.50"A display string, not an amount the adapter accepts

Other currencies use other minor-unit conventions, so confirm each one with the provider's reference instead of dividing by 100. Validate amounts in your tool before the agent's request is built: a positive integer, the action's currency, and no floating-point value standing in for the ledger quantity.

How do I put my own HTTP API under a limit?

A generic HTTP executor cannot infer what an endpoint changes. You declare it. The amount is a deliberately small expression over the validated input: an integer, input.<path> or count(input.<path>), with one optional multiplication by an integer. Anything else is refused when you save the action.

// One call sends one email per recipient. `to` is required, so the count always exists.
await ops.actions.create({
  name: 'send-email',
  method: 'PUT',
  urlTemplate: 'https://api.example.com/v1/emails/{{input.emailId}}',
  headers: { Authorization: 'Bearer {{secret:MAILER_TOKEN}}' },
  bodyTemplate: { to: '{{input.to}}', subject: '{{input.subject}}' },
  inputSchema: {
    type: 'object',
    required: ['emailId', 'to', 'subject'],
    properties: {
      emailId: { type: 'string', pattern: '^[a-z0-9-]{1,40}$' },
      to: { type: 'array', items: { type: 'string' } },
      subject: { type: 'string' },
    },
  },
  impact: { dimension: 'emails', amount: 'count(input.to)', bound: 'exact' },
});

// Later, if the API starts sending a copy to each recipient's manager:
await ops.actions.declare('send-email', {
  impact: { dimension: 'emails', amount: 'count(input.to) * 2', bound: 'upper_bound' },
});

exact means the call changes exactly that much. upper_bound means at most that much. Both reserve the full amount. You write what the action counts, and Anlyon enforces it before dispatch; it does not check that your expression matches what the provider does. An upper_bound set too low is a definition error, and so is a collection count on an endpoint that expands one input into many downstream operations.

An amount that reads an input the caller left out gives no quantity. That effect is unbounded, never zero. An applicable limit refuses it with impact_unbounded, and with no applicable limit it runs. Mark the counted input required in the schema. Changing what a governed action already declares needs actions:govern, which is not granted by default, so treat a declaration change as a behaviour change and review it with the request template.

How is an impact limit different from a budget?

ControlCountsStops
Budget (per key)Anlyon operations, action invocations includedFurther covered requests with 429 BUDGET_EXCEEDED
Impact limit (per environment and scope)What a governed action changes: money, mutations or a declared unitA dispatch that does not fit, graded refused

Ten invocations under a budget can move very different amounts of money. A budget does not cap the money an approved refund moves, and an impact limit does not count invocations. Label them separately in your runbook.

How do I prove two agents cannot overspend it?

Use a dedicated test environment, the stripe.refund adapter with a test key, two agent keys holding actions:invoke, and two refundable test payments. Create a money limit of 10,000 (USD $100.00) with nothing consumed. Give each request its own operationKey, so the test exercises capacity rather than deduplication.

// race.ts
import { Client } from '@anlyonhq/sdk';

const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });
const agentA = new Client({ apiKey: process.env.ANLYON_AGENT_KEY_A! });
const agentB = new Client({ apiKey: process.env.ANLYON_AGENT_KEY_B! });

const { data: limit } = await ops.impactLimits.create({
  name: 'Race test', dimension: 'money', currency: 'usd', period: 'total', amount: 10_000,
});

const [a, b] = await Promise.all([
  agentA.actions.invoke('refund', { paymentIntent: 'pi_test_A', amount: 8_000, currency: 'usd' },
    { operationKey: 'race-refund-a' }),
  agentB.actions.invoke('refund', { paymentIntent: 'pi_test_B', amount: 8_000, currency: 'usd' },
    { operationKey: 'race-refund-b' }),
]);

for (const { data } of [a, b]) {
  console.log(data!.effectId, data!.status, data!.grade, data!.error);
}

const { data: after } = await ops.impactLimits.get(limit!.id);
console.log(after!.consumed, after!.reserved, after!.unknownExposure, after!.available);

A refusal answers HTTP 200 with the result in the body, so read status and grade rather than the status code. Interpret the run like this:

ObservationInterpretation
One succeeded, one failed with grade refused and impact_limit_exceededThe shared boundary held
One waiting for approval, the other refusedCapacity is reserved at dispatch, after approval, not at review
Both refusedCheck existing exposure, the mutation limit and policy
Both dispatchedCheck scope, environment, quantity and whether both went through Anlyon

On 2026-10-04 this race ran against Stripe test mode with two keys and $80 refunds against a $100 limit. One refund dispatched. The other was refused with impact_limit_exceeded and zero attempts. The limit then read 8,000 consumed and 2,000 available, and Stripe listed one refund. The shared-allowance model reproduces the same accounting offline.

Then extend the test. Repeat with a new session and a third key in the same environment: neither brings a new allowance. Send a request larger than the remaining room and confirm it is refused whole rather than trimmed. A send to four recipients with two left is refused, and both remaining units stay available.

What happens to capacity when an outcome is unknown?

If a refund loses its response, the provider may already have paid it. Its reservation stays held as unknownExposure, part of reserved, until a read-back or an operator settles it, across restarts and period boundaries. So a limit can refuse new work while consumed is zero. Find the effects behind it with ops.actions.effects({ unresolved: true }) and settle them as described in reconciling an unknown agent action. Resolving an effect as failed to free capacity, without evidence, turns accounting pressure into a false claim about the world.

How do I lower or remove a limit while actions are pending?

await ops.impactLimits.update(limit!.id, { amount: 5_000 }); // blocks new work; held exposure stays
await ops.impactLimits.archive(limit!.id);                    // stops applying to new effects
Operator intentUse
Reduce future exposureLower the limit with update
Stop all new dispatch in the environmentThe environment halt
Stop this limit applying to new workarchive, after checking what it would admit
Learn what a timed-out action didReconcile or resolve that effect

Lowering never releases existing exposure and never recalls a dispatched request. If a limit of 100 has 80 committed and you lower it to 50, nothing previously committed disappears; new work waits until availability recovers. Archiving a restrictive limit to clear a warning can admit more than you intended, while its existing reservations still settle. During an incident, halting the environment is the separate control for stopping all new dispatch; see resuming after an environment halt.

A limit's name and amount can change. Its dimension, scope and period are fixed, so a different boundary means a new limit. After any change, send a safe request that should no longer fit and confirm the refusal names the limit you expected.

Where to go next

Free during Early Beta Access, no credit card. Start building

Frequently asked questions

How do I make several AI agents share one refund limit?
Route the refunds through a governed action, such as the stripe.refund adapter, and create one impact limit in the environment those agents' keys belong to. Every agent, session and key in that environment draws from the same limit, reserved immediately before dispatch, so a new session or key does not get a new allowance. Calls made outside Anlyon, and actions in another environment, are not counted.
Is a refund limit of 500 the same as $500?
No. A money limit counts integer minor units in one currency. For USD, 500 means $5.00 and 50,000 means $500.00. Check the minor-unit convention of any other currency against the provider's reference rather than dividing by 100.
What happens when two agents race for the last of a limit?
Each operation reserves every applicable limit in one transaction immediately before dispatch, and a limit admits or refuses an operation whole. If the remaining room covers one request, one is dispatched and the other is refused with impact_limit_exceeded before anything reaches the provider.
Does lowering a limit cancel actions that are already pending?
No. Lowering a limit never releases existing exposure and never recalls a dispatched request. It blocks new work until availability recovers. Archiving a limit stops it applying to new effects while its existing reservations still settle.

Let your agent act for your users, safely.

A few lines of server code, then send a user a connect link. Nothing to host.

$ claude mcp add --transport http anlyon https://api.anlyon.com/mcp