# `MingaAgent.Providers.Native.ReqLLMAdapter`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/providers/native/req_llm_adapter.ex#L1)

ReqLLM-specific adapter helpers for the native provider.

`MingaAgent.Providers.Native` owns orchestration policy: turn flow, retry, cost, compaction, approvals, tool coordination, context updates, and event normalization. This module owns the ReqLLM-shaped details needed to make one provider request and decode one provider response.

# `llm_client`

```elixir
@type llm_client() :: (String.t(), [ReqLLM.Message.t()], keyword() -&gt;
                   {:ok, ReqLLM.StreamResponse.t()} | {:error, term()})
```

Streaming LLM client compatible with ReqLLM.stream_text/3.

# `raw_usage`

```elixir
@type raw_usage() :: %{
  optional(:input_tokens) =&gt; non_neg_integer(),
  optional(:output_tokens) =&gt; non_neg_integer(),
  optional(:input) =&gt; non_neg_integer(),
  optional(:output) =&gt; non_neg_integer(),
  optional(:cache_read_input_tokens) =&gt; non_neg_integer(),
  optional(:cache_creation_input_tokens) =&gt; non_neg_integer(),
  optional(:cache_read) =&gt; non_neg_integer(),
  optional(:cache_write) =&gt; non_neg_integer(),
  optional(:total_cost) =&gt; number()
}
```

Raw ReqLLM usage payload before Native normalizes it into TurnUsage.

# `stream_callbacks`

```elixir
@type stream_callbacks() :: [
  on_text: (String.t() -&gt; term()),
  on_thinking: (String.t() -&gt; term()),
  on_tool_call: (tool_call() -&gt; term())
]
```

Callbacks used while streaming a provider response.

# `tool_call`

```elixir
@type tool_call() :: MingaAgent.Providers.Native.ReqLLMAdapter.ToolCall.t()
```

Neutralized tool-call payload emitted by ReqLLM streaming.

# `turn_result`

```elixir
@type turn_result() :: MingaAgent.Providers.Native.ReqLLMAdapter.TurnResult.t()
```

Decoded result from one provider response.

# `anthropic_model?`

```elixir
@spec anthropic_model?(String.t()) :: boolean()
```

Returns true for Anthropic-compatible models.

# `assistant_tool_call`

```elixir
@spec assistant_tool_call(String.t(), String.t(), map()) :: ReqLLM.ToolCall.t()
```

Creates a ReqLLM tool-call value for assistant messages.

# `call_sync`

```elixir
@spec call_sync(
  llm_client(),
  String.t(),
  [ReqLLM.Message.t()],
  keyword(),
  MingaAgent.Config.t()
) ::
  {:ok, String.t()} | {:error, term()}
```

Runs a non-streaming text request through ReqLLM stream processing.

# `default_client`

```elixir
@spec default_client() :: llm_client()
```

Returns the default ReqLLM streaming client.

# `ensure_api_key_in_env`

```elixir
@spec ensure_api_key_in_env(String.t()) :: :ok
```

Sets the provider API key env var when credentials are file-backed.

# `openai_codex_model?`

```elixir
@spec openai_codex_model?(String.t()) :: boolean()
```

Returns true for OpenAI Codex OAuth-backed models.

# `process_stream`

```elixir
@spec process_stream(ReqLLM.StreamResponse.t(), stream_callbacks()) ::
  {:ok, turn_result()} | {:error, term(), String.t()}
```

Processes a ReqLLM stream response into a neutral turn result.

# `stream`

```elixir
@spec stream(llm_client(), String.t(), [ReqLLM.Message.t()], keyword()) ::
  {:ok, ReqLLM.StreamResponse.t()} | {:error, term()}
```

Runs one ReqLLM streaming request attempt. Retry ownership stays in Native.

# `stream_opts`

```elixir
@spec stream_opts(
  String.t(),
  [ReqLLM.Tool.t()],
  String.t(),
  pos_integer(),
  MingaAgent.Config.t()
) ::
  keyword()
```

Builds ReqLLM stream options for one native provider request.

# `summary_client`

```elixir
@spec summary_client(llm_client(), MingaAgent.Config.t()) ::
  MingaAgent.Compaction.summary_fn()
```

Builds the summary callback expected by the compaction subsystem.

# `validate_model`

```elixir
@spec validate_model(String.t()) :: :ok | {:error, String.t(), :invalid_format}
```

Validates the model string before ReqLLM sees it.

---

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