> For the complete documentation index, see [llms.txt](https://weavescope.gitbook.io/beam_weaver/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://weavescope.gitbook.io/beam_weaver/operations/rate_limiting.md).

# Rate Limiting

BeamWeaver rate limiting bounds model and tool work before the runtime starts supervised tasks.

The first implementation is an in-memory token bucket:

```elixir
{:ok, limiter} =
  BeamWeaver.RateLimiter.start_bucket(
    capacity: 10,
    refill_amount: 10,
    refill_interval: 1_000
  )

:ok = BeamWeaver.RateLimiter.acquire(limiter, 1, timeout: 5_000)
```

Callers can wait, reject immediately, or drop immediately:

```elixir
BeamWeaver.RateLimiter.acquire(limiter, 1, mode: :wait, timeout: 5_000)
BeamWeaver.RateLimiter.acquire(limiter, 1, mode: :reject)
BeamWeaver.RateLimiter.acquire(limiter, 1, mode: :drop)
```

Failures are tagged tuples:

```elixir
{:error, %BeamWeaver.RateLimiter.Error{type: :timeout}}
{:error, %BeamWeaver.RateLimiter.Error{type: :rate_limited}}
```

Queued callers are monitored. If waiting work is canceled, it is removed from the queue and does not consume future refill capacity.

## Related Guides

* [Models](/beam_weaver/core-components/models.md#rate-limiting)
* [Fault Tolerance](/beam_weaver/capabilities/fault_tolerance.md)
* [Prebuilt Middleware](/beam_weaver/core-components/prebuilt_middleware.md#model-and-tool-call-limits)
* [Going To Production](/beam_weaver/operations/going_to_production.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://weavescope.gitbook.io/beam_weaver/operations/rate_limiting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
