Create a service
Create an autoscaled service in five steps in the app, with the legion CLI, with the API or from an agent over MCP, and what you have after it is created.
After this page you have a service with a Service URL and one key, and you know how to create one in the app, from a terminal, with the API and from an agent.
This page creates an autoscaled service. To put a service on a port of a rental, see Expose a port. To serve a model from one rental, rent a premade model: it gets a service with one key, and you can turn autoscaling on later.
You need the permission to manage services (services.: organization owners and members have it) and credit in your organization. Creating a service with at least one always-on replica needs credit at once, and a service that scales to zero starts spending when its first request arrives.
Create it in the app
Open Rent, then Services, then New service. The first choice is where it runs: On a rental ("Use a port on a machine you already rent") takes the short path in Expose a port, and Autoscaled ("Legion runs it and scales with traffic") takes the five steps below.
While you go through the five steps, an estimate of the cost stays on the right (at the bottom on a phone) and updates as you choose. Your answers survive a reload.
1. Model
Choose what to serve.
Legion models lists the premade models. Each shows the GPUs it needs at least and what it can do.
My own image appears only when your organization may use its own images. Give the image, the port it serves on, the kind (
openaiorhttp) and the model name. Then say what it needs, because Legion can't know: the minimum total GPU memory per replica and the GPU counts it can use (1, 2, 4 and 8 by default). The Hardware step stays blocked until you have set them. A private image needs a registry credential saved first: see Private images. Your image runs on rented hosts, so don't put secrets in it.
Under Advanced you can add environment variables and secrets, change a model's settings, and, for your own image, set the command and arguments. See Configuration. Changing them later rolls the replicas.
Then pick the Service name. Use lower case letters, numbers and hyphens. The name must be unique within your organization, so two organizations can use the same name. Legion adds a short random ending to make the Service URL: the service will be at https:/, for example https:/. The ending keeps URLs from being guessable, never changes, and is shown on the service and in the create response.
2. Hardware
You don't have to choose GPUs. By default Legion picks the cheapest hardware that fits: for each replica it looks at every eligible offer and every GPU count the model can use, keeps the ones that can run it, and rents the cheapest in total. All you set are limits.
Never pay more than (optional). The most one replica may cost per hour, fees included. This is a price for the whole replica, not per GPU. Legion won't start a replica above it. For spot, it is also your bid.
GPUs. Choose Any GPU that fits (recommended, and the default) or Only these GPUs. The second shows a list of only the GPUs that fit the model, each with its count per replica, GPU memory, price per hour and the number of hosts offering it. Tick the ones you accept. The list has no order: price decides.
Spot or on-demand. Spot is cheaper: a host can reclaim the GPU, and Legion starts a replacement. On-demand costs more: the GPU is yours until the replica stops. See Interruptible rentals for how the spot price works.
Placement. Under Advanced placement, choose eligible hosts (the default: any host that passes Legion's checks) or only my own hosts. See Own hosts and eligible hosts.
Your own image. The requirements you gave in the Model step decide which GPUs fit and appear here. Premade models state their own.
The step shows the likely hardware: the cheapest fit right now, its price per hour, the range of prices a replica could cost and how many hosts can run it, for example "1 x RTX 4090 at 0.42 an hour, 14 hosts available". It is a current price, not a promise: see How Legion chooses hardware. When no host fits, it says so and offers an alert: see Offer alerts.
3. Scaling and budget
Set how far the service scales and what it may spend. Every field has a default, and Scaling and cold starts explains each one.
Minimum and maximum replicas, always-on replicas, target requests per replica and idle timeout.
Monthly spend cap. Required. The form suggests one. When this month's spend reaches it, the service pauses. See Service billing.
Email owners at. The share of the cap, 50, 80 or 100 percent, at which Legion emails the owners.
4. Access
Choose API key required (the default) or Public, and optionally Only these addresses. See Access. With an API key required, the service is created with its first key, so the URL is never open. Choosing Public for an autoscaled service shows a warning, and you confirm it: anyone with the URL can drive scale-up, up to your maximum replicas and your cap.
Key name.
Expires: in 7 days, 30 days, 90 days (the default), 1 year, or never. A key that never expires shows a warning and needs you to sign in again to confirm.
Requests per minute limit (optional). It stops a runaway client from spending your cap.
With an API key required, callers need the key. Without it, requests are refused.
5. Review and create
Review the recap and choose Create service. The first time your organization creates a service, you also tick I understand that hosts can see this traffic. The text says: your replicas run on GPUs owned by Legion providers, and the host machine can see the model, the requests and the responses it handles. For your own image it adds that the host can see the image too.
Billing starts when the first replica starts, by the second, only while replicas run. With the minimum at 0 that is when the first request arrives.
After you create it
The service opens with its status Starting and a dialog titled Copy your key now. This is the only time the key is shown. Legion keeps only a fingerprint of it, so a lost key can't be recovered, only replaced. Copy it, save it somewhere safe, tick the box and choose Done. If you reload before that, the key is gone: create another from the Keys tab and revoke the lost one.
The first replica needs a host, a model download and a start. The Overview shows the status and how long this usually takes. The Service URL answers once a replica is ready. Until then, calls get a 503 service_: see Call a service.
Create it from a terminal
The legion CLI has one command group for services, legion services, shortened to legion svc. It shows the cost before it creates anything:
legion services create support-chat \
--catalog CATALOG_ID \
--max-price 2.50 \
--monthly-cap 400 \
--ack-host-visibility--max-price is an optional all-in price ceiling for one whole replica per hour (all its GPUs), and --monthly-cap is required, both in dollars. By default Legion picks the cheapest hardware that fits. To limit it, repeat --gpu with a GPU model (--gpu H100 --gpu L40S); the list is an allow-list and has no order. Anything you leave out is asked for on a terminal, with the platform's default in brackets. Before it creates anything, the command shows the likely hardware, the cost floor, the ceiling and the cap and asks you to confirm, or pass --yes in a script. --ack-host-visibility acknowledges that hosts can see the traffic, once per organization.
Other flags: --spot, --placement own_, --scale-to-zero with --min 0, --min, --max, --target-concurrency, --key-name and --key-expires 7d|30d|90d|365d|never. For your own image use --image IMAGE --port 8000 --kind openai|http --served-model NAME --min-gpu-memory 48 --gpu-counts 1,2. The first key's secret is printed once.
The other commands are in the command reference.
Create it with the API
createService (POST /) takes the same choices as the form. It needs an Idempotency-Key, like createRental, so a retry never creates two services. Amounts are in minor units (cents).
The request has a target, an access, a protocol and, for an autoscaled service, a monthly_:
targetstarts with themode,autoscaledorrental. Withautoscaledit gives the model (catalog_, or your ownid imagewithserve),hardware(strategy: cheapest_,fit max_, optionalprice_ per_ replica_ hour gpu_,models tier,placement, and for your own imagemin_andgpu_ memory_ gb gpu_) andcounts scaling. Withrentalit givesrental_andid port.accessis{ "mode": "public" | "keys", "sources": [.. It defaults to. . ] } keysfor an autoscaled service andpublicfor a service on a rental.sourcesis up to 16 CIDR ranges and works with either mode.protocolisopenaiorhttp.initial_names the first key when access iskey keys, withexpires_(7, 30, 90 or 365) orin_ days no_.expiry acknowledge_must behost_ visibility truethe first time your organization creates an autoscaled service.nameis required for an autoscaled service. For a service on a rental it defaults to the rental's name.
curl -X POST https://api.legion.ambient.xyz/v1/services \
-H "Authorization: Bearer $LEGION_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"name": "support-chat", "target": {"mode": "autoscaled", "catalog_id": "CATALOG_ID"}, "access": {"mode": "keys"}, "monthly_spend_cap": {"amount_minor": 40000, "currency": "USD"}, "initial_key": {"name": "default", "expires_in_days": 90}, "acknowledge_host_visibility": true}'The answer is 201 with the service and, under initial_, the key and its secret, shown once. The response carries Cache-Control: no-store.
Before you create, estimateService (POST /, which takes the same target and monthly_) returns likely_ (the cheapest GPU model and count that fit now, with price_), price_ (min and max), the cost per hour while idle, at the minimum and at the maximum, cap_, a suggested cap, the median cold_ of the model and hosts_. getServiceDefaults (GET /) returns the defaults the platform uses, and the app and the CLI read them from there. When no host fits the model at your price, create answers 409 no_, so you hear it at once, not after waiting.
Setting a key to never expire, or creating or rotating a key on a signed-in session, needs a fresh sign-in (403 step_): see Keys and security.
Changing a service is updateService (PATCH /): scaling, budget, access, and the switch between one rental and autoscaling. Pausing and resuming are their own calls, or paused in the same request.
Create it from an agent
An agent connected over MCP creates a service with create_, in either mode. It spends credit once a replica runs, so it asks first: without confirm: true it returns a preview with the price (the cost per hour while idle, at the minimum and at the maximum, and the cap), and does nothing. The agent passes confirm: true only after your yes. See Service tools.
The service tools that change anything work with a Full access API key. An Agent key, and an app connected by signing in, can only read services and get 403 api_ on a change: create the service in the app instead. A new key's secret comes back to the agent once, in the answer. The agent gives it to you to store, and shouldn't print it again or keep it.
Before you move on
Write the key down where your callers read secrets from, not in code.
Open the Overview and check the cost card matches your plan.
Call the service once: Call a service.