# A service's metrics and cost

> GET /v1/services/{service_id}/usage. Request metrics over window (1h in minute points, the default; 24h in 5-minute points; 7d hourly): requests, status classes, rejections, time to first…

Source: https://legion.ambient.xyz/docs/api/services/get-service-usage

`GET https://api.legion.ambient.xyz/v1/services/{service_id}/usage`

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

Request metrics over `window` (`1h` in minute points, the default; `24h` in 5-minute points; `7d` hourly):
requests, status classes, rejections, time to first byte p50 and p95, load. And per UTC day over the last
`days` (default 30, at most 90): replica time, GPU time and its cost (the cap's estimate at the replicas'
all-in prices), requests and errors; plus this month's spend against the cap. Needs `services.read`.

## Path parameters

- `service_id`, string (uuid), required

## Query parameters

- `window`, ServiceMetricsWindow
- `days`, integer

## Responses

### 200

The usage.

- `window`, ServiceMetricsWindow, required
- `step_seconds`, integer, required
- `points`, array of ServiceMetricsPoint, required: Request metrics over `window`.
  - `at`, string (date-time), required
  - `requests`, integer, required
  - `status_2xx`, integer, required
  - `status_4xx`, integer, required
  - `status_5xx`, integer, required
  - `rejected`, integer, required: Answered by the router itself: 429, 503 busy or starting.
  - `ttfb_p50_ms`, integer, required
  - `ttfb_p95_ms`, integer, required
  - `max_in_flight`, integer, required
  - `max_queued`, integer, required
  - `ready_replicas`, integer, required
- `days`, array of ServiceUsageDay, required: Cost and replica time per UTC day over `days`, oldest first.
  - `date`, string (date), required
  - `replica_seconds`, integer (int64), required: Replica running time that day, loading included.
  - `gpu_seconds`, integer (int64), required
  - `cost`, Money, required: GPU time at the replicas' all-in prices (the cap's estimate); billing is the authority.
  - `requests`, integer (int64), required
  - `errors`, integer (int64), required: 5xx answers plus requests the router refused (429, 503).
- `spend_this_month`, ServiceSpend, required
  - `month`, string, required: The UTC month, YYYY-MM.
  - `estimated`, Money, required: GPU time of the replicas this month at their all-in prices, the figure the cap is enforced on.
  - `cap`, Money, required: The monthly spend cap; null on a service in mode `rental` without one.
  - `alerted_pct`, integer, required: The highest cap alert sent this month. Alerts go to owners and the creator at the fixed thresholds 50, 80 and 100 percent.

Example:

```json
{
  "window": "1h",
  "step_seconds": 0,
  "points": [
    {
      "at": "2026-10-15T12:00:00Z",
      "requests": 0,
      "status_2xx": 0,
      "status_4xx": 0,
      "status_5xx": 0,
      "rejected": 0,
      "ttfb_p50_ms": 0,
      "ttfb_p95_ms": 0,
      "max_in_flight": 0,
      "max_queued": 0,
      "ready_replicas": 0
    }
  ],
  "days": [
    {
      "date": "2026-10-15",
      "replica_seconds": 0,
      "gpu_seconds": 0,
      "cost": {
        "amount_minor": 250,
        "currency": "USD"
      },
      "requests": 0,
      "errors": 0
    }
  ],
  "spend_this_month": {
    "month": "2026-11",
    "estimated": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "cap": {
      "amount_minor": 250,
      "currency": "USD"
    },
    "alerted_pct": 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.

### 500

An unexpected server error. Safe to retry.

## Errors

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

## Example request

```sh
curl -s "https://api.legion.ambient.xyz/v1/services/$SERVICE_ID/usage" \
  -H "Authorization: Bearer $LEGION_API_KEY"
```
