# `LLMProxy.Provider.TokenCodec`
[🔗](https://github.com/elixir-vibe/llm_proxy/blob/v0.3.1/lib/llm_proxy/provider/token_codec.ex#L1)

Configurable encoding boundary for provider API keys and OAuth tokens.

A codec receives the credential field as context. This lets a codec bind its
ciphertext to the field and prevents an access token from being used as a
refresh token. Configure a module or a `{module, options}` tuple with
`:provider_token_codec`.

# `context`

```elixir
@type context() :: %{field: :token | :refresh_token}
```

# `options`

```elixir
@type options() :: keyword() | map()
```

# `decode`

```elixir
@callback decode(String.t(), context(), options()) :: {:ok, String.t()} | {:error, term()}
```

# `encode`

```elixir
@callback encode(String.t(), context(), options()) :: {:ok, String.t()} | {:error, term()}
```

# `encoded?`

```elixir
@callback encoded?(String.t(), options()) :: boolean()
```

# `validate_options`
*optional* 

```elixir
@callback validate_options(options()) :: :ok | {:error, term()}
```

# `credential`

```elixir
@spec credential(LLMProxy.Schemas.ProviderToken.t()) ::
  {:ok, LLMProxy.Provider.Credential.t()} | {:error, term()}
```

# `decode`

```elixir
@spec decode(String.t() | nil, :token | :refresh_token) ::
  {:ok, String.t() | nil} | {:error, term()}
```

# `encode`

```elixir
@spec encode(String.t() | nil, :token | :refresh_token) ::
  {:ok, String.t() | nil} | {:error, term()}
```

# `encode_attrs`

```elixir
@spec encode_attrs(map()) :: {:ok, map()} | {:error, term()}
```

# `encoded?`

```elixir
@spec encoded?(String.t() | nil) :: boolean()
```

---

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