# Configuration

> Set environment variables and secrets, tune a premade model's settings, and override the command of your own image, for rentals and services.

Source: https://legion.ambient.xyz/docs/renting/configuration

After this page you can pass configuration to the container of a rental or a service: environment variables (some of them secret), the settings of a premade model, and, for your own image, a different command.

The same three parts work on a rental and on a [service](https://legion.ambient.xyz/docs/renting/services/create), in the app, with the `legion` CLI, over MCP and with the API.

> The provider's machine can read anything in the container, including every environment variable and secret. A secret is hidden from other people in your organization and from the API, not from the host that runs it. Treat it like a prompt: give the container only what it needs, and use keys you can revoke.

## Environment variables

Add variables on the **Software** step of the rent form, under **Advanced configuration**, and on the **Model** step of the autoscaled service form, under **Advanced**. Both open the same sections: **Environment variables**, **Model settings** (for a premade model) and **Command and arguments** (for your own image). Each variable has a **Name**, a **Value**, a **Secret** switch and **Remove**. They work for starter images, models and your own image.

The rules:

- A name starts with a letter or an underscore, then letters, digits and underscores, up to 128 characters. It is case sensitive.
- Names that start with `LEGION_` are reserved for Legion. So are the names the runtime sets itself: `PATH`, `HOME`, `HOSTNAME`, `CUDA_VISIBLE_DEVICES` and every name that starts with `NVIDIA_`. A reserved name is refused with `env_reserved`, and a name or value that breaks the rules above with `invalid_env`.
- At most 64 variables, a value up to 32 KiB, and 64 KiB for all values together.

Legion passes the variables to your container when it starts it. A model's own settings (below) arrive as `LEGION_SETTING_` variables, so you never set those yourself.

### Secrets

Turn on **Secret** for a value that must not be read back: an API token, a password, a signing key.

- A secret value is write only. After you save, the app and the API show the name and **Set, hidden**, never the value. Press **Replace** to enter a new value. To keep it, leave the row alone.
- Legion stores it encrypted, and it appears in no log, event or audit entry. Those record the name only.
- A value that is not secret is shown back as you entered it.
- The provider's machine receives the value in plain form, because the container needs it. See the note above.

### Changing variables later

Open the **Details** tab of a rental, or the **Settings** tab of a service. Each has a **Configuration** card. Change the rows, then press **Save configuration**.

- On a **running rental**, the app asks you to confirm with **Save and restart**. The container is created again with the new values. Files outside `/workspace` are reset, and the workspace is kept.
- On a **stopped rental**, press **Save**. The new values apply the next time it starts.
- On an **autoscaled service**, it is a change to the template. The app says the replicas roll one at a time: Legion starts a new replica with the new values before it retires an old one, so the service keeps serving.
- A service on a rental uses the rental's variables.

## Model settings

A premade model has a short list of settings that are safe to change. They appear under **Model settings** when you choose the model, with the allowed range, a line of help and the default. A setting you leave alone uses the image's default.

| Key | Type | What it does |
| --- | --- | --- |
| `max_model_len` | whole number | The longest prompt plus answer, in tokens. A longer context needs more GPU memory. |
| `gpu_memory_utilization` | number | The share of each GPU's memory the model server may use. |
| `max_num_seqs` | whole number | How many requests it works on at once. More needs more memory. |
| `enable_prefix_caching` | on or off | Reuses the work for a prompt prefix that repeats. |
| `tool_call_parser` | one of a list | How the model's tool calls are read. |
| `reasoning_parser` | one of a list | How the model's reasoning text is separated from its answer. |

Each model supports only the keys its image supports, with its own bounds. This is what each premade model allows:

| Catalog id | Setting | Allowed values | Default |
| --- | --- | --- | --- |
| `qwen3-5-4b` | Context length (`max_model_len`) | 1024 to 262144 | `8192` |
| `qwen3-5-4b` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `qwen3-5-4b` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `qwen3-5-4b` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `qwen3-5-4b` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | `qwen3_coder` |
| `qwen3-5-4b` | Reasoning format (`reasoning_parser`) | `qwen3` | `qwen3` |
| `qwen3-5-9b` | Context length (`max_model_len`) | 1024 to 262144 | `8192` |
| `qwen3-5-9b` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `qwen3-5-9b` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `qwen3-5-9b` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `qwen3-5-9b` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | `qwen3_coder` |
| `qwen3-5-9b` | Reasoning format (`reasoning_parser`) | `qwen3` | `qwen3` |
| `qwen3-6-35b-a3b-fp8` | Context length (`max_model_len`) | 1024 to 262144 | `32768` |
| `qwen3-6-35b-a3b-fp8` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `qwen3-6-35b-a3b-fp8` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `qwen3-6-35b-a3b-fp8` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `qwen3-6-35b-a3b-fp8` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | `qwen3_coder` |
| `qwen3-6-35b-a3b-fp8` | Reasoning format (`reasoning_parser`) | `qwen3` | `qwen3` |
| `qwen3-coder-30b-a3b-fp8` | Context length (`max_model_len`) | 1024 to 262144 | `32768` |
| `qwen3-coder-30b-a3b-fp8` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `qwen3-coder-30b-a3b-fp8` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `qwen3-coder-30b-a3b-fp8` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `qwen3-coder-30b-a3b-fp8` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | `qwen3_coder` |
| `huihui-qwen3-5-4b-abliterated` | Context length (`max_model_len`) | 1024 to 262144 | `8192` |
| `huihui-qwen3-5-4b-abliterated` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `huihui-qwen3-5-4b-abliterated` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `huihui-qwen3-5-4b-abliterated` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `huihui-qwen3-5-4b-abliterated` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | Chosen by the image at start |
| `huihui-qwen3-5-4b-abliterated` | Reasoning format (`reasoning_parser`) | `qwen3` | `qwen3` |
| `huihui-qwen3-5-9b-abliterated` | Context length (`max_model_len`) | 1024 to 262144 | `8192` |
| `huihui-qwen3-5-9b-abliterated` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `huihui-qwen3-5-9b-abliterated` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `huihui-qwen3-5-9b-abliterated` | Prefix caching (`enable_prefix_caching`) | On or off | On |
| `huihui-qwen3-5-9b-abliterated` | Tool call format (`tool_call_parser`) | `qwen3_coder`, `qwen3_xml` | Chosen by the image at start |
| `huihui-qwen3-5-9b-abliterated` | Reasoning format (`reasoning_parser`) | `qwen3` | `qwen3` |
| `huihui-gemma-4-12b-abliterated` | Context length (`max_model_len`) | 1024 to 131072 | `8192` |
| `huihui-gemma-4-12b-abliterated` | GPU memory share (`gpu_memory_utilization`) | `0.80`, `0.85`, `0.90`, `0.95` | `0.90` |
| `huihui-gemma-4-12b-abliterated` | Concurrent requests (`max_num_seqs`) | 1 to 1024 | Chosen by the image at start |
| `huihui-gemma-4-12b-abliterated` | Prefix caching (`enable_prefix_caching`) | On or off | On |

Any other key, or a value outside the bounds, is refused with `invalid_model_setting`, naming the key. The catalog entry's `settings` list carries the same values for an agent.

A setting that changes how much memory the model needs can change the hardware it needs. A longer context length or more concurrent requests can need a bigger GPU, or more GPUs. The form shows a note when that happens, and the estimate shows the effect before you pay: the GPUs it needs, the price range and, for a service, the likely hardware. For a service, Legion uses the same numbers when it picks the cheapest hardware that fits.

Legion passes each setting to the model server as `LEGION_SETTING_<KEY>`, for example `LEGION_SETTING_MAX_MODEL_LEN=16384`. Changing a setting on a running rental restarts its container, like a variable.

## Command and arguments

For your own image only, **Command and arguments** replaces what the container runs:

- **Command** replaces the image's `ENTRYPOINT`.
- **Arguments** replace its `CMD`.

Enter one item per line in each field. They are separate items, not one line, so there is no shell to quote for. Use at most 64 items of up to 4 KiB each. A list that breaks this is refused with `invalid_command`. Leave them empty to run what the image says.

Legion's own SSH server and, for a served model, its serve wrapper still apply as before. A premade image or model refuses an override with `override_not_allowed`.

## From the CLI

```sh
legion rental create --offer HOST_NAME --image ghcr.io/acme/train:1 --gpus 1 --ssh-key KEY_LABEL \
  --env DATASET=imagenet --env EPOCHS=30 \
  --secret-env HF_TOKEN \
  --command python --arg train.py --arg --fast
```

- `--env NAME=value` sets a variable. Repeat it for more.
- `--secret-env NAME` makes a secret. It reads the value from standard input, or asks for it at a hidden prompt on a terminal, and never takes it as an argument, so it stays out of your shell history and process list.
- `--setting key=value` sets a model setting, for example `--setting max_model_len=16384`.
- `--command` and `--arg` set the command and arguments, one item per use of the flag.

`legion services create` and `legion services update` take the same flags, and the preview shows the names of variables, never a secret. The preview also shows the hardware a setting changes. See the [command reference](https://legion.ambient.xyz/docs/cli/commands).

## From an agent or the API

The create and update tools take the same fields, and so do the API's rental and service requests:

```json
{
  "env": [
    { "name": "DATASET", "value": "imagenet", "secret": false },
    { "name": "HF_TOKEN", "value": "SECRET_VALUE", "secret": true }
  ],
  "model_settings": { "max_model_len": 16384, "enable_prefix_caching": true },
  "command": ["python"],
  "args": ["train.py", "--fast"]
}
```

A secret comes back as `{ "name": "HF_TOKEN", "secret": true }` with no value, and a variable that is not secret comes back with its value. Previews and events list names only. An agent never asks you to type a secret into the chat: it sends you to the app or to `legion --secret-env`.

## Errors

| Code | Meaning |
| --- | --- |
| `env_reserved` | A variable name is reserved: `LEGION_*`, or one the runtime sets. |
| `invalid_env` | A variable name or value breaks the rules: a bad name, a duplicate, too many variables, or a value too large. |
| `invalid_model_setting` | A key the model doesn't support, or a value outside its bounds. The answer names the key. |
| `invalid_command` | The command or arguments are too long, or have too many items. |
| `override_not_allowed` | A command or arguments on a premade image or model. |
| `host_unsupported` | The host's Legion software is too old to pass the configuration to a container. Choose another host. |
| `model_settings_do_not_fit` | With these settings the model needs more GPU memory than the GPUs you chose have. Lower the context length or concurrent requests, or rent more GPUs. |
| `model_settings_unavailable` | Legion can't work out what these settings need for this model right now. Try again, or leave the settings at their defaults. |
