# `LlmCall.Application`
[🔗](https://github.com/gilbertwong96/llm_call/blob/main/lib/llm_call/application.ex#L1)

Starts the two Finch pools this library calls through.

There are two, because a protocol is a property of the transport and a pool picks one:

  * `LlmCall.Finch.HTTP2` — one connection that multiplexes, plus keep-alive PINGs.
    Serves `https://`.
  * `LlmCall.Finch.HTTP1` — `size` connections with no multiplexing. Serves `http://`.

A provider that says nothing is routed by its `base_url` scheme, which is what curl
does: `https://` negotiates HTTP/2 through ALPN, and `http://` is HTTP/1.1. The split
exists because HTTP/2 over plaintext is `h2c` — there is no ALPN, so Mint assumes prior
knowledge and sends `PRI * HTTP/2.0` to a server that is speaking HTTP/1 text.

A provider can override the choice with `pool:`:

    use LlmCall.Provider,
      base_url: "http://localhost:11434",
      auth: :none,
      codecs: [chat: LlmCall.Dialect.OpenAI.Chat],
      pool: :http1                      # or :http2

    pool: [size: 200, count: 4]         # Finch's own keys, on top of the defaults

A host that wants its own pool starts it in its own supervision tree and passes
`http_opts: [name: MyPool]` to a provider or client; these stay unused in that case.
If either name is taken when this application starts, that pool is left alone.

## Overriding the defaults

`config :llm_call, :pools` may override either pool by name, with Finch's own keys:

    config :llm_call,
      pools: %{
        LlmCall.Finch.HTTP1 => [size: 200],
        LlmCall.Finch.HTTP2 => [count: 2]
      }

The library's own shape is the base and the configuration is merged onto it, so a host
that only wants a higher HTTP/1 ceiling says just that. See `h1_pool_opts/0` and
`h2_pool_opts/0` for what the base is.

## Why these numbers

Capacity is a property of a deployment, not of a library, so neither pool is sized
generously. What *is* a library's business is the shape: HTTP/2 ignores `:size` and
only `:count` adds connections, while HTTP/1 has no multiplexing at all, so `size` is a
hard ceiling.

On the HTTP/2 pool the keep-alive PING is the one setting here that changes behaviour
rather than capacity. A single long-lived connection that a NAT or load balancer drops
without a RST leaves a corpse that the next request discovers; Finch sends the PING once
the connection has been idle this long, and a write onto a dead socket moves the pool to
`:disconnected` so it reconnects before a request lands.

# `deep_merge`

```elixir
@spec deep_merge(keyword() | map(), keyword() | map()) :: keyword()
```

Merges `override` onto `base`, recursing into nested sections.

A plain `Keyword.merge/2` would replace `http2: [ping_interval: ...]` wholesale when a
host sets only `http2: [max_connection_age: ...]`, losing the rest. Both inputs may be a
keyword list or a map; the result is a keyword list, which is what `Finch.start_link/1`
and `Finch.start_pool/3` take.

Public because `LlmCall.Provider` merges a `pool:` declaration onto the same shape.

# `default_children`

```elixir
@spec default_children(atom()) :: {Finch, keyword()} | []
```

Returns the children to start for one pool name, or none when it is registered.

Registration is checked here because a `Finch` child that finds the name taken returns
`{:error, {:already_started, pid}}`, which would fail the whole application start rather
than yield to the existing pool. The check is not atomic with Finch's own registration;
a pool started in the same instant by another supervision tree is the one case this
cannot order.

# `default_ping_interval`

```elixir
@spec default_ping_interval() :: pos_integer()
```

The keep-alive `ping_interval` this library sets on its HTTP/2 pool.

Exposed so a host can compare against its own value instead of copying a number.

# `default_pool_count`

```elixir
@spec default_pool_count() :: pos_integer()
```

The connection or shard count this library starts with.

# `default_pool_size`

```elixir
@spec default_pool_size() :: pos_integer()
```

The HTTP/1 connection ceiling this library starts with.

# `h1_pool_name`

```elixir
@spec h1_pool_name() :: atom()
```

The name of the HTTP/1 pool this library starts.

# `h1_pool_opts`

```elixir
@spec h1_pool_opts() :: keyword()
```

The pool configuration this library gives an HTTP/1 origin.

HTTP/1 has no multiplexing, so `size` is a hard ceiling on concurrent requests and
`count` shards it.

# `h2_pool_name`

```elixir
@spec h2_pool_name() :: atom()
```

The name of the HTTP/2 pool this library starts.

# `h2_pool_opts`

```elixir
@spec h2_pool_opts() :: keyword()
```

The pool configuration this library gives an HTTP/2 origin.

`size` is ignored on HTTP/2 — one connection multiplexes streams — so `count` is what
adds connections. The keep-alive PING is what makes an idle connection's death visible.

# `pool_name_for`

```elixir
@spec pool_name_for(String.t() | URI.t()) :: atom()
```

The name of the pool an origin is served by when a provider declares none.

# `pool_opts_for`

```elixir
@spec pool_opts_for(String.t() | URI.t()) :: keyword()
```

The pool configuration for the origin of `base_url`.

`https://` gets the HTTP/2 shape and everything else the HTTP/1 one. Only `https` counts
as secure: `http://` has no ALPN, so HTTP/2 there is h2c prior knowledge.

# `resolved_pool_opts`

```elixir
@spec resolved_pool_opts(atom()) :: keyword()
```

The pool options a named pool gets after `config :llm_call, :pools` is applied.

The library's shape is the base and the configuration is merged onto it, so this is what
`default_children/0` hands Finch. Exposed because a host debugging its tuning wants to
see the resolved value without reading a running pool's internals.

---

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