# `PhoenixKit.API.PersonalKeysConfig`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v3.5.0/lib/phoenix_kit/api/personal_keys_config.ex#L1)

Settings of personal API keys (`PhoenixKit.API.Keys.create_personal_key/3`): how long
one may live and how many a person may have.

| Setting | Default | Allowed |
|---|---|---|
| `api_personal_key_max_days` | `90` | 1 to 365 |
| `api_personal_key_max_count` | `5` | 1 to 50 |

`api_personal_key_max_days` is both the ceiling of a personal key's expiry and the
expiry the "My API keys" form proposes and a rotation gives the new key: the end of the
UTC day that many days from today (`latest_expiry/0`). Lowering it does not shorten
keys already issued. `api_personal_key_max_count` counts a person's live personal keys,
a key in the grace period of a rotation included.

A stored value that does not parse or is below its minimum reads as the default; one
above its maximum reads as the maximum. A Settings read error reads as the default
(`PhoenixKit.API.Config.int/2`).

The same table drives the form on Settings -> API: `fields/0`, `current/0`,
`validate/1` and `save/2`, all or nothing like `PhoenixKit.API.FlowConfig`'s.

# `current`

```elixir
@spec current() :: %{required(String.t()) =&gt; String.t()}
```

The current value of every form field, as the text the field shows.

# `fields`

```elixir
@spec fields() :: [map()]
```

The two fields of the form, in the order the page shows them.

# `latest_expiry`

```elixir
@spec latest_expiry() :: DateTime.t()
```

The latest expiry a personal key may have now: the end of the UTC day `max_days/0`
days from today, as the form's dates are read.

# `max_count`

```elixir
@spec max_count() :: pos_integer()
```

Live personal keys one person may have (`api_personal_key_max_count`).

# `max_days`

```elixir
@spec max_days() :: pos_integer()
```

Days a personal key may live at most (`api_personal_key_max_days`).

# `save`

```elixir
@spec save(map(), keyword()) ::
  {:ok, [String.t()]} | {:error, [String.t()] | :save_failed}
```

Validates and writes a form. Returns the settings that changed. `opts` are the
history options of `Settings.update_setting_with_module/4` (`actor_uuid:`,
`source:`).

# `validate`

```elixir
@spec validate(map()) :: {:ok, [{String.t(), integer()}]} | {:error, [String.t()]}
```

Checks a submitted form. `{:ok, [{setting, integer}]}` when every field is a whole
number inside its range; otherwise `{:error, fields}` naming every bad field
(a missing field is bad, never the default).

---

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