---
title: "Set quotas per agent grant · Agent Wranglers"
url: https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing/quota-per-grant
id: AGT-24
level: Recommended
updated: 2026-10-22
tokens: 1085
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Set quotas per agent grant

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Quotas and pricing](https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: AGT-24
- Level: Recommended
- Chapter: [Quotas and pricing](https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing.md)
- Rule: Count usage per agent grant, the pair of one user and one agent, as well as per user and per operator. One agent can use at most its share of the user's quota.
- Check: A test gives one user two agent grants, each with half the quota. The first agent sends calls until it gets 429. The second agent's next call and the user's own next call both succeed.
- How: Agents call far faster than people and retry in loops. Without a limit per grant, one runaway agent uses up the quota that the user's other agents and the user's own browser need. Keep three counters, for the grant, the user and the verified operator from [Set a policy for each agent operator](https://agentwranglers.se/playbook/agents-as-users/identifying-agents/policy-per-operator.md). Refuse when any of them is over. Let the user set each agent's share in the account page, with a default such as half the user's quota. Answer an agent over its limit with 429, `Retry-After` and the headers in [Tell clients their rate limit](https://agentwranglers.se/playbook/api-design/reliability/rate-limit-headers.md). Tenant-wide fairness is in [Give each customer a fair share](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/per-tenant-limits.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
export async function withinQuota(redis, { userId, agentId, operator }, limits) {
  const minute = Math.floor(Date.now() / 60_000);
  const keys = [`q:grant:${userId}:${agentId}:${minute}`, `q:user:${userId}:${minute}`, `q:op:${operator}:${minute}`];
  const counts = await Promise.all(keys.map(async key => { const n = await redis.incr(key); await redis.expire(key, 120); return n; }));
  return counts[0] <= limits.grant && counts[1] <= limits.user && counts[2] <= limits.operator;
}
```

### Python example

```python
def within_quota(redis, user_id: str, agent_id: str, operator: str, limits: dict) -> bool:
    minute = int(time.time() // 60)
    keys = [f"q:grant:{user_id}:{agent_id}:{minute}", f"q:user:{user_id}:{minute}", f"q:op:{operator}:{minute}"]
    pipe = redis.pipeline()
    for key in keys:
        pipe.incr(key)
        pipe.expire(key, 120)
    grant, _, user, _, op, _ = pipe.execute()
    return grant <= limits["grant"] and user <= limits["user"] and op <= limits["operator"]
```

## Sources

- [OWASP Top 10 for LLM Applications, LLM10 Unbounded Consumption](https://genai.owasp.org/llmrisk/llm102025-unbounded-consumption/)
- [MCP specification on tools (security considerations)](https://modelcontextprotocol.io/specification/2026-07-28/server/tools)

## Related rules

- AGT-3 [Set a policy for each agent operator](https://agentwranglers.se/playbook/agents-as-users/identifying-agents/policy-per-operator.md) in Agents as users
- API-36 [Tell clients their rate limit](https://agentwranglers.se/playbook/api-design/reliability/rate-limit-headers.md) in API design
- SCL-31 [Give each customer a fair share](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/per-tenant-limits.md) in Scaling

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing/quota-per-grant">Agent Wranglers agents as users playbook</a>`. In code you write, add a comment next to it with the same link.

- Next: [Cap what each agent grant may spend](https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing/spend-cap-per-grant.md)
- [Quotas and pricing](https://agentwranglers.se/playbook/agents-as-users/quotas-and-pricing.md)
