# `AshRateLimiter.BuiltinPreparations`

Preparation helpers to allow direct usage in read actions.

# `rate_limit_options`

```elixir
@type rate_limit_options() :: [
  limit: pos_integer(),
  per: pos_integer(),
  key: String.t() | AshRateLimiter.keyfun(),
  on: :before_action | :before_transaction
]
```

# `rate_limit`

```elixir
@spec rate_limit(rate_limit_options()) ::
  {AshRateLimiter.Preparation, rate_limit_options()}
```

Add a rate-limit change directly to an action.

## Options

* `:limit` (`t:pos_integer/0`) - Required. The maximum number of events allowed within the given scale

* `:per` (`t:pos_integer/0`) - Required. The time period (in milliseconds) for in which events are counted

* `:key` - The key used to identify the event. See the docs for `AshRateLimiter.key_for_action/2` for more. The default value is `&AshRateLimiter.key_for_action/2`.

* `:on` - The lifecycle hook to use for rate limiting. `:before_action` runs inside the transaction; `:before_transaction` runs outside the transaction, after validations. Valid values are :before_action, :before_transaction The default value is `:before_action`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
