# Save an SSH public key

> POST /v1/ssh-keys. Saves one OpenSSH public key under a label of the caller's choosing.

Source: https://legion.ambient.xyz/docs/api/identity/add-ssh-key

`POST https://api.legion.ambient.xyz/v1/ssh-keys`

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

Saves one OpenSSH public key under a label of the caller's choosing. Needs `rentals.manage`. Only a public key is accepted, as one line of
`type base64 [comment]`: `ssh-ed25519`, `ssh-rsa` (at least 2048
bits), `ecdsa-sha2-nistp256`, `ecdsa-sha2-nistp384`,
`ecdsa-sha2-nistp521`, `sk-ssh-ed25519@openssh.com` or
`sk-ecdsa-sha2-nistp256@openssh.com`. The key is parsed and stored in
its canonical form (`type base64`, no comment), and the response
carries its fingerprint, as `ssh-keygen -l` prints it.

A private key (OpenSSH, PEM, PuTTY) is refused with 400
`private_key_refused` and is never stored, logged or echoed. Anything
else that is not exactly one valid public key (options before the key
type, several lines, a certificate, an unsupported type, a cut-off
or malformed key, an RSA key under 2048 bits) is 400
`invalid_ssh_key`; a blank label is 400 `invalid_label`. A person can
save 20 keys: the 21st is 409 `ssh_key_limit`. Saving a key the
person already has, whatever its label or comment, is 409
`ssh_key_exists`. Each addition is recorded in an audit event with
the key's fingerprint, never the key.

## Request body

- `label`, string, required: The person's name for the key. Leading and trailing spaces are dropped.
- `public_key`, string, required: One OpenSSH public key line, `type base64 [comment]`. A private key is refused.

Example:

```json
{
  "label": "string",
  "public_key": "string"
}
```

## Responses

### 201

The saved key.

- `id`, string (uuid), required
- `label`, string, required: The person's name for the key.
- `key_type`, SshKeyType, required
- `public_key`, string, required: The canonical OpenSSH public key, `type base64` with no comment, ready to send as a rental's `ssh_public_key`.
- `fingerprint`, string, required: The SHA-256 fingerprint as `ssh-keygen -l` prints it.
- `created_at`, string (date-time), required

Example:

```json
{
  "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "label": "string",
  "key_type": "ssh-ed25519",
  "public_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEZ0ZXN0a2V5Zm9ybGVnaW9uZG9jcw",
  "fingerprint": "SHA256:2fmxiBMT0FMF3tnMUkvVAPLNdAOaCFoNtoGSJENyf8Q",
  "created_at": "2026-10-15T12:00:00Z"
}
```

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

### 409

The resource's current state does not allow the operation. `legal_versions_stale`: a legal document version sent is not the current one; the
problem's `legal` holds the current documents.

### 500

An unexpected server error. Safe to retry.

## Errors

- 400 [`invalid_label`](https://legion.ambient.xyz/docs/errors#invalid_label)
- 400 [`invalid_ssh_key`](https://legion.ambient.xyz/docs/errors#invalid_ssh_key)
- 400 [`private_key_refused`](https://legion.ambient.xyz/docs/errors#private_key_refused)
- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 409 [`ssh_key_exists`](https://legion.ambient.xyz/docs/errors#ssh_key_exists)
- 409 [`ssh_key_limit`](https://legion.ambient.xyz/docs/errors#ssh_key_limit)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/ssh-keys" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "label": "string",
  "public_key": "string"
}'
```
