# Use Legion with AI agents

> Let an AI agent find GPU offers, rent and manage GPUs, and check spend on Legion, with the Legion skill, the MCP server, or both.

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

After this page you know what Legion offers an AI agent, which of the two ways to connect one to use, how to connect Claude by signing in, and how to get an agent renting its first GPU, with you approving every step that costs money.

Legion gives an agent two things:

- **The Legion skill** is a folder of instructions in the open Agent Skills format. It teaches an agent how Legion works: how to find an offer, rent it, connect over SSH, expose a service, read your spend and clean up. It also gives the agent its safety rules: ask before it spends, expose or deletes.
- **The MCP server** gives an agent Legion as tools: `list_catalog`, `list_offers`, `create_rental`, `get_billing_account` and the rest. The tools use the same API as the app. Claude connects by signing in to Legion, and other clients and scripts use an API key. Its address is:

```text
https://api.legion.ambient.xyz/v1/mcp
```

## Which one to use

| You have | Use |
| --- | --- |
| An agent that supports MCP servers, such as Claude, Cursor, VS Code or Codex | The MCP server. Add the skill too, for the workflow and the safety rules. |
| An agent with a shell and network access but no MCP support | The skill alone. It uses the [Legion API](https://legion.ambient.xyz/docs/api/overview) with `curl`. |
| A sandbox with no network access from the agent's shell | The MCP server. The tools run on Legion's side. |
| Only a wish to try it | The MCP server, connected read-only with an API key. The agent can look but not change anything. |

The skill and the server work together. The server does the work and asks for confirmation on anything that costs money. The skill tells the agent how to plan the work and what to say to you.

## Quick start

1. **Connect Claude.** In Claude, open **Customize**, then **Connectors**, then **Add custom connector**, and enter the server's address above. Click **Add**, then **Connect**, sign in to Legion in your browser, choose **Agent** or **Agent + hosts**, and approve. In Claude Code, run `claude mcp add --transport http legion https://api.legion.ambient.xyz/v1/mcp`, then `/mcp`. The steps for each plan are in [Connect Claude](https://legion.ambient.xyz/docs/agents/mcp#connect-claude). You can [install the skill](https://legion.ambient.xyz/docs/agents/skill) too.
2. **Ask.** Start with something that only reads, such as:

```text
Which GPUs can I rent on Legion right now, and how much credit do I have?
```

When you are ready, ask for a rental. The agent shows you the price and what it is about to do, and waits for your yes. See [Examples](https://legion.ambient.xyz/docs/agents/examples).

## Use an API key instead

An API key is for scripts, CI and clients without OAuth, such as Cursor, VS Code and Codex.

1. **Create a key for the agent.** In the Legion app, open **Settings**, then **API keys**, and create a key named for the agent: choose **Agent** access and an expiry. Use a key from a member of your organization rather than an owner if you can. See [Safety](https://legion.ambient.xyz/docs/agents/safety).
2. **Connect the agent.** [Connect the MCP server](https://legion.ambient.xyz/docs/agents/mcp#use-an-api-key) for your client, and [install the skill](https://legion.ambient.xyz/docs/agents/skill). Put the key in an environment variable, never in the chat.

Then ask, as above.

## What an agent can do

An agent can search the market, rent a GPU, wait for it to run and give you the SSH command, read your [services](https://legion.ambient.xyz/docs/renting/services/overview), and, with a Full access API key, expose a port of a rental or serve an autoscaled model as a service, with keys, show your balance and what each rental has cost, and stop, start or delete rentals. [Tools reference](https://legion.ambient.xyz/docs/agents/tools) lists every tool.

An agent cannot add credit, change payouts, create API keys, invite people, enroll a host or change a host's blocked networks. Those stay in the app. It can manage your existing hosts only if you choose **Agent + hosts** when you connect it, or give it a key with provider tools.

## Go further

- [Install the skill](https://legion.ambient.xyz/docs/agents/skill): for Claude Code, Claude, and other agents that read Agent Skills.
- [Connect the MCP server](https://legion.ambient.xyz/docs/agents/mcp): sign in with Claude, or copy-paste setup with a key for each client.
- [Tools reference](https://legion.ambient.xyz/docs/agents/tools): every tool, what it changes, and which ask first.
- [Safety](https://legion.ambient.xyz/docs/agents/safety): what the agent asks before, and how to limit the damage of a mistake.
- [Examples](https://legion.ambient.xyz/docs/agents/examples): five conversations and the tool calls behind them.
- [The legion CLI](https://legion.ambient.xyz/docs/cli): an agent with a shell can run `legion` with `-o json --yes`. See [Scripting and automation](https://legion.ambient.xyz/docs/cli/scripting).
- [llms.txt](https://legion.ambient.xyz/llms.txt): the docs index for agents.
