Service limits and status codes
The limits that apply to services and every status and code a caller or a client of the service API can get, with what to do about it.
Errors from a service come as application/ with a stable code and a request_. Branch on code, not on the text. Quote the request_ when you contact support.
Limits
| Limit | Value |
|---|---|
| Autoscaled services per organization | 10 (services on a rental follow rentals) |
| Active keys per service | 10 |
| Replicas per service | 10, and 20 across the organization (ask support to raise them) |
| Services created | 20 an hour for an organization |
| Keys created | 60 an hour for an organization |
| Request body | 10 MiB |
| Request headers | 32 KiB |
| Requests waiting when every replica is busy | 64 per service, for at most 30 seconds |
X-Legion-Wait | At most 300 seconds |
| Request timeout | 600 seconds by default, at most 3600 |
| Silence while streaming | A connection that sends nothing for 60 seconds is closed |
| Failed key checks | 20 a minute from one address, then 5 minutes of 429 |
| Service kinds | openai and http |
A service's own key can also have a requests-per-minute limit that you set.
What a caller can get
These come from the Service URL.
| Status | Code | What it means | What to do |
|---|---|---|---|
| 401 | unauthorized | The key is missing, unknown, expired, revoked, or for another service. The answer is the same for all of them. | Check the key and the URL. Create a new key if it expired or was revoked. |
| 402 | spend_ | This month's spend reached the cap. | The owner raises the cap or waits for the next month (UTC). Don't retry in a loop. |
| 402 | insufficient_ | The organization is out of credit. | An owner adds credit. |
| 403 | service_ | Legion took the service down. | Contact support. |
| 403 | org_ | The organization is suspended. | Contact support. |
| 404 | service_ | No service has this name, or the URL is not a service. | Check the URL. |
| 413 | request_ | The request body is over 10 MiB. | Send less. |
| 429 | rate_ | The key went over its requests-per-minute limit, or too many wrong keys came from one address. Retry-After says when. | Wait that long, then retry with a growing delay. |
| 503 | service_ | No replica is ready yet. One is starting. Retry-After is the usual start time. | Retry after it, or send X-Legion-Wait to be held until one is ready. See Call a service. |
| 503 | service_ | Every replica is at its limit and the queue is full or the wait ended. Retry-After is 5 seconds. | Retry with a growing delay. If it is common, raise the maximum replicas. |
| 503 | service_ | The service is paused. | Resume it. |
| 503 | router_ | Legion's router can't read its settings right now. | Retry after a moment. |
Requests the router refuses to forward (a path with ., an absolute-form target or TRACE) are 400, and a path outside / on an openai service is refused. Anything else comes from your model: its status and body pass through unchanged, and a 3xx is never followed. A request that runs past the request timeout is ended.
When a replica fails before it answers, Legion retries the request once on another replica. It never retries after the first byte of the response.
What the service API can answer
These come from the Legion API (/), for the app, the CLI, agents and your own code.
| Status | Code | What it means | What to do |
|---|---|---|---|
| 400 | invalid_ | A field is missing or malformed. | Fix the request. |
| 400 | invalid_ | The serve port, kind or model name is not valid. | Fix it. The kind is openai or http. |
| 400 | service_ | The kind isn't supported yet, for example WebSocket services. | Use openai or http. |
| 400 | invalid_ | A scaling setting breaks a rule: the maximum is below the minimum, warm replicas are above the minimum, or a value is out of range. | Fix the values. |
| 400 | invalid_ | The hardware settings are not valid: for example a GPU count the model can't use, or no memory for your own image. | Fix them. |
| 400 | image_, registry_ | Your own image is private, or the registry sign-in for it was refused. | Fix the registry sign-in in the app. |
| 400 | invalid_ | An allowed address range isn't valid, or is private or reserved. | Fix the list (up to 16 CIDR ranges). |
| 400 | invalid_ | The name isn't lower case letters, numbers and hyphens, 3 to 40 characters starting with a letter, or it is reserved. | Choose another. |
| 400 | invalid_ | The cap is missing, zero or not valid. | Set a positive amount. |
| 400 | host_ | The first service of an organization needs acknowledge_. | Read What a host can see, then send it. |
| 402 | insufficient_ | Creating a service that keeps replicas running needs credit. | An owner adds credit. |
| 403 | service_ | Exposing a port is switched off for your organization, or paused by Legion. | An organization owner can switch it back on in the app, or contact support. |
| 403 | custom_ | Your organization can't use its own images. | Choose a premade model. |
| 403 | step_ | The change needs a fresh sign-in: a key with no expiry, a new or rotated key in the app, or deleting a service. | Sign in again and retry. |
| 403 | api_ | The key can't use this operation. | Use a key with the right scope. |
| 404 | not_ | The service, key or replica doesn't exist, or belongs to another organization. | Check the id. |
| 409 | service_ | Another service of yours has this name. | To change that service's model, hardware or price ceiling, use its Settings tab instead: it keeps its name and URL. Or delete it first: once it is deleted, the name is free. Or choose another name. |
| 409 | rule_ | That port of the rental is already exposed. | Use the service that exists. |
| 409 | too_ | The rental or the organization is at its limit of exposed ports. | Delete one you don't need. |
| 409 | rental_ | The rental must be starting or running to expose a port. | Wait for it, or start it. |
| 409 | rental_ | The rental has no name to build an address from. | Choose a name for the service. |
| 409 | host_ | The rental's host can't expose ports yet. | Rent on another host. |
| 409 | too_ | The organization has 10 services. | Delete one you don't use. |
| 409 | too_ | The service has 10 active keys. | Revoke one. |
| 409 | no_ | No hardware that fits the model is available at your price ceiling right now. | Raise the price ceiling, remove GPU models from your allow-list, or set an offer alert. |
| 409 | catalog_ | The GPUs can't run the model. | Choose at least the GPUs the model needs. |
| 409 | replica_ | The maximum replicas is over your organization's limit (10 per service, 20 in all). | Lower it, or ask support to raise the limit. |
| 409 | service_ | The call needs autoscaling on, for example resume or scaling settings on a service on a rental. | Turn autoscaling on first. |
| 409 | invalid_ | The switch between one rental and autoscaling isn't possible as asked. | Choose the strategy or the replica to keep, and retry. |
| 409 | service_ | The service is being deleted. | Nothing to do. |
| 409 | service_ | The service is at its monthly cap and can't resume. | Raise the cap first. |
| 409 | service_ | Legion took the service down. | Contact support. |
| 409 | revision_ | Someone changed the service after you read it. | Read it again and retry. |
| 409 | key_ | The key to rotate is already revoked. | Create a new key. |
| 409 | rental_ | You tried to stop, start, delete or expose a replica of an autoscaled service. | Change the service's scaling instead. |
| 422 | idempotency_ | The Idempotency-Key was used for a different request. | Use a new key for a new action, and the same one only to retry the same request. |
| 429 | rate_ | Too many creates in the last hour. Retry-After says when. | Wait. |
Every other code of the Legion API is in Errors.