> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mellea.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# mellea.backends.model_options

> Common ModelOptions for Backend Generation.

export const SidebarFix = () => <script dangerouslySetInnerHTML={{
  __html: `
        (function () {
          const INTERVAL_MS = 500;

          const upgradeSidebar = () => {
            const links = document.querySelectorAll('a[href^="#"]');

            links.forEach((link) => {
              if (link.dataset.badged === "true") return;

              const rawText = (link.textContent || "").trim();

              // ========== FUNC ==========
              if (rawText.startsWith("FUNC ")) {
                const label = rawText.replace(/^FUNC\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Make the whole link a single flex row & prevent wrapping
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(48, 100, 227, 0.20)";
                badge.style.color = "#1D4ED8";

                badge.textContent = "FUNC";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }

              // ========== CLASS ==========
              if (rawText.startsWith("CLASS ")) {
                const label = rawText.replace(/^CLASS\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Same flex / nowrap treatment for class links
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(74, 222, 128, 0.20)";
                badge.style.color = "#15803D";

                badge.textContent = "CLASS";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }
            });
          };

          upgradeSidebar();
          setInterval(upgradeSidebar, INTERVAL_MS);
        })();
      `
}} />;

<SidebarFix />

Common ModelOptions for Backend Generation.

## Classes

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#4ADE8033]/20 text-[#15803D]">CLASS</span> `ModelOption` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/backends/model_options.py#L8" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

A type that wraps around model options.

Uses sentinel values (wrapped by @@@) to provide backend and model-agnostic keys for common model options.

Create a dictionary containing model options like this:

```python theme={null}
from mellea.backends import ModelOption
model_options = {{
    ModelOption.TEMPERATURE : 0.0,
    ModelOption.SYSTEM_PROMPT : "You are a helpful assistant"
}}
```

**Attributes:**

* `TOOLS`: Sentinel key for a list or dict of [`MelleaTool`](tools#class-melleatool) instances to expose for tool calling.
* `TOOL_CHOICE`: Key for tool choice strategy (passed through to the backend).
* `MAX_NEW_TOKENS`: Sentinel key for the maximum number of new tokens to generate.
* `SYSTEM_PROMPT`: Sentinel key for the system prompt string.
* `TEMPERATURE`: Key for the sampling temperature (passed through to the backend).
* `CONTEXT_WINDOW`: Sentinel key for the context window size.
* `THINKING`: Sentinel key for enabling/configuring reasoning/thinking mode.
* `SEED`: Sentinel key for the random seed for reproducible generation.
* `STREAM`: Sentinel key for enabling streaming responses.

<div className="h-8" />

**Methods:**

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

#### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `replace_keys` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/backends/model_options.py#L50" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
replace_keys(options: dict, from_to: dict[str, str]) -> dict[str, Any]
```

Return a new dict with selected keys in `options` renamed according to `from_to`.

Returns a new dict with the keys in `options` replaced with the corresponding value for that key in `from_to`.

* Any key with value == None is treated the same as the key missing.

* If the destination key already exists in `options`, the original value is kept in the output.

* Regardless of the presence of the destination key in `options`,
  the source key is always absent in the output.

Example:

```python theme={null}
>>> options = {{"k1": "v1", "k2": "v2", "M1": "m1"}}
>>> from_to = {{"k1": "M1", "k2": "M2"}}

>>> new_options = replace_keys(options, from_to)
>>> print(new_options)
... {{"M1": "m1", "M2": "v2"}}
```

* Notice that "M1" keeps the original value "m1", rather than "v1".
* Notice that both "k1" and "k2" are absent in the output.

**Args:**

* `options`: The source dictionary whose keys may be renamed.
* `from_to`: Mapping of old key names to new key names.

**Returns:**

* dict\[str, Any]: A new dictionary with the specified keys renamed.

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

#### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `remove_special_keys` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/backends/model_options.py#L122" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
remove_special_keys(model_options: dict[str, Any]) -> dict[str, Any]
```

Return a copy of `model_options` with all sentinel-valued keys removed.

Sentinel keys are those whose names start with `@@@` (e.g. `ModelOption.TOOLS`).
These are Mellea-internal keys that must not be forwarded to backend APIs.

**Args:**

* `model_options`: A model options dictionary that may contain sentinel keys.

**Returns:**

* dict\[str, Any]: A new dictionary with all `@@@`-prefixed keys omitted.

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

#### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `merge_model_options` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.6.0/mellea/backends/model_options.py#L141" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
merge_model_options(persistent_opts: dict[str, Any], overwrite_opts: dict[str, Any] | None) -> dict[str, Any]
```

Merge two model-options dicts, with `overwrite_opts` taking precedence on conflicts.

Creates a new dict that contains all keys and values from persistent opts and overwrite opts.
If there are duplicate keys, overwrite opts key value pairs will be used.

**Args:**

* `persistent_opts`: Base model options (lower precedence).
* `overwrite_opts`: Per-call model options that override
  `persistent_opts` on key conflicts; `None` is treated as empty.

**Returns:**

* dict\[str, Any]: A new merged dictionary.

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />
