Configuration
Set environment variables and secrets, tune a premade model's settings, and override the command of your own image, for rentals and services.
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, 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_and every name that starts withVISIBLE_ DEVICES NVIDIA_. A reserved name is refused withenv_, and a name or value that breaks the rules above withreserved 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_ 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
/are reset, and the workspace is kept.workspace 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_ | whole number | The longest prompt plus answer, in tokens. A longer context needs more GPU memory. |
gpu_ | number | The share of each GPU's memory the model server may use. |
max_ | whole number | How many requests it works on at once. More needs more memory. |
enable_ | on or off | Reuses the work for a prompt prefix that repeats. |
tool_ | one of a list | How the model's tool calls are read. |
reasoning_ | 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_) | 1024 to 262144 | 8192 |
qwen3-5-4b | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
qwen3-5-4b | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
qwen3-5-4b | Prefix caching (enable_) | On or off | On |
qwen3-5-4b | Tool call format (tool_) | qwen3_, qwen3_ | qwen3_ |
qwen3-5-4b | Reasoning format (reasoning_) | qwen3 | qwen3 |
qwen3-5-9b | Context length (max_) | 1024 to 262144 | 8192 |
qwen3-5-9b | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
qwen3-5-9b | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
qwen3-5-9b | Prefix caching (enable_) | On or off | On |
qwen3-5-9b | Tool call format (tool_) | qwen3_, qwen3_ | qwen3_ |
qwen3-5-9b | Reasoning format (reasoning_) | qwen3 | qwen3 |
qwen3-6-35b-a3b-fp8 | Context length (max_) | 1024 to 262144 | 32768 |
qwen3-6-35b-a3b-fp8 | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
qwen3-6-35b-a3b-fp8 | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
qwen3-6-35b-a3b-fp8 | Prefix caching (enable_) | On or off | On |
qwen3-6-35b-a3b-fp8 | Tool call format (tool_) | qwen3_, qwen3_ | qwen3_ |
qwen3-6-35b-a3b-fp8 | Reasoning format (reasoning_) | qwen3 | qwen3 |
qwen3-coder-30b-a3b-fp8 | Context length (max_) | 1024 to 262144 | 32768 |
qwen3-coder-30b-a3b-fp8 | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
qwen3-coder-30b-a3b-fp8 | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
qwen3-coder-30b-a3b-fp8 | Prefix caching (enable_) | On or off | On |
qwen3-coder-30b-a3b-fp8 | Tool call format (tool_) | qwen3_, qwen3_ | qwen3_ |
huihui-qwen3-5-4b-abliterated | Context length (max_) | 1024 to 262144 | 8192 |
huihui-qwen3-5-4b-abliterated | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
huihui-qwen3-5-4b-abliterated | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
huihui-qwen3-5-4b-abliterated | Prefix caching (enable_) | On or off | On |
huihui-qwen3-5-4b-abliterated | Tool call format (tool_) | qwen3_, qwen3_ | Chosen by the image at start |
huihui-qwen3-5-4b-abliterated | Reasoning format (reasoning_) | qwen3 | qwen3 |
huihui-qwen3-5-9b-abliterated | Context length (max_) | 1024 to 262144 | 8192 |
huihui-qwen3-5-9b-abliterated | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
huihui-qwen3-5-9b-abliterated | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
huihui-qwen3-5-9b-abliterated | Prefix caching (enable_) | On or off | On |
huihui-qwen3-5-9b-abliterated | Tool call format (tool_) | qwen3_, qwen3_ | Chosen by the image at start |
huihui-qwen3-5-9b-abliterated | Reasoning format (reasoning_) | qwen3 | qwen3 |
huihui-gemma-4-12b-abliterated | Context length (max_) | 1024 to 131072 | 8192 |
huihui-gemma-4-12b-abliterated | GPU memory share (gpu_) | 0., 0., 0., 0. | 0. |
huihui-gemma-4-12b-abliterated | Concurrent requests (max_) | 1 to 1024 | Chosen by the image at start |
huihui-gemma-4-12b-abliterated | Prefix caching (enable_) | On or off | On |
Any other key, or a value outside the bounds, is refused with invalid_, 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_, for example LEGION_. 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_. 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_.
From the CLI
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=valuesets a variable. Repeat it for more.--secret-env NAMEmakes 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=valuesets a model setting, for example--setting max_.model_ len=16384 --commandand--argset 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.
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:
{
"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_ 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_ | A variable name is reserved: LEGION_, or one the runtime sets. |
invalid_ | A variable name or value breaks the rules: a bad name, a duplicate, too many variables, or a value too large. |
invalid_ | A key the model doesn't support, or a value outside its bounds. The answer names the key. |
invalid_ | The command or arguments are too long, or have too many items. |
override_ | A command or arguments on a premade image or model. |
host_ | The host's Legion software is too old to pass the configuration to a container. Choose another host. |
model_ | 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_ | Legion can't work out what these settings need for this model right now. Try again, or leave the settings at their defaults. |