Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

When the limit is hit

Detect a governed action refused by an impact limit, read why, and decide what to do next: wait, raise the limit, or settle held exposure.

An impact limit is reserved immediately before dispatch. When it has no room, the call is refused before anything is sent to the provider. This page shows what your code gets back, how to read it, and what an operator can do.

Why the refusal looks the way it does

A refusal by a limit is a normal, expected outcome of a call, not a transport error. The invoke request itself succeeded: Anlyon recorded the operation, checked it, and decided not to send it. So:

  • The HTTP status is 200. The refusal is in the body. A caller that checks only the status code will miss it. Read status and grade.
  • Nothing reached the provider, and the allowance that was left is untouched.
  • The refusal is a record. It has an effect with zero attempts and an evidence entry, so you can find every refused call later.

Detect a refusal in your code

The scenario: a daily limit of 5 emails. One call has sent to 3 recipients. A second call asks for 3 more, with 2 left. send-email is a declared action that counts one emails unit per address in to.

import { Client } from '@anlyonhq/sdk';

const agent = new Client({ apiKey: process.env.ANLYON_API_KEY! });

const { data } = await agent.actions.invoke(
  'send-email',
  { emailId: 'welcome-2', to: ['a@example.com', 'b@example.com', 'c@example.com'], subject: 'Welcome' },
  { idempotencyKey: 'welcome-2' },
);

if (data!.grade === 'refused') {
  // status is "failed"; error names the reason and every shortfall.
  console.log(data!.status, data!.error);
}
curl -s -X POST https://api.anlyon.com/api/v2/actions/send-email/invoke \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: welcome-2" \
  -d '{ "input": { "emailId": "welcome-2", "to": ["a@example.com", "b@example.com", "c@example.com"], "subject": "Welcome" } }'
import os
from anlyon import Client

agent = Client(api_key=os.environ["ANLYON_API_KEY"])

result = agent.actions.invoke(
    "send-email",
    {"emailId": "welcome-2", "to": ["a@example.com", "b@example.com", "c@example.com"], "subject": "Welcome"},
    idempotency_key="welcome-2",
)

if result.data["grade"] == "refused":
    print(result.data["status"], result.data["error"])

The response, abridged:

{
  "success": true,
  "data": {
    "id": "inv_01JABCDEF",
    "status": "failed",
    "grade": "refused",
    "effectId": "eff_01JABCDEF",
    "responseStatus": null,
    "error": "Dispatch refused (impact_limit_exceeded): Not enough allowance: Daily emails needs 3, has 2."
  }
}

The error names impact_limit_exceeded and lists every limit that fell short, by name, with what the call needed and what was available. A call under several limits reports each shortfall in the same sentence, separated by ;. responseStatus is null because nothing was sent.

A second API key, a new session or a child agent does not bring a new allowance. The limit is keyed on the environment, not on the caller.

From the CLI, an invoke that is refused exits with code 14.

Read the refused effect

The refused call still leaves an effect. Read it with the effectId from the response, or list refused effects. Reading effects needs actions:read, which is in the default set.

const { data: effect } = await agent.actions.effect(data!.effectId!);
console.log(effect!.stage, effect!.outcome, effect!.rejectionReason, effect!.attempts.length);

const { data: refused } = await agent.actions.effects({ grade: 'refused', action: 'send-email' });
curl -s https://api.anlyon.com/api/v2/actions/effects/eff_01JABCDEF \
  -H "Authorization: Bearer $ANLYON_API_KEY"

curl -s "https://api.anlyon.com/api/v2/actions/effects?grade=refused&action=send-email" \
  -H "Authorization: Bearer $ANLYON_API_KEY"
effect = agent.actions.effect(result.data["effectId"]).data
print(effect["stage"], effect["outcome"], effect["rejectionReason"], len(effect["attempts"]))

refused = agent.actions.effects(grade="refused", action="send-email").data
{
  "stage": "rejected",
  "outcome": "not_dispatched",
  "rejectionReason": "impact_limit_exceeded",
  "grade": "refused",
  "verification": "not_dispatched",
  "attempts": []
}

Zero attempts means nothing was sent to the provider. The effect’s evidence has an entry that begins “Not dispatched”, with the shortfalls in its details.

From the CLI: anlyon effects list --action send-email --grade refused and anlyon effects get <id>.

Check that the allowance is untouched

Reservation is all or nothing. If one applicable limit has no room, none is reserved. The refused call above asked for 3 with 2 left. It did not take the 2.

const { data: limit } = await agent.impactLimits.get('lim_01JABCDEF');
console.log(limit!.consumed, limit!.reserved, limit!.available); // 3, 0, 2
curl -s https://api.anlyon.com/api/v2/impact-limits/lim_01JABCDEF \
  -H "Authorization: Bearer $ANLYON_API_KEY"
limit = agent.impact_limits.get("lim_01JABCDEF").data
print(limit["consumed"], limit["reserved"], limit["available"])

A third call, to 2 recipients, then succeeds and the limit reads:

