Keys and security
How access to a service works: public or keys, keys shown once, expiry, rotation, revocation, who may do what, what a provider host can see, and own hosts compared with eligible hosts.
After this page you know how access to a service works, how to hand out and take back keys, and exactly what a provider's machine can and cannot see.
Access
Every service has an access setting, and you can change it at any time without changing the address:
API key required. Callers send a service key as
Authorization: Bearer lek_. Legion checks it and passes the request on without it, so your app never sees the key. A request without a valid key gets. . . 401.Public. Anyone who has the address can call it, and no key is needed. Your app has to do its own sign-in if it needs one. Any service can be public, an autoscaled one too. Making an autoscaled service public needs your confirmation and shows a warning: anyone with the address can drive it to scale up, bounded by its maximum replicas and its monthly spend cap. Public services are rate limited per caller address, in place of per-key limits.
Only these addresses (optional, with either choice). A list of IPv4 or IPv6 ranges. Requests from anywhere else are refused.
You can create, rotate and revoke keys while a service is public, so you can prepare keys and then switch to API key required with no downtime. Switch in the service's Settings, in the Access panel, or with legion services update chat --access keys.
Service keys
One key system serves every service, whatever its mode, with one list, one set of API calls, one set of CLI commands and one panel in the app.
Format.
lek_followed by 43 characters. They are random, 256 bits.One service only. A key works for the service it was made for. Used on another service, or on the Legion API, it is refused.
Shown once. The key's secret appears when you create it, in a dialog that stays until you confirm you saved it. Legion keeps only a fingerprint (a SHA-256 hash) of the key, so a lost key can't be recovered, only replaced. The list shows the first 12 characters,
lek_and 8 more, and the last use of each key.At most 10 active keys per service, so you can give each client its own.
Not a Legion API key. A service key can't call the Legion API, and a Legion API key can't call a service.
Send it as Authorization: Bearer lek_. See Call a service.
Create a key
On the service's Keys tab, choose Create key:
Name, up to 64 characters.
Expires: in 7 days, 30 days, 90 days (the default), 1 year, or never. A key that never expires shows a warning, because a leaked key then works forever.
Requests per minute limit (optional): stops a runaway client from spending your cap.
From a terminal, legion services keys create chat --name ci --expires 30d (--expires takes 7d, 30d, 90d, 365d or never; -o name prints only the secret). With the API, createServiceKey (POST /) takes an Idempotency-Key and answers 201 with the key and its secret, with Cache-Control: no-store. Organizations can make 60 keys an hour.
curl -X POST https://api.legion.ambient.xyz/v1/services/SERVICE_ID/keys \
-H "Authorization: Bearer $LEGION_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"name": "ci", "expires_in_days": 30}'An expired key answers 401 like an unknown one. Expiry is checked on every request.
Rotate a key
Rotation swaps a key without downtime: Legion creates a new key and lets the old one expire after an overlap, 24 hours by default and anywhere from 0 (at once) to 168 hours (7 days). Roll your clients over to the new key during the overlap, and the old one stops by itself. The CLI is legion services keys rotate chat ci --overlap-hours 12. The rotation is one action, rotateServiceKey, and one entry in the service's activity naming both keys.
Revoke a key
Revoke ends a key now and can't be undone. Callers that use it get 401 within seconds, at most 30. Revoking never asks you to sign in again, so you can cut off access fast during an incident. If it is the last active key, nobody can call the service until you create another. From a terminal, legion services keys revoke chat ci. Revoked keys stay in the list, under Show revoked, for your records.
If a key leaks, revoke it first, then create its replacement.
Direct key (legacy)
A served rental made before services existed keeps its direct address and its key, and both keep working. The service's Keys tab lists that key as Direct key (legacy). Revoke on that row closes direct access: the address stops answering, and the service's own URL with lek_ keys keeps working. New served rentals have no direct address.
Who can do what
| Action | Owner | Member | Needs a fresh sign-in |
|---|---|---|---|
| See services, masked keys and usage | Yes | Yes | No |
| Create a service | Yes | Yes | No |
| Change scaling, price ceiling or cap | Yes | Yes | No |
| Create or rotate a key | Yes | Yes | Yes, in the app |
| Revoke a key | Yes | Yes | No |
| Delete an autoscaled service | Yes | Only one they created | Yes |
| Delete a service on a rental | Yes | Yes | No |
A fresh sign-in (step-up) means you sign in again, within 10 minutes of the change, to confirm it's you. The app asks, keeps what you typed and brings you back. A call that needs it without one answers 403 step_. Deleting an autoscaled service is possible only in the app, on a signed-in session.
API keys and agents: a full-access API key skips the sign-in, because no person is there to do it, but it can't delete autoscaled services. An Agent key, and an app connected by signing in (such as Claude), can only read services: any change answers 403 api_. Changes through the MCP tools need a Full access API key, and each of those tools asks first. See Service tools.
Keys never reach a host
Your key is checked by Legion's router and goes no further. The router removes it before it forwards the request, so the machine running your model never gets it. Each replica has its own secret, made for that replica, that the router uses to reach it. A new replica gets a new secret, and a stopped replica's secret stops working. The replica also doesn't see who called: Legion adds a request ID and removes the caller's address and headers.
Replicas can't be reached from the internet at all. The only way in is through the router, which checks a key first.
Request and response bodies, query strings and the Authorization header are never written to Legion's logs. Legion logs when a request came, which service and key, the status, the size and how long it took, and keeps the caller's address for 30 days.
Web terminal on replicas
An autoscaled service can let people open Legion's web terminal on its replicas, to look inside one while it serves. It is off by default. Turn it on in Advanced when you create the service, or later on the service's Settings tab under Web terminal on replicas. With the API, send replica_ (enabled, access) to createService or updateService.
On or off applies to new replicas. A replica keeps the web terminal it was started with until it is replaced, so turning it on reaches the replicas Legion starts after the change.
Who can open it applies at once, to every running and warm replica: everyone in the organization who can manage rentals, or only the person who created the service and the organization's owners. Only that person or an owner can change who (
403 terminal_).access_ forbidden Nothing you change inside a replica lasts. Files, installed packages and settings are lost when the replica is replaced or scaled down. Put what you need in the image or the service's configuration.
Neither change restarts a replica. A replica's rental page says the setting is the service's and links to it, and every terminal opened is recorded there.
What a host can see
Replicas run in containers on machines that Legion's providers own. The provider has full control of the machine. A host can therefore:
read the model's weights, your image, and every request and response the replica handles, including your prompts and the answers;
change the answers it gives.
Legion does not use confidential computing, so there is no encryption that hides requests from the host that runs them. Don't say otherwise to your users. The first time your organization creates a service, you confirm that you understand this.
What this means in practice:
Premade models have public weights, so a host learns nothing about the model, only your traffic.
Your own image is visible to the host, so don't put secrets in it.
Don't send data through a service that you would not hand to the operator of the machine. For private data, use only your own hosts.
Legion limits what one provider can do: it never puts more than half of a service's replicas on one provider once there are four or more, it stops using a replica whose requests mostly fail, and it skips a host that failed one of your replicas for 24 hours.
Replicas have no SSH, no terminal and no exec, so a member of your team can't read secrets from one interactively.
Own hosts and eligible hosts
Placement says which hosts may run your replicas. You choose it when you create the service.
Eligible hosts (the default). Any host that passes Legion's service checks: it is approved and not quarantined, its agent supports the service features, user namespace isolation is on, its fingerprint isn't flagged as a duplicate, its provider isn't flagged by Legion's risk checks, and its Legion score meets the model's minimum. Most renters own no hosts, so this is the default. The host-visibility notice above applies.
Own hosts. Only machines your organization owns. The provider is you, so nobody else can see the traffic. It needs hosts of your own that can run the model, and you pay Legion's fee for using your own host.
You can change placement later with legion services update chat --placement own_. Replicas are then replaced one at a time, as for any hardware change.
Safe defaults
Every new service starts with the cautious choice, and each is visible in the form:
A key that expires in 90 days.
A monthly spend cap you must set, with alerts at 50, 80 and 100 percent. See Service billing.
A maximum of 2 replicas and a price ceiling per replica.
A key is always required: there are no public services. The URL isn't guessable, but having it is not enough.
No CORS: Legion's services send no cross-origin permissions, because a browser that can call a service would hold its key. Call services from your server.
Legion can email you and show a banner for a spend alert, a service that has run at its maximum for 30 minutes, a key used from a new country, or a burst of refused requests.
Abuse is covered by the Acceptable Use Policy. Legion can take a service down, in which case callers get 403 service_ and its replicas stop.