# How to reach the model a rental serves

> GET /v1/rentals/{rental_id}/serve. For a rental created with serve: the service Legion exposed for it, the API key the container checks (LEGION_API_KEY) and whether the service is ready.

Source: https://legion.ambient.xyz/docs/api/rentals/get-rental-serve

`GET https://api.legion.ambient.xyz/v1/rentals/{rental_id}/serve`

Authenticate with an API key: `Authorization: Bearer $LEGION_API_KEY`.

For a rental created with `serve`: the service Legion exposed for it, the API key
the container checks (`LEGION_API_KEY`) and whether the service is ready. The key is secret: the answer
carries `Cache-Control: no-store`. `status`: `starting` (the rental is not up yet, or its service is
being set up), `loading` (the service is live but the model server does not answer yet: the model is still
downloading or loading), `ready`, `unavailable` (no service can be exposed; `status_reason` says why, for example
`service_unavailable`, `service_limit` or `rule_deleted`; `POST.../serve/expose` tries again) or
`error`. Once the host's agent reports the service's readiness (`readiness`), `ready` needs a
`ready` phase: a live service whose container is still pulling, starting, downloading or loading is
`loading`, and one whose container failed is `error` with `service_error`. A rental created without
`serve` is `404` `serve_not_configured`. A replica of a service is 409 `rental_managed_by_service`: its key
opens nothing and callers use the service's URL and keys. Needs `rentals.manage`; another organization's rental is `404`.

## Path parameters

- `rental_id`, string (uuid), required

## Responses

### 200

The rental's serve configuration and status.

- `kind`, RentalServeKind, required: What the service speaks. `openai`, an OpenAI-compatible API; `comfyui`, ComfyUI; `http`, any other HTTP service.
- `model`, string, required
- `catalog_id`, string
- `port`, integer, required
- `api_key`, string, required: The key the service checks, `lsk_` and 43 URL-safe characters. Secret.
- `url`, string, required: The public address (`https://<hostname>`) once the service rule exists; null before.
- `ingress_rule_id`, string (uuid), required: The exposed-port rule behind `url`; null while there is none.
- `status`, RentalServeStatus, required
- `status_reason`, string, required: Why the status is not `ready`, when there is a reason: `service_unavailable`, `service_limit`, `rule_deleted`, `rental_failed`, `rental_<state>` for a rental that is not up, `service_error` (the service reported a failure, see `readiness` and `failure`), or the exposed-port rule's own error (`listen_failed`, `mesh_rejected`, `other`).
- `readiness`, RentalServeReadiness: How far the rental's model service has come, as the host's agent last reported it. Absent until an agent that reports it (`serve_status_v1`) has, and while the rental is not `starting` or `running`. A report older than 120 seconds is not shown.
  - `phase`, ServePhase, required: How far the model service of a rental created with `serve` has come. `pulling`: the host is pulling the rental's image. `starting`: the container is being created or started, or runs and the service has said nothing yet. `downloading`: the service is downloading the model's weights (a Legion model image on its first start). `loading`: it is loading the model, or its port does not accept connections yet. `ready`: the service says it is ready and its port accepts connections. `error`: the service says it failed, or the container failed.
  - `progress`, number (double): With `pulling`, the share of the image the host has; with `downloading`, the share of the weights. Absent when not known.
  - `since`, string (date-time), required: When Legion first saw this phase.
  - `reported_at`, string (date-time), required: When the agent last reported it.
- `failure`, ServeFailure: . Why the rental's model service last failed, as the host's agent reported it (`serve_failure_v1`). Kept after the rental stops or is deleted, and cleared once the service is ready again. Absent when no failure was reported (an older agent sends none).
  - `reason`, string, required: A short code: `gpu_memory_insufficient` (the GPU did not have the memory the model needs, for example because something outside Legion uses it), `disk_full`, `download_failed`, `invalid_setting`, `server_exited`, `container_failed`, or another code a newer agent sends. Show `message` for a code you do not know.
  - `message`, string, required: One sentence in plain words, for example `The model needs 21.6 GiB of GPU memory; 5.2 GiB is free.`; may be empty.
  - `reported_at`, string (date-time), required: When the agent first reported this failure.
- `service_id`, string (uuid): The rental's service: its URL and keys.
- `legacy_direct`, boolean: True while the rental still has its direct address with `api_key` open to anyone who has it (a serve rental from before services, decision 23); switching the service's access to keys ends it.

Example:

```json
{
  "kind": "openai",
  "model": "string",
  "catalog_id": "string",
  "port": 0,
  "api_key": "string",
  "url": "string",
  "ingress_rule_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "status": "starting",
  "status_reason": "string",
  "readiness": {
    "phase": "pulling",
    "progress": 0,
    "since": "2026-10-15T12:00:00Z",
    "reported_at": "2026-10-15T12:00:00Z"
  },
  "failure": {
    "reason": "string",
    "message": "string",
    "reported_at": "2026-10-15T12:00:00Z"
  },
  "service_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "legacy_direct": false
}
```

### 400

The request is malformed or fails validation. An image reference that
is not a container image reference answers `invalid_image_reference`.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission this operation requires (`forbidden`),
or signed in without having joined an organization yet
(`no_organization`; `getOnboarding` and the invitation and
organization operations under it work), or could not sign in
(`email_unverified`, `account_conflict`, and `domain_not_allowed`). `not_invited` is no longer returned to
session tokens.

`access_not_approved`: a signed-in person who is not approved
for the beta yet. Every operation that takes a credential answers it to
them, except `getMe` and `joinMyWaitlist`; the problem carries
`access` (`waitlisted` or `not_requested`, and the email). Approved
means a member of an organization, holding a pending invitation, or Legion; an API key always belongs to a member.

`oauth_token_mcp_only`: the caller sent an OAuth access token (`lgo_`), which is accepted
only by `mcpMessage` and the tool calls it dispatches. Every other operation answers it, whatever
the token's scope. Use an API key or the Legion web app.

`org_suspended`: the caller's organization is suspended. Every operation that takes a
credential answers it, by session or API key, except `getMe` (which shows `org.suspended_at` and
`org.suspension_reason`) and the support operations under `/v1/support/`.

`terms_not_accepted`: an approved caller who has not accepted
the current version of the Terms of Use and the Acceptable Use Policy. Every operation that takes a credential answers it, except `getMe`,
`acceptLegalDocuments`, `joinMyWaitlist` and the wind-down operations
(`listRentals`, `stopRental`, `deleteRental`, `listHosts`,
`updateListing` with `listed` false, `removeHost`); the problem
carries `legal`. An API key acts for the person who created it, so it
is refused until that person accepts. Terminal
operations also return
`session_required` (called with an API key) and `step_up_required`
(neither a sign-in nor a step-up challenge within the step-up window).

### 404

The resource does not exist or belongs to another organization.

### 409

The resource's current state does not allow the operation. `legal_versions_stale`: a legal document version sent is not the current one; the
problem's `legal` holds the current documents.

### 500

An unexpected server error. Safe to retry.

## Errors

- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 404 [`serve_not_configured`](https://legion.ambient.xyz/docs/errors#serve_not_configured)
- 409 [`rental_managed_by_service`](https://legion.ambient.xyz/docs/errors#rental_managed_by_service)

## Example request

```sh
curl -s "https://api.legion.ambient.xyz/v1/rentals/$RENTAL_ID/serve" \
  -H "Authorization: Bearer $LEGION_API_KEY"
```
