> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Your own agent

> Connect an agent you build and run yourself: the CLI, the MCP server or the REST API, with an API key.

An agent you build and run yourself, such as a bot on your own server, uses Spiral like any program: through the
`spiral` CLI, the MCP server or the REST API, with an API key.

**1. Create a key**

Create a key under **API keys** in the [console](https://spiral.ai/start) and store it as a secret on the agent's
machine, as `SPIRAL_API_KEY`.

**2. Install the CLI and the agent skill**

```bash theme={null}
npx -y spiral-cli@latest init
```

`init` installs `spiral`, logs in and adds the agent skill, the short guide that teaches an agent Spiral's
commands. On a machine with a browser, `init --browser` signs in without pasting a key; on a server, pipe the key
in: `printf %s "$SPIRAL_API_KEY" | spiral init --json`. It needs Node.js 22.12 or later. `spiral update` installs the newest release later.

**3. Let it work**

The agent runs commands such as these, with `--json` for one line of JSON per command:

```bash theme={null}
spiral tools search "remove background" --category image --json
spiral runs create --provider wavespeed --model wavespeed-ai/image-background-remover \
  --set image=@./photo.png --wait --save --json
```

`spiral skills get core` prints the full guide for the installed version.

**4. Hear when runs finish**

Give runs a [webhook](/docs/concepts/webhooks.md), so the agent hears when a run finishes instead of polling.

## Other ways in

* **MCP:** an agent framework that speaks MCP can connect to `https://api.spiral.ai/mcp` with the key as a bearer
  token. See [MCP server](/docs/mcp-server.md).
* **REST:** call the [API](/docs/api-reference/introduction.md) directly with the key.
* **One line:** an agent that can fetch a URL and keep a secret can set itself up from `set up https://spiral.ai/SKILL.md`.

If something does not work, see [Troubleshooting](/docs/mcp-server.md#troubleshooting).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.