# `PhoenixAI.Store.Guardrails.TokenBudget`
[🔗](https://github.com/franciscpd/phoenix-ai-store/blob/v0.1.0/lib/phoenix_ai/store/guardrails/token_budget.ex#L1)

Guardrail policy that enforces token budgets scoped to conversations,
users, or time windows.

This is a **stateful** policy that reads accumulated token counts from
the store adapter. The adapter must implement the
`PhoenixAI.Store.Adapter.TokenUsage` sub-behaviour.

## Options

  * `:max` (required) — maximum allowed token count
  * `:scope` — `:conversation` (default), `:user`, or `:time_window`
  * `:mode` — `:accumulated` (default) or `:estimated`
  * `:token_counter` — module implementing `PhoenixAI.Store.Memory.TokenCounter`
    (default: `PhoenixAI.Store.Memory.TokenCounter.Default`)
  * `:window_ms` — for `:time_window` scope, the window duration in ms
  * `:key_prefix` — for `:time_window` scope, Hammer key prefix
  * `:rate_limiter` — for `:time_window` scope, the Hammer-compatible module to use
    (default: `PhoenixAI.Store.Guardrails.TokenBudget.RateLimiter`)

## Assigns

The policy expects `request.assigns` to contain:

  * `:adapter` — the adapter module
  * `:adapter_opts` — keyword options for the adapter

These are injected by `PhoenixAI.Store.check_guardrails/3`.

---

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