# `LlmCall.Dialect.Anthropic.Messages`
[🔗](https://github.com/gilbertwong96/llm_call/blob/main/lib/llm_call/dialect/anthropic/messages.ex#L1)

Anthropic Messages (`POST /v1/messages`).

`system` is a top-level field, `max_tokens` is required, tool results are
`tool_result` blocks inside a user turn, and reasoning is controlled by an
explicit thinking budget rather than an effort level.

A server tool is `{"type": "web_search_20250305", "name": "web_search"}`. The codec
takes `ToolSpec.name` as the versioned type and derives the callable name from its
date suffix; `provider_options.anthropic["name"]` overrides it.

`thinking.budget_tokens` must be at least 1024 and less than `max_tokens`, and
`usage.input_tokens` counts only the tokens after the last cache breakpoint, so
`Usage.total_tokens` adds the cache read and write counters.

`stop_reason` values outside the canonical union decode as `:unknown`:
`pause_turn` (a server-tool loop paused; send the response back to continue) and
`model_context_window_exceeded`. `refusal` decodes as `:content_filter`, because
it is a classifier stop. The wire value stays in `Response.raw`.

The `anthropic-version` header is pinned to the API version this codec targets,
and a codec header wins over a client one, so it is not overridable per call.

`call_id` on a tool result is the Anthropic `tool_use_id`.

# `encode_request`

```elixir
@spec encode_request(LlmCall.Request.t(), LlmCall.Config.t()) ::
  {:ok, LlmCall.EncodedRequest.t()} | {:error, LlmCall.Error.t()}
```

Validates the request and encodes it as a `POST` to the codec's `@path`.

---

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