# `AshAi.Transcript.Codec`
[🔗](https://github.com/ash-project/ash_ai/blob/v1.5.6/lib/ash_ai/transcript/codec.ex#L5)

Encodes Elixir terms as JSON-safe values and back, without losing atoms,
tuples, binaries, or ReqLLM structs.

Provider metadata on ReqLLM messages uses atom keys and values (for example
`%{provider: :anthropic, signature: "..."}`) that a JSON round trip would turn
into strings, which the provider encoders would then ignore. Values that JSON
can't represent are wrapped in a single-key object:

- atoms: `%{"$atom" => "anthropic"}`
- maps with atom keys: `%{"$atoms" => %{"provider" => ...}}`
- other maps with non-string keys: `%{"$map" => [[key, value], ...]}`
- tuples: `%{"$tuple" => [...]}`
- non-UTF-8 binaries: `%{"$binary" => base64}`
- ReqLLM structs: `%{"$struct" => "ReqLLM.Message", "fields" => ...}`

Decoding only creates existing atoms and only rebuilds the ReqLLM structs
listed here; any other value decodes to plain data.

# `decode`

```elixir
@spec decode(term()) :: term()
```

Decodes a value produced by `encode/1`.

# `encode`

```elixir
@spec encode(term()) :: term()
```

Encodes a term as a JSON-safe value.

---

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