{ "consumed": 5, "reserved": 0, "available": 0 }

Three calls were made and the destination saw two writes. Reading limits needs impact-limits:read, which is in the default set, so an agent can check available before it asks.

When each of your users has their own limit

A limit created with scope: "end_user" gives each end user the whole amount. A call made with forUser(userId) is refused when that user has no room, and other users are unaffected. The error and the effect look the same as above. To read the user’s figures, pass their id:

curl -s "https://api.anlyon.com/api/v2/impact-limits/lim_01JABCDEF?endUserId=user_4417" \
  -H "Authorization: Bearer $ANLYON_API_KEY"

A call with no end user counts on the limit’s shared allowance. A key created with endUserRequired reads its own end user’s figures. See Impact limits.

impact_unbounded: the call gave no amount

A second refusal has the same shape and a different reason. It happens when a limit applies to the action and the call gives no evaluable amount for that limit’s dimension.

For a declared action that means the amount expression reads an input the caller left out. count(input.to) with no to has nothing to count. No quantity is unbounded, never zero.

{
  "stage": "rejected",
  "outcome": "not_dispatched",
  "rejectionReason": "impact_unbounded",
  "grade": "refused",
  "attempts": []
}

The invocation comes back status: "failed" with an error that names impact_unbounded. The error text has this form:

Limit <limit id> (<limit name>) caps <dimension>, and this operation gives no exact quantity or upper bound for it.

The limit is untouched. Two details:

  • With no applicable limit the call runs. Without an emails limit, the same input runs and the effect records an empty impact. A limit in another unit does not concern it.
  • The same action with a countable input runs under the same limit. A call with one recipient consumes 1.

The fix is in the definition. Mark the input required in the action’s schema when the amount depends on it.

When held exposure fills the limit

available is limit - consumed - reserved. reserved includes every effect whose outcome is still pending or unknown. That capacity stays held until evidence or an operator settles it. A period boundary does not release it.

For example, a refund of 8000 against a daily limit of 10000 loses its response just before midnight UTC. On the new day the limit reads:

{ "consumed": 0, "reserved": 8000, "unknownExposure": 8000, "available": 2000 }

A new call for 3000 is refused with impact_limit_exceeded. After reconciliation finds the refund, the 8000 settles into the day it was reserved in, and the current day reads:

{ "consumed": 0, "reserved": 0, "available": 10000 }

So a limit can refuse a call while consumed is zero. Look at reserved and unknownExposure. unknownExposure is the part of reserved whose outcome is unknown or possibly partial. It is not an additional amount.

When the limit fills after an approval was requested

A limit is checked at dispatch, not at review. A pending approval reserves nothing against the limit: the call’s usage is counted only when the approved call runs. If the limit fills while an invocation waits for its approval, approving it dispatches nothing:

{ "rejectionReason": "impact_limit_exceeded" }

The preview showed available: 10000 and sufficient: true at review. Another refund of 5000 ran before the approval. The approve call succeeds, and the invocation.status inside its response is failed. The allowances in a preview are as of review.

What an operator can do

Raise the limit. This needs impact-limits:write, which no key receives by default, so the agent a limit constrains cannot raise it. In the console it needs the admin role in that environment.

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

await operator.impactLimits.update('lim_01JABCDEF', { amount: 10 });
curl -s -X PATCH https://api.anlyon.com/api/v2/impact-limits/lim_01JABCDEF \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 10 }'
operator = Client(api_key=os.environ["ANLYON_OPERATOR_KEY"])

operator.impact_limits.update("lim_01JABCDEF", amount=10)

A limit’s name and amount can change. Its dimension, scope and period are fixed. Lowering a limit never releases existing exposure. It blocks new work until availability recovers.

Wait for the period. A day limit is the UTC day and a month limit is the UTC month. consumed starts again at zero in the next period. A total limit has one period and does not reset. Held exposure carries over, as shown above.

Resolve held exposure. If reserved is what fills the limit, settle the effects behind it. List them with effects({ unresolved: true }), then reconcile or resolve each one. See When the outcome is unknown.

Then invoke again. A refused effect is final. It does not run later when room appears. Send a new invocation with a new Idempotency-Key. The same operationKey with the same request returns the refused effect, so use a new one of those as well.

What your agent should do

  1. Check grade === "refused" and the reason in error, not just the HTTP status.
  2. Tell the user, or the person supervising the agent, that the cap was reached. Do not loop: the same call will be refused again until room appears.
  3. Optionally read available with impactLimits.list() before asking, and skip calls that cannot fit.

How it behaves

  • Governed means an adapter or a declaration. A governed action draws from the limit. Keep the provider credential in the vault so the action is the path to the provider.
  • A limit belongs to one environment. Each environment has its own.
  • The money examples in these pages are stripe.refund.
  • The amount of a declared action is the expression you wrote. Set an upper_bound at the most one call can change.
  • A limit bounds quantity. Five emails fit a limit of five, whoever receives them.
  • The refusal record is a database record.

Was this page helpful?