# `Spectre.LLM`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/runtime/llm.ex#L1)

Small LLM boundary used by `Spectre.Runner`.

The runner sends a typed `Spectre.Prompt.Plan` here. A module that exports
`complete_plan/2` receives that plan with separate instruction, context, and
task fragments. Existing modules, tuples, and functions continue to receive
the plan's legacy string byte-for-byte. Tuple/function adapters may opt into
the typed contract with `prompt_format: :plan`; `prompt_format: :string`
explicitly selects compatibility serialization.

A fallback model independently negotiates the same capability, so a legacy
primary and structured fallback (or the reverse) can share one prompt plan.

# `completion`

```elixir
@type completion() :: String.t() | Spectre.Inference.Response.t() | map()
```

# `completion_result`

```elixir
@type completion_result() :: {:ok, completion()} | {:error, term()}
```

# `prompt`

```elixir
@type prompt() :: String.t() | Spectre.Prompt.Plan.t()
```

# `complete`

```elixir
@callback complete(
  String.t(),
  keyword()
) ::
  {:ok, String.t() | Spectre.Inference.Response.t() | map()} | {:error, term()}
```

# `complete_plan`
*optional* 

```elixir
@callback complete_plan(
  Spectre.Prompt.Plan.t(),
  keyword()
) ::
  {:ok, String.t() | Spectre.Inference.Response.t() | map()} | {:error, term()}
```

# `complete`

```elixir
@spec complete(
  prompt(),
  keyword()
) :: completion_result()
```

Completes a rendered string or typed prompt plan through the configured model
adapter or function.

    Spectre.LLM.complete("Say hello", model: {MyApp.LLM, :complete, model: "small"})

# `complete_once`

```elixir
@spec complete_once(
  prompt(),
  keyword()
) :: completion_result()
```

Executes exactly one configured model without applying the legacy fallback.

`Spectre.Inference` uses this primitive so one boundary owns retry and
profile fallback decisions.

# `provider_opts`

```elixir
@spec provider_opts(
  keyword(),
  [atom()]
) :: keyword()
```

Strips Spectre runtime context from an adapter keyword list.

Everything the runtime attaches for its own purposes — routing context,
state, prompt assigns, model bookkeeping — is removed, along with any
`spectre_*`-prefixed key, leaving only options intended for the provider.
Adapters call this instead of maintaining their own allowlists:

    def complete(prompt, opts) do
      provider_opts = Spectre.LLM.provider_opts(opts, [:test_pid])
      MyHTTP.post(url, body, provider_opts)
    end

`extra_keys` removes host-specific keys on top of the runtime set.

# `runtime_opt_keys`

```elixir
@spec runtime_opt_keys() :: [atom()]
```

Returns the option keys the Spectre runtime injects into adapter calls.

---

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