Skip to content

Configuration

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

On this page

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.

Note:

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.

Model settings
KeyTypeWhat it does
max_model_lenwhole numberThe longest prompt plus answer, in tokens. A longer context needs more GPU memory.
gpu_memory_utilizationnumberThe share of each GPU's memory the model server may use.
max_num_seqswhole numberHow many requests it works on at once. More needs more memory.
enable_prefix_cachingon or offReuses the work for a prompt prefix that repeats.
tool_call_parserone of a listHow the model's tool calls are read.
reasoning_parserone of a listHow 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:

Model settings
Catalog idSettingAllowed valuesDefault
qwen3-5-4bContext length (max_model_len)1024 to 2621448192
qwen3-5-4bGPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
qwen3-5-4bConcurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
qwen3-5-4bPrefix caching (enable_prefix_caching)On or offOn
qwen3-5-4bTool call format (tool_call_parser)qwen3_coder, qwen3_xmlqwen3_coder
qwen3-5-4bReasoning format (reasoning_parser)qwen3qwen3
qwen3-5-9bContext length (max_model_len)1024 to 2621448192
qwen3-5-9bGPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
qwen3-5-9bConcurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
qwen3-5-9bPrefix caching (enable_prefix_caching)On or offOn
qwen3-5-9bTool call format (tool_call_parser)qwen3_coder, qwen3_xmlqwen3_coder
qwen3-5-9bReasoning format (reasoning_parser)qwen3qwen3
qwen3-6-35b-a3b-fp8Context length (max_model_len)1024 to 26214432768
qwen3-6-35b-a3b-fp8GPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
qwen3-6-35b-a3b-fp8Concurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
qwen3-6-35b-a3b-fp8Prefix caching (enable_prefix_caching)On or offOn
qwen3-6-35b-a3b-fp8Tool call format (tool_call_parser)qwen3_coder, qwen3_xmlqwen3_coder
qwen3-6-35b-a3b-fp8Reasoning format (reasoning_parser)qwen3qwen3
qwen3-coder-30b-a3b-fp8Context length (max_model_len)1024 to 26214432768
qwen3-coder-30b-a3b-fp8GPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
qwen3-coder-30b-a3b-fp8Concurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
qwen3-coder-30b-a3b-fp8Prefix caching (enable_prefix_caching)On or offOn
qwen3-coder-30b-a3b-fp8Tool call format (tool_call_parser)qwen3_coder, qwen3_xmlqwen3_coder
huihui-qwen3-5-4b-abliteratedContext length (max_model_len)1024 to 2621448192
huihui-qwen3-5-4b-abliteratedGPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
huihui-qwen3-5-4b-abliteratedConcurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
huihui-qwen3-5-4b-abliteratedPrefix caching (enable_prefix_caching)On or offOn
huihui-qwen3-5-4b-abliteratedTool call format (tool_call_parser)qwen3_coder, qwen3_xmlChosen by the image at start
huihui-qwen3-5-4b-abliteratedReasoning format (reasoning_parser)qwen3qwen3
huihui-qwen3-5-9b-abliteratedContext length (max_model_len)1024 to 2621448192
huihui-qwen3-5-9b-abliteratedGPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
huihui-qwen3-5-9b-abliteratedConcurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
huihui-qwen3-5-9b-abliteratedPrefix caching (enable_prefix_caching)On or offOn
huihui-qwen3-5-9b-abliteratedTool call format (tool_call_parser)qwen3_coder, qwen3_xmlChosen by the image at start
huihui-qwen3-5-9b-abliteratedReasoning format (reasoning_parser)qwen3qwen3
huihui-gemma-4-12b-abliteratedContext length (max_model_len)1024 to 1310728192
huihui-gemma-4-12b-abliteratedGPU memory share (gpu_memory_utilization)0.80, 0.85, 0.90, 0.950.90
huihui-gemma-4-12b-abliteratedConcurrent requests (max_num_seqs)1 to 1024Chosen by the image at start
huihui-gemma-4-12b-abliteratedPrefix caching (enable_prefix_caching)On or offOn

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

Shell
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.

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

Errors
CodeMeaning
env_reservedA variable name is reserved: LEGION_*, or one the runtime sets.
invalid_envA variable name or value breaks the rules: a bad name, a duplicate, too many variables, or a value too large.
invalid_model_settingA key the model doesn't support, or a value outside its bounds. The answer names the key.
invalid_commandThe command or arguments are too long, or have too many items.
override_not_allowedA command or arguments on a premade image or model.
host_unsupportedThe host's Legion software is too old to pass the configuration to a container. Choose another host.
model_settings_do_not_fitWith 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_unavailableLegion can't work out what these settings need for this model right now. Try again, or leave the settings at their defaults.