# `MingaClaudeBridge.Status`
[🔗](https://github.com/jsmestad/minga-claude-bridge/blob/main/lib/minga_claude_bridge/status.ex#L1)

Holds the route's last known readiness and plan limits, and reports changes to Minga.

  * Availability results are cached per credential for a short time, so opening `/model` repeatedly does not start Claude Code every time.
  * Sessions send their `rate_limit_event`s here. A `rejected` status reports the route as `{:unavailable, :rate_limited, remedy}` with the reset time; the next allowed status reports it ready again with the last plan label.
  * Plan windows (`MingaAgent.InferenceRoute.PlanWindow`) come from `get_usage` answers (`put_usage/2`) and rate-limit events, merged by `MingaClaudeBridge.Route.PlanUsage`. Every change is reported with `Minga.Extension.ModelRoutes.report_usage/2`.
  * The models of the last probe and the measured context windows feed `MingaClaudeBridge.Route.models/1`. Windows are cached per credential and model with their measurement time.
  * Background measurements run under a `Task.Supervisor`, at most one per credential at a time (`start_measurement/3`).

Reports go through the reporter `MingaClaudeBridge` received when it registered the route. The reporter and both report functions are options so tests can observe reports.

# `availability`

```elixir
@type availability() :: {:ready, String.t()} | {:unavailable, atom(), String.t()}
```

# `report_fun`

```elixir
@type report_fun() :: (term(), availability() -&gt; term())
```

# `cached`

```elixir
@spec cached(GenServer.server(), term(), non_neg_integer()) ::
  {:ok, availability()} | :miss
```

Returns a cached availability for `key` when it is younger than `ttl` milliseconds.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `context_windows`

```elixir
@spec context_windows(GenServer.server()) :: %{required(String.t()) =&gt; pos_integer()}
```

Returns the most recently measured context window in tokens per model id, across credentials. Empty before the first measurement.

# `latest_rate_limit`

```elixir
@spec latest_rate_limit(GenServer.server()) ::
  MingaClaudeBridge.Wire.RateLimit.t() | nil
```

Returns the latest rate-limit event, or `nil`.

# `limit_remedy`

```elixir
@spec limit_remedy(number() | nil) :: String.t()
```

Returns the remedy text for a reached plan limit.

# `models`

```elixir
@spec models(GenServer.server()) :: [map()] | nil
```

Returns the model entries of Claude Code's last `initialize` answer, or `nil` before the first probe or when the server is not running.

# `plan_windows`

```elixir
@spec plan_windows(GenServer.server()) :: [MingaAgent.InferenceRoute.PlanWindow.t()]
```

Returns the current plan windows in display order.

# `put`

```elixir
@spec put(GenServer.server(), term(), availability()) :: :ok
```

Caches an availability result for `key`.

# `put_context_windows`

```elixir
@spec put_context_windows(GenServer.server(), term(), %{
  required(String.t()) =&gt; pos_integer()
}) :: :ok
```

Records the context windows measured for credential `key`. Models it could not measure keep their earlier value.

# `put_models`

```elixir
@spec put_models(GenServer.server(), [map()]) :: :ok
```

Records the model entries of a probe.

# `put_reporter`

```elixir
@spec put_reporter(term()) :: :ok
```

Stores the reporter from route registration for every later status server.

# `put_usage`

```elixir
@spec put_usage(GenServer.server(), term(), map()) :: :ok
```

Records a `get_usage` answer read with credential `key`: refreshes every plan window and reports them. An answer without windows reports an empty list, so Minga clears stale windows.

When the account's own answer named no plan and this credential's last check was ready, the plan the usage names is reported as the new ready label.

# `rate_limit`

```elixir
@spec rate_limit(GenServer.server(), MingaClaudeBridge.Wire.RateLimit.t()) :: :ok
```

Records a rate-limit event, as sessions do with their `:on_rate_limit` pid.

# `stale_models`

```elixir
@spec stale_models(GenServer.server(), term(), [String.t()], non_neg_integer()) :: [
  String.t()
]
```

Returns the ids among `model_ids` whose window for credential `key` is missing or older than `ttl` milliseconds.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the status server.

Options: `:name`, `:reporter` (defaults to the stored reporter), `:report` (a two-argument function, defaults to `Minga.Extension.ModelRoutes.report_status/2`), `:report_usage` (a two-argument function, defaults to `Minga.Extension.ModelRoutes.report_usage/2`), `:tasks` (the `Task.Supervisor` for measurements; without it no measurement starts), and `:notify` (a pid that receives `{:claude_bridge_measurement, :started | :finished, key}`, for tests).

# `start_measurement`

```elixir
@spec start_measurement(GenServer.server(), term(), (-&gt; term())) ::
  :ok | :busy | :unavailable
```

Starts `fun` as the background measurement for credential `key` under the task supervisor. Returns `:busy` while a measurement for `key` runs and `:unavailable` without a task supervisor.

# `usage_label`

```elixir
@spec usage_label(GenServer.server(), term()) :: String.t() | nil
```

Returns the plan label of the last `get_usage` answer for credential `key`, for example "Claude Max", or `nil`.

---

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