# `Raxol.AgentClientProtocol.Schema.UsageUpdate`
[🔗](https://github.com/DROOdotFOO/raxol-agent/blob/raxol_agent_client_protocol-v0.1.0/packages/raxol_agent_client_protocol/lib/raxol/agent_client_protocol/schema/session_update.ex#L490)

Payload for the `SessionUpdate` `usage_update` variant: a context-window
and cost update for a session -- tokens currently in context (`used`),
the total context window size (`size`), and an optional cumulative
session `cost`.

Not present in f1729; ported straight from the pinned v1.19.0 oracle
schema (`priv/schema-oracle/v1/schema.json`, `$defs/UsageUpdate`), no
upstream attribution. `used`/`size` are required non-negative integers
per the oracle (no `x-deserialize-default-on-error` on either); `cost` is
optional and decode-lenient, defaulting to `nil` on an absent or
unparseable value.

# `t`

```elixir
@type t() :: %Raxol.AgentClientProtocol.Schema.UsageUpdate{
  _meta: map(),
  cost: Raxol.AgentClientProtocol.Schema.Cost.t() | nil,
  size: non_neg_integer(),
  used: non_neg_integer()
}
```

# `from_json`

```elixir
@spec from_json(term()) :: {:ok, t()} | {:error, term()}
```

Total: never raises. A missing/non-non-negative-integer `used` or `size`
is the only failure mode (both required); an absent or unparseable
optional `cost` defaults to `nil` rather than failing the whole object.

# `new`

```elixir
@spec new(non_neg_integer(), non_neg_integer()) :: t()
```

# `new`

```elixir
@spec new(
  non_neg_integer(),
  non_neg_integer(),
  Raxol.AgentClientProtocol.Schema.Cost.t() | nil
) :: t()
```

# `to_json`

```elixir
@spec to_json(t()) :: map()
```

---

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