# Tools reference

> Every tool the Legion MCP server offers, what it changes, which ones ask before they act, and how arguments, errors and limits work.

Source: https://legion.ambient.xyz/docs/agents/tools

Each tool runs one operation of the [Legion API](https://legion.ambient.xyz/docs/api/overview) as you, with your permissions in the organization, whether Claude is connected by signing in or the client uses an API key. The tool list is generated from the API's description, so the tools, their summaries and which ones ask first always match it. The **For** column says who a tool is for: **Renting** tools are on every key an agent uses, and **Hosting** tools are for providers (`audience: provider` in the API's description) and are offered only to a key made with provider tools, or a connection approved as **Agent + hosts**. For any other Agent key or connection the server does not list them, and calling one is refused as an unknown tool.

## The tools

| Tool | For | What it does | Effect | Asks you first | Reference |
| --- | --- | --- | --- | --- | --- |
| `estimate_backup` | Renting | What a backup of this rental would cost | Read only | No | [`GET /v1/rentals/{rental_id}/backup-estimate`](https://legion.ambient.xyz/docs/api/rentals/estimate-rental-backup) |
| `estimate_workspace_export` | Renting | What downloading a rental's workspace export will cost | Read only | No | [`GET /v1/rentals/{rental_id}/workspace-exports/estimate`](https://legion.ambient.xyz/docs/api/rentals/estimate-workspace-export) |
| `get_backup` | Renting | Get a backup | Read only | No | [`GET /v1/backups/{backup_id}`](https://legion.ambient.xyz/docs/api/rentals/get-backup) |
| `get_billing_account` | Renting | Get the organization's balance | Read only | No | [`GET /v1/billing/account`](https://legion.ambient.xyz/docs/api/billing/get-billing-account) |
| `get_me` | Renting | Get the caller | Read only | No | [`GET /v1/me`](https://legion.ambient.xyz/docs/api/identity/get-me) |
| `get_offer` | Renting | Get one offer with its score breakdown and uptime history | Read only | No | [`GET /v1/offers/{host_id}`](https://legion.ambient.xyz/docs/api/offers/get-offer) |
| `get_rental` | Renting | Get a rental | Read only | No | [`GET /v1/rentals/{rental_id}`](https://legion.ambient.xyz/docs/api/rentals/get-rental) |
| `get_rental_charges` | Renting | Get what a rental has cost | Read only | No | [`GET /v1/rentals/{rental_id}/charges`](https://legion.ambient.xyz/docs/api/billing/get-rental-charges) |
| `get_rental_host` | Renting | The host a rental runs on, its health and its GPUs' live telemetry | Read only | No | [`GET /v1/rentals/{rental_id}/host`](https://legion.ambient.xyz/docs/api/rentals/get-rental-host) |
| `get_rental_logs` | Renting | Read a rental's logs | Read only | No | [`GET /v1/rentals/{rental_id}/logs`](https://legion.ambient.xyz/docs/api/rentals/get-rental-logs) |
| `get_rental_network` | Renting | The rental's effective network policy and whether its host applied it | Read only | No | [`GET /v1/rentals/{rental_id}/network`](https://legion.ambient.xyz/docs/api/rentals/get-rental-network) |
| `get_service` | Renting | Get a service | Read only | No | [`GET /v1/services/{service_id}`](https://legion.ambient.xyz/docs/api/services/get-service) |
| `get_service_logs` | Renting | Read a service's logs, every replica | Read only | No | [`GET /v1/services/{service_id}/logs`](https://legion.ambient.xyz/docs/api/services/get-service-logs) |
| `get_service_metrics` | Renting | A service's inference metrics | Read only | No | [`GET /v1/services/{service_id}/metrics`](https://legion.ambient.xyz/docs/api/services/get-service-metrics) |
| `get_spend_breakdown` | Renting | The organization's spend by one dimension | Read only | No | [`GET /v1/renter/spend/breakdown`](https://legion.ambient.xyz/docs/api/billing/get-renter-spend-breakdown) |
| `get_spend_overview` | Renting | The organization's spend over a period, with the previous period | Read only | No | [`GET /v1/renter/spend/overview`](https://legion.ambient.xyz/docs/api/billing/get-renter-spend-overview) |
| `get_storage_policy` | Renting | How long a stopped rental's files are kept, and what backups cost | Read only | No | [`GET /v1/storage-policy`](https://legion.ambient.xyz/docs/api/rentals/get-storage-policy) |
| `get_workspace_export` | Renting | Get a workspace export | Read only | No | [`GET /v1/rentals/{rental_id}/workspace-exports/{export_id}`](https://legion.ambient.xyz/docs/api/rentals/get-workspace-export) |
| `inspect_image` | Renting | Inspect a container image before renting it | Read only | No | [`POST /v1/images/inspect`](https://legion.ambient.xyz/docs/api/images/inspect-image) |
| `list_backups` | Renting | The organization's backups, newest first | Read only | No | [`GET /v1/backups`](https://legion.ambient.xyz/docs/api/rentals/list-backups) |
| `list_billing_activity` | Renting | List what happened to the organization's balance or earnings | Read only | No | [`GET /v1/billing/activity`](https://legion.ambient.xyz/docs/api/billing/list-billing-activity) |
| `list_catalog` | Renting | List Legion's starter images and premade models, and which a host can run | Read only | No | [`GET /v1/catalog`](https://legion.ambient.xyz/docs/api/images/list-catalog) |
| `list_offer_alerts` | Renting | List the caller's offer alerts | Read only | No | [`GET /v1/offer-alerts`](https://legion.ambient.xyz/docs/api/offers/list-offer-alerts) |
| `list_offers` | Renting | Search GPU offers | Read only | No | [`GET /v1/offers`](https://legion.ambient.xyz/docs/api/offers/list-offers) |
| `list_registry_credentials` | Renting | The organization's registry credentials | Read only | No | [`GET /v1/registry-credentials`](https://legion.ambient.xyz/docs/api/images/list-registry-credentials) |
| `list_rental_backups` | Renting | A rental's backups, newest first | Read only | No | [`GET /v1/rentals/{rental_id}/backups`](https://legion.ambient.xyz/docs/api/rentals/list-rental-backups) |
| `list_rental_charges` | Renting | List what the organization's rentals have cost | Read only | No | [`GET /v1/billing/charges`](https://legion.ambient.xyz/docs/api/billing/list-rental-charges) |
| `list_rentals` | Renting | List the organization's rentals | Read only | No | [`GET /v1/rentals`](https://legion.ambient.xyz/docs/api/rentals/list-rentals) |
| `list_service_events` | Renting | A service's activity | Read only | No | [`GET /v1/services/{service_id}/events`](https://legion.ambient.xyz/docs/api/services/list-service-events) |
| `list_services` | Renting | List the organization's services | Read only | No | [`GET /v1/services`](https://legion.ambient.xyz/docs/api/services/list-services) |
| `list_spend_by_rental` | Renting | The organization's rentals that were charged in a period | Read only | No | [`GET /v1/renter/spend/rentals`](https://legion.ambient.xyz/docs/api/billing/list-renter-spend-rentals) |
| `list_ssh_keys` | Renting | List the caller's saved SSH public keys | Read only | No | [`GET /v1/ssh-keys`](https://legion.ambient.xyz/docs/api/identity/list-ssh-keys) |
| `add_registry_credential` | Renting | Save a registry credential | Changes data | Yes | [`POST /v1/registry-credentials`](https://legion.ambient.xyz/docs/api/images/create-registry-credential) |
| `add_ssh_key` | Renting | Save an SSH public key | Changes data | Yes | [`POST /v1/ssh-keys`](https://legion.ambient.xyz/docs/api/identity/add-ssh-key) |
| `cancel_backup` | Renting | Cancel a queued or uploading backup | Changes data | No | [`POST /v1/backups/{backup_id}/cancel`](https://legion.ambient.xyz/docs/api/rentals/cancel-backup) |
| `cancel_workspace_export` | Renting | Cancel a pending workspace export | Changes data | Yes | [`POST /v1/rentals/{rental_id}/workspace-exports/{export_id}/cancel`](https://legion.ambient.xyz/docs/api/rentals/cancel-workspace-export) |
| `create_offer_alert` | Renting | Be emailed once when a matching machine is available | Changes data | No | [`POST /v1/offer-alerts`](https://legion.ambient.xyz/docs/api/offers/create-offer-alert) |
| `create_service_key` | Renting | Create a service key | Changes data | Yes | [`POST /v1/services/{service_id}/keys`](https://legion.ambient.xyz/docs/api/services/create-service-key) |
| `delete_offer_alert` | Renting | Delete an offer alert | Changes data | No | [`DELETE /v1/offer-alerts/{alert_id}`](https://legion.ambient.xyz/docs/api/offers/delete-offer-alert) |
| `export_workspace` | Renting | Export a stopped rental's workspace | Changes data | No | [`POST /v1/rentals/{rental_id}/workspace-exports`](https://legion.ambient.xyz/docs/api/rentals/create-workspace-export) |
| `rotate_service_key` | Renting | Rotate a service key | Changes data | Yes | [`POST /v1/services/{service_id}/keys/{key_id}/rotate`](https://legion.ambient.xyz/docs/api/services/rotate-service-key) |
| `update_rental` | Renting | Change a rental's settings | Changes data | Yes | [`PATCH /v1/rentals/{rental_id}`](https://legion.ambient.xyz/docs/api/rentals/update-rental) |
| `backup_rental` | Renting | Back up a stopped or failed rental's workspace | Spends credit | Yes | [`POST /v1/rentals/{rental_id}/backups`](https://legion.ambient.xyz/docs/api/rentals/create-rental-backup) |
| `create_backup_download_link` | Renting | Mint a download link for a ready backup | Spends credit | Yes | [`POST /v1/backups/{backup_id}/download-links`](https://legion.ambient.xyz/docs/api/rentals/create-backup-download-link) |
| `create_rental` | Renting | Rent GPUs on a host | Spends credit | Yes | [`POST /v1/rentals`](https://legion.ambient.xyz/docs/api/rentals/create-rental) |
| `create_service` | Renting | Create a service | Spends credit | Yes | [`POST /v1/services`](https://legion.ambient.xyz/docs/api/services/create-service) |
| `create_workspace_export_download_link` | Renting | Make a single-use download link for a ready workspace export | Spends credit | Yes | [`POST /v1/rentals/{rental_id}/workspace-exports/{export_id}/download-links`](https://legion.ambient.xyz/docs/api/rentals/create-workspace-export-download-link) |
| `start_rental` | Renting | Restart a stopped rental | Spends credit | Yes | [`POST /v1/rentals/{rental_id}/start`](https://legion.ambient.xyz/docs/api/rentals/start-rental) |
| `update_service` | Renting | Change a service's model, hardware, scaling or budget, or switch autoscaling on or off | Spends credit | Yes | [`PATCH /v1/services/{service_id}`](https://legion.ambient.xyz/docs/api/services/update-service) |
| `delete_backup` | Renting | Delete a ready backup early | Deletes or stops | Yes | [`DELETE /v1/backups/{backup_id}`](https://legion.ambient.xyz/docs/api/rentals/delete-backup) |
| `delete_rental` | Renting | Delete a rental and its workspace | Deletes or stops | Yes | [`DELETE /v1/rentals/{rental_id}`](https://legion.ambient.xyz/docs/api/rentals/delete-rental) |
| `delete_service` | Renting | Delete a service | Deletes or stops | Yes | [`DELETE /v1/services/{service_id}`](https://legion.ambient.xyz/docs/api/services/delete-service) |
| `remove_registry_credential` | Renting | Remove a registry credential | Deletes or stops | Yes | [`DELETE /v1/registry-credentials/{credential_id}`](https://legion.ambient.xyz/docs/api/images/delete-registry-credential) |
| `revoke_service_key` | Renting | Revoke a service key | Deletes or stops | Yes | [`DELETE /v1/services/{service_id}/keys/{key_id}`](https://legion.ambient.xyz/docs/api/services/revoke-service-key) |
| `stop_rental` | Renting | Stop a rental | Deletes or stops | Yes | [`POST /v1/rentals/{rental_id}/stop`](https://legion.ambient.xyz/docs/api/rentals/stop-rental) |
| `get_earnings_overview` | Hosting | The organization's earnings over a period, with the previous period | Read only | No | [`GET /v1/provider/earnings/overview`](https://legion.ambient.xyz/docs/api/billing/get-provider-earnings-overview) |
| `get_host` | Hosting | Get a host | Read only | No | [`GET /v1/hosts/{host_id}`](https://legion.ambient.xyz/docs/api/hosts/get-host) |
| `get_host_network` | Hosting | A host's network state and the abuse flags raised on its rentals | Read only | No | [`GET /v1/hosts/{host_id}/network`](https://legion.ambient.xyz/docs/api/hosts/get-host-network) |
| `get_host_removal_preview` | Hosting | Preview what is on a host before removing it | Read only | No | [`GET /v1/hosts/{host_id}/removal-preview`](https://legion.ambient.xyz/docs/api/hosts/get-host-removal-preview) |
| `get_price_recommendation` | Hosting | What Legion recommends the host charge per GPU-hour | Read only | No | [`GET /v1/hosts/{host_id}/price-recommendation`](https://legion.ambient.xyz/docs/api/hosts/get-host-price-recommendation) |
| `get_provider_earnings` | Hosting | Get the organization's provider earnings | Read only | No | [`GET /v1/billing/earnings`](https://legion.ambient.xyz/docs/api/billing/get-provider-earnings) |
| `get_rental_earnings` | Hosting | Get what a rental on one of the organization's hosts has earned | Read only | No | [`GET /v1/billing/earnings/rentals/{rental_id}`](https://legion.ambient.xyz/docs/api/billing/get-rental-earnings) |
| `list_earnings_attention` | Hosting | Hosts that are earning less than they could, with what to do | Read only | No | [`GET /v1/provider/earnings/attention`](https://legion.ambient.xyz/docs/api/billing/list-provider-earnings-attention) |
| `list_earnings_by_host` | Hosting | What each of the organization's hosts earned and how it performed | Read only | No | [`GET /v1/provider/earnings/hosts`](https://legion.ambient.xyz/docs/api/billing/list-provider-earnings-hosts) |
| `list_host_benchmarks` | Hosting | A host's benchmark runs, newest first | Read only | No | [`GET /v1/hosts/{host_id}/benchmarks`](https://legion.ambient.xyz/docs/api/hosts/list-host-benchmarks) |
| `list_host_gpu_benchmarks` | Hosting | A host's GPU benchmark runs, newest first | Read only | No | [`GET /v1/hosts/{host_id}/gpu-benchmarks`](https://legion.ambient.xyz/docs/api/hosts/list-host-gpu-benchmarks) |
| `list_hosts` | Hosting | List the organization's hosts | Read only | No | [`GET /v1/hosts`](https://legion.ambient.xyz/docs/api/hosts/list-hosts) |
| `list_maintenance_windows` | Hosting | The organization's maintenance windows | Read only | No | [`GET /v1/maintenance-windows`](https://legion.ambient.xyz/docs/api/hosts/list-maintenance-windows) |
| `preview_maintenance` | Hosting | What scheduling maintenance would do | Read only | No | [`GET /v1/maintenance-windows/preview`](https://legion.ambient.xyz/docs/api/hosts/preview-maintenance) |
| `cancel_maintenance` | Hosting | Cancel scheduled maintenance windows | Changes data | Yes | [`POST /v1/maintenance-windows/cancel`](https://legion.ambient.xyz/docs/api/hosts/cancel-maintenance) |
| `end_maintenance` | Hosting | End active maintenance windows now ("done with maintenance") | Changes data | Yes | [`POST /v1/maintenance-windows/end`](https://legion.ambient.xyz/docs/api/hosts/end-maintenance) |
| `rename_host` | Hosting | Rename a host | Changes data | Yes | [`PUT /v1/hosts/{host_id}/name`](https://legion.ambient.xyz/docs/api/hosts/rename-host) |
| `reschedule_maintenance` | Hosting | Move or change scheduled maintenance windows | Changes data | Yes | [`POST /v1/maintenance-windows/reschedule`](https://legion.ambient.xyz/docs/api/hosts/reschedule-maintenance) |
| `schedule_maintenance` | Hosting | Schedule maintenance on one or many hosts | Changes data | Yes | [`POST /v1/maintenance-windows`](https://legion.ambient.xyz/docs/api/hosts/schedule-maintenance) |
| `update_host_listing` | Hosting | Set a host's price and availability | Changes data | Yes | [`PUT /v1/hosts/{host_id}/listing`](https://legion.ambient.xyz/docs/api/hosts/update-listing) |
| `remove_host` | Hosting | Remove a host | Deletes or stops | Yes | [`POST /v1/hosts/{host_id}/remove`](https://legion.ambient.xyz/docs/api/hosts/remove-host) |

The last column links to the API operation the tool runs. Its page has every parameter and response.

## What the columns mean

- **Read only** tools change nothing. They are safe to let an agent call freely.
- **Changes data** tools create or change something. They are `add_registry_credential`, which saves a registry credential for private images, `add_ssh_key`, which saves an SSH key that later rentals can use, `export_workspace`, which packs a stopped rental's `/workspace` into a file kept for 24 hours (making it is free; each download link is charged, see below), `cancel_workspace_export`, which stops a pending export and discards its upload, `cancel_backup`, which cancels a queued or uploading backup, discards its upload and refunds it, `update_rental`, which changes an interruptible rental's max price per GPU-hour, whether it resumes by itself, whether it backs up automatically or which SSH key opens it (the old key stops working within about a minute), and the Service tools `create_service_key`, which makes a service key, and `rotate_service_key`, which replaces one, and the Hosting tools `update_host_listing`, which sets a host's price and whether it is offered, `rename_host`, and the maintenance tools `schedule_maintenance`, `reschedule_maintenance`, `cancel_maintenance` and `end_maintenance`, which announce, move, call off or end a [maintenance window](https://legion.ambient.xyz/docs/providing/maintenance) and email the renters on the host, and the Renting tools `create_offer_alert`, which asks Legion to email you once when a machine matching a search becomes available (an [offer alert](https://legion.ambient.xyz/docs/renting/offer-alerts)), and `delete_offer_alert`, which takes one back.
- **Spends credit** tools charge your credit. They are `create_rental`, which starts billing and can turn on the [automatic backup](https://legion.ambient.xyz/docs/renting/stopping-and-backups#automatic-backup-when-a-rental-is-interrupted) of an interruptible rental, `start_rental`, which starts billing, `backup_rental`, which makes a [backup](https://legion.ambient.xyz/docs/renting/stopping-and-backups#backups) of a stopped or failed rental, kept for 7 or 30 days, `create_backup_download_link`, which makes a download link for a backup: the first is included in its price, and each further one is charged, and `create_workspace_export_download_link`, which makes a download link for a ready workspace export: $0.15 per GiB of the file, every link. A download link works once. The Service tools `create_service` and `update_service` expose a port of a rental or start replicas that spend credit, up to the service's monthly cap.
- **Deletes or stops** tools end something. They are `stop_rental`, `delete_rental`, `remove_registry_credential`, which removes a registry credential, `delete_backup`, which deletes a backup early with no refund, and the Hosting tool `remove_host`, which cannot be undone. The Service tools `delete_service` and `revoke_service_key` end a service and cut off a key.
- **Back up and stop, or back up then delete:** `stop_rental` and `delete_rental` with `backup_retention_days` also make a backup and charge its price, so the agent states that price, from `estimate_backup`, and asks first. The preview of `stop_rental` and `delete_rental` presents both choices side by side: stop or delete without a backup (the default, unless the rental backs up automatically) and back up first with its price, and the agent asks which one the user wants.
- **Hosting** tools are `list_hosts`, `get_host`, `list_host_benchmarks`, `list_host_gpu_benchmarks`, `get_host_network`, `get_price_recommendation`, `get_provider_earnings`, `get_earnings_overview`, `list_earnings_by_host`, `list_earnings_attention`, `get_rental_earnings`, `update_host_listing`, `rename_host`, `get_host_removal_preview`, `remove_host`, `list_maintenance_windows`, `preview_maintenance`, `schedule_maintenance`, `reschedule_maintenance`, `cancel_maintenance` and `end_maintenance`. They read your hosts, their benchmarks and network state, what a removal would meet (the renters' files stored on the host), the price Legion recommends, your earnings and how your hosts are performing, and change a host's price, listing and name, or remove it. The maintenance tools read a host's windows and what a new window would do (`preview_maintenance`, which writes nothing), and schedule, move, cancel or end one: the preview before a yes names the hosts, the start and planned end, whether each is penalty-free, and how many renter organizations and rentals are emailed. A host change also needs an organization owner's key.
- **Asks you first** is **Yes** for a tool that does nothing until the agent passes `confirm: true`, and the agent should only do that after you said yes. It is **No** for a tool that only reads.

## Arguments

| Argument | Type, and the tools that take it | What it does |
| --- | --- | --- |
| Path and query parameters | Every tool whose operation has them | The operation's own parameters are top-level arguments with the same names. For example `list_offers` takes `gpu_models`, `min_gpus`, `sort`, `limit` and `cursor`. The API's own pages list them. |
| `body` | Every tool whose operation has a request body | The request body goes in this one argument. |
| `idempotency_key` | Required string, on `create_rental`, `create_service` and `create_service_key` | The operation takes an `Idempotency-Key`. The key is at most 255 characters. The agent makes a new one for each thing it means to do and reuses it when it retries that same thing, so a retry never rents twice. See [Idempotency](https://legion.ambient.xyz/docs/api/idempotency). |
| `confirm` | Boolean, on every tool that asks first | `true` once you have said yes. Without it the tool only returns a preview. |
| `expected_price_per_gpu_hour_minor` | Integer, on `create_rental` and `start_rental` | The price per GPU-hour, in cents, that you agreed to. Required when `confirm` is true. If the price has changed, the call is refused and you are shown the current price. |
| `expected_hourly_total_minor` | Integer, on `create_rental` | The hourly total, in cents, from the preview (the price per GPU-hour times the number of GPUs). Required when `confirm` is true. It ties your yes to the GPU count as well as the price. |
| `confirm_rental_name` | String, on `delete_rental` | Required when `confirm` is true. It must equal the rental's name, so a mistaken ID can't delete the wrong rental. |
| `confirm_host_name` | String, on `update_host_listing`, `rename_host` and `remove_host` | Required when `confirm` is true. It must equal the host's current name, so a mistaken ID can't change or remove the wrong host. |
| `confirm_large_price_cut` | Boolean, on `update_host_listing` | Required (`true`) when the new price is under half the current one, after you said yes to that cut. Without it the call is refused with `price_cut_unconfirmed`. |
| `stored_data` | String in `body`, on `remove_host` | `when_empty` ("Remove when empty") or `delete_now` ("Delete renters' files and remove now"). Required when the host holds renters' files, else the call is refused with `host_has_stored_data`. Read `get_host_removal_preview` first and offer both. `delete_now` also needs `body.reason` and `body.confirm_host_name` (the host's name, as the user typed it, besides the top-level `confirm_host_name`), after the user said yes to deleting the files. |
| `confirm_force` | Boolean, on `remove_host` | Required with `body.force` true, after you said yes to forcing: rentals stranded on the offline host end as failed. Without it the call is refused with `invalid_params`. |
| `expected_listing_price_per_gpu_hour_minor` | Integer, on `update_host_listing` | The new price per GPU-hour, in cents, equal to `body.price_per_gpu_hour.amount_minor` in USD. Required when `confirm` is true. A mismatch is refused, so a price typed in dollars where cents belong is caught. |

## How asking first works

A tool that asks first does nothing when `confirm` is missing. Instead it returns a preview with the code `confirmation_required`. For `create_rental`, the preview shows the price, your balance, the SSH key and the image. For a host tool it shows the host's name and state and what the change does: the old and new price and what a new rental earns you, that the old name is never assigned again, or that removing the host revokes its credentials and that the machine comes back only by enrolling again as a new host. The agent shows you the preview, and calls again with `confirm: true` only if you say yes.

```json
{
  "name": "create_rental",
  "arguments": {
    "idempotency_key": "6f1c2b8e-3d4a-4f5e-9b7c-2a1d0e8f9c3b",
    "body": {
      "host_id": "8c0e2f4a-1b3d-4e5f-9a7b-6c5d4e3f2a1b",
      "gpu_count": 1,
      "image": "pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime",
      "ssh_public_key": "ssh-ed25519 AAAA… you@laptop"
    }
  }
}
```

This call has no `confirm`, so it creates nothing. It returns the preview. After your yes, the agent sends the same call with `confirm: true` and `expected_price_per_gpu_hour_minor` and `expected_hourly_total_minor` set to the values in the preview.

`confirm` is a safeguard against mistakes. It can't stop an agent that has been manipulated into passing it. Your client's own approval prompt can. See [Safety](https://legion.ambient.xyz/docs/agents/safety).

## Results

A successful call returns the API's JSON, as structured content and as text.

## Errors

When the API refuses a call, the result is marked as an error and carries the problem: `code`, `title`, `detail`, `status` and `request_id`. The agent should branch on `code`, as with the API. Every API code is in [Errors](https://legion.ambient.xyz/docs/errors). Quote the `request_id` when you contact [support](https://legion.ambient.xyz/docs/account/support).

The server adds a few codes of its own:

| Code | What it means |
| --- | --- |
| `confirmation_required` | The tool asks first and `confirm` was missing. Nothing was done. The result is the preview. |
| `price_mismatch` | `expected_price_per_gpu_hour_minor` or `expected_hourly_total_minor` does not match the current price, or `expected_listing_price_per_gpu_hour_minor` does not equal the new listing price. Nothing was created or changed. |
| `price_changed` | From `create_rental`: the host's price changed after the check, before the GPUs were reserved. Nothing was created. `current_price_per_gpu_hour` is the new price. |
| `name_mismatch` | `confirm_rental_name` is not the rental's name, or `confirm_host_name` is not the host's current name. Nothing was deleted or changed. |
| `price_cut_unconfirmed` | From `update_host_listing`: the new price is under half the current one and `confirm_large_price_cut` was missing. Nothing was changed. Show the cut and ask again. |
| `invalid_params` | An argument is missing or wrong, for example `confirm: true` without `expected_price_per_gpu_hour_minor`. `detail` says which. Nothing was done. |
| `secret_withheld` | The answer contained a credential, so the server withheld it. The agent should not try to get the value another way. Use the Legion app. |
| `response_too_large` | The answer is too large for an agent. The agent narrows the request with filters, `limit` and `cursor`. |
| `rate_limited` | The key made too many calls. Wait, then try again. |

## Limits

- Each API key or connected app can make **120 MCP requests a minute**. Each API key can make **20 rental creations or restarts an hour**. Each organization can make **60 rental creations or restarts an hour**, over all its keys.
- The API's own limits apply to the tools too: for example, checking images is limited per organization. Over a limit the result has the code `rate_limited`. See [Rate limits](https://legion.ambient.xyz/docs/api/rate-limits).
- Lists return a page at a time. The agent passes `next_cursor` back as `cursor`. See [Pagination](https://legion.ambient.xyz/docs/api/pagination).

## Hints for clients

Every tool carries hints that clients can use: read tools are marked read only, and tools that remove or widen access are marked destructive. A client may ask for your approval before a tool call. Leave that on for any tool that isn't read only.

## Service tools

A [service](https://legion.ambient.xyz/docs/renting/services/overview) is a public URL for something you run on Legion: a port on one of your rentals, or a model that Legion runs on rented GPUs and scales with traffic. The tools that manage services are in the table above (`list_services`, `get_service`, `create_service`, `update_service`, `delete_service`, `create_service_key`, `rotate_service_key`, `revoke_service_key`, `get_service_metrics` and `list_service_events`). They run the service operations of the [Legion API](https://legion.ambient.xyz/docs/api/overview) as you, with the same permissions (`services.read` and `services.manage`). What each does:

- `get_service` shows the Service URL, access, mode, status, scaling, cap, replicas, a usage summary and the keys (masked).
- `create_service` works in either mode: on a rental (a port of one of your rentals) or autoscaled (a model or image). Without `confirm` it returns a preview with the estimate: the likely hardware, its price, the range, the cost per hour idle, at the minimum and at the maximum, and the cap.
- `update_service` changes scaling, the price ceiling or cap, the access (public or API key required, and the allowed addresses) and the mode (turn autoscaling on or off), or pauses and resumes with `paused: true` or `false`.
- `delete_service` deletes the service and its keys. For a service on a rental the rental is untouched. Deleting an autoscaled service needs a fresh sign-in, so it is refused with `step_up_required`: use the app.

Things to know:

- **Configuration.** `create_rental`, `create_service` and `update_service` take `env`, `model_settings`, and, for your own image, `command` and `args`. Previews and events show variable names and whether each is secret, never a secret's value, and the preview says when a change restarts the container or rolls the replicas. An agent never asks you to type a secret into the chat: save it in the app or with `legion --secret-env`. See [Configuration](https://legion.ambient.xyz/docs/renting/configuration).
- **`create_rental` with `serve`** also returns the `service_id` of the service it creates.
- **Making a service public** removes the key check. For an autoscaled service it also lets anyone with the Service URL drive scale-up, up to its maximum replicas and cap. The preview says so, and the agent asks you first. The preview of `create_service` for an autoscaled model carries the estimate: the likely hardware, its price and the range.
- **A key's secret is a credential.** `create_service` (with an API key required), `create_service_key` and `rotate_service_key` return the new key's secret once, in the answer. The agent gives it to you to store, and doesn't print it again, write it to a file or put it in a URL. Legion keeps only a fingerprint, so it can't be shown again.
- **Changes need a Full access key.** An Agent key, and an app connected by signing in, can only read services (`list_services`, `get_service`, `get_service_metrics`, `list_service_events`). A change answers `403 api_key_scope`: make it in the app, or use a Full access API key with the MCP server.
- **Asks first** works as for every other tool: without `confirm: true` the tool returns a preview and changes nothing. The agent passes `confirm: true` only after your yes, in your latest message.

## Registry credentials

`list_registry_credentials` lists the organization's saved credentials for private images (name, host, path prefix, username, last used), never a token. `add_registry_credential` and `remove_registry_credential` ask first, like every tool that changes things, and need the `registry.manage` permission, which owners have. Don't paste a token into the chat: save it in **Settings**, **Registry credentials**, or with `legion registry add`. See [Private images](https://legion.ambient.xyz/docs/renting/images#private-images).

## What isn't a tool

Adding credit, payouts, API keys, invitations and enrollment tokens are not tools. Enrolling a host needs an enrollment token, which is a secret that adds a machine to your organization, so you run the installer on the machine yourself from **Add a host** in the app. A host's blocked networks are a provider security control and stay in the app, and so do egress requests and the web terminal. Use the Legion app for them. Managing existing hosts is possible only with the Hosting tools, on a key made with provider tools. Connecting to a rental is `ssh`, which the agent runs in a shell, not an MCP tool: see [Connecting](https://legion.ambient.xyz/docs/renting/connecting).
