# `LlmCall.Dialect.OpenAI.Chat`
[🔗](https://github.com/gilbertwong96/llm_call/blob/main/lib/llm_call/dialect/openai/chat.ex#L1)

OpenAI Chat Completions (`POST /v1/chat/completions`).

OpenAI-compatible providers use this codec too; their differences belong in
`LlmCall.Request.provider_options` and the transport's base URL, not in a new
protocol.

System instructions become a leading `system` message. Tool results become
`role: "tool"` messages, emitted before the message's remaining content
because OpenAI requires them directly after the assistant tool call.

`usage.prompt_tokens_details` carries both cache counters (read and write), and
`reasoning_effort` accepts `none`, `minimal`, `low`, `medium`, `high`, `xhigh`,
and `max`; the model decides which it honours.

The deprecated `message.function_call` and `delta.function_call` are not decoded
into `ToolCall`s: OpenAI replaced them with `tool_calls`, and only the old shape
is kept as `Content.Raw`, so a legacy provider's call is visible but not
dispatchable through `LlmCall.Response.tool_calls/1`.

# `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*
