# Read a rental's logs

> GET /v1/rentals/{rental_id}/logs. .

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

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

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

. The rental's logs: what its container writes and what Legion did with it. Lines come oldest first. `source` picks the streams (repeat it for several; all by default),
`level` is a minimum, `q` is searched as one plain-text phrase in the message (never a query
language). `start` and `end` bound the time range (default: the last hour; a range may span at
most 14 days, the time logs are kept). Without `cursor` or `after` a page holds the newest
`limit` lines of the range; `next_cursor` pages back to older ones. For a live tail, poll with
`after` set to the last page's `tail_cursor`: each answer holds the lines strictly newer, oldest
first, and a new `tail_cursor`.

What is logged: the container's standard output and error as the host's agent reads them from
the container engine, for a Legion model image also the model server's log (`model_server`) and
Legion's download and start log (`legion_serve`), and Legion's own events about the rental
(`legion`, as the host's agent reports them: image pulled, container started, health check
passed, stopped, failed with the reason). Lines longer than 4096 bytes are cut (`truncated`). Each rental may send 50 lines and
8 KiB a second, with bursts of a minute's worth; a `legion` line says how many were not kept. The values of the rental's environment variables (secrets included) and of the variables Legion
sets are replaced by `[redacted]` before a line leaves the host, when they are 8 characters or
longer (exact values: a value the workload encodes or prints in parts is not recognized). Lines Legion adds never name the host or its addresses. Logs are kept 14 days.

Isolation: the organization's own rentals only, checked before the log store is asked; the
provider of the host never reads a renter's logs through Legion. `available` is false when the
host's agent cannot send logs yet (the page is then empty). A log store that is not configured
answers 503 `logs_unavailable`, one that fails or does not answer within 10 seconds 502
`logs_upstream_error`. At most 300 log reads a minute per organization (`429` `rate_limited`
with `Retry-After`). Needs `logs.read`; another organization's rental is `404`.

## Path parameters

- `rental_id`, string (uuid), required

## Query parameters

- `start`, string (date-time): The range's start (RFC 3339). Default `end` minus one hour; at most 14 days before `end`.
- `end`, string (date-time): The range's end (RFC 3339). Default now.
- `source`, array of RentalLogSource: The streams to read; repeat for several. Default all.
- `level`, LogLevel: The lowest level to return.
- `q`, string: Plain text searched, as one phrase, in the message. Not a query language.
- `limit`, integer
- `cursor`, string: A page's `next_cursor`, to read the lines before it. Not with `after`.
- `after`, string: A page's `tail_cursor`, to read only the lines strictly newer (the live tail). Not with `cursor`; `start` and `end` are then ignored.

## Responses

### 200

The log lines, oldest first.

- `lines`, array of RentalLogLine, required: Oldest first.
  - `id`, string, required: Stable for the line: the same line read twice has the same id.
  - `time`, string (date-time), required: When the line was written, with nanoseconds.
  - `source`, RentalLogSource, required: . Where a line came from. `stdout` and `stderr`: the container's output. `model_server`: the model server of a Legion model image (vLLM, ComfyUI). `legion_serve`: Legion's download and start of the model in such an image. `legion`: Legion's events about the rental as the host's agent reports them, never written by the container.
  - `level`, LogLevel, required: A severity, folded to four. As a query it is the lowest to return; on a line, an unrecognized or missing severity is `info`.
  - `message`, string, required
  - `rental_id`, string (uuid), required: The rental (a service's replica) the line belongs to.
  - `truncated`, boolean, required: The line was longer than 4096 bytes and was cut.
- `next_cursor`, string, required: Pass as `cursor` to read older lines of the range; null when there are none.
- `tail_cursor`, string, required: Pass as `after` to read the lines newer than this page (the live tail).
- `available`, boolean, required: False when no host of these rentals has an agent that sends logs yet; the page is then empty.
- `retention_days`, integer, required: How long lines are kept: 14 days.

Example:

```json
{
  "lines": [
    {
      "id": "string",
      "time": "2026-10-15T12:00:00Z",
      "source": "stdout",
      "level": "info",
      "message": "string",
      "rental_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
      "truncated": false
    }
  ],
  "next_cursor": "string",
  "tail_cursor": "string",
  "available": false,
  "retention_days": 0
}
```

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

### 429

Rate limited (`code` is `rate_limited`), or the organization asked the
pull-through mirror to copy in too many different tags or digests of one
repository today (`mirror_quota_exceeded`). Retry after the `Retry-After`
seconds.

### 500

An unexpected server error. Safe to retry.

### 502

The log store failed or did not answer within 10 seconds (`logs_upstream_error`). Retry with backoff.

### 503

Legion has no log store configured (`logs_unavailable`).

## Errors

- 400 [`invalid_logs_query`](https://legion.ambient.xyz/docs/errors#invalid_logs_query)
- 400 [`invalid_cursor`](https://legion.ambient.xyz/docs/errors#invalid_cursor)
- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)
- 502 [`logs_upstream_error`](https://legion.ambient.xyz/docs/errors#logs_upstream_error)
- 503 [`logs_unavailable`](https://legion.ambient.xyz/docs/errors#logs_unavailable)

## Example request

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