# Create egress request

> POST /v1/egress-requests. Asks Legion to allow a domain (example.com, or *.example.com for its subdomains) or an IPv4 range for one rental, or for the whole organization (omit…

Source: https://legion.ambient.xyz/docs/api/network/create-egress-request

`POST https://api.legion.ambient.xyz/v1/egress-requests`

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

Asks Legion to allow a domain (`example.com`, or `*.example.com` for its
subdomains) or an IPv4 range for one rental, or for the whole organization (omit
`rental_id`; needs `network.manage`, which only owners have). Rental scope needs
`rentals.manage`. The pattern goes through the same validator as the platform's list. Legion reviews the request, normally within one working day, and the requester is emailed
the decision. A request nobody decides expires after 14 days. At most one request is
pending for the same organization, scope, kind and pattern; an organization may send 20
requests in any 24 hours and have 50 pending. The allow-list is abuse control: it does not
stop data leaving through the sites on it. A repeat with the same `Idempotency-Key` and
body returns the original request.

## Headers

- `Idempotency-Key`, string, required: Client-chosen key, unique per request intent, at most 255 characters.

## Request body

- `kind`, EgressKind, required: `domain`: a host name (`example.com`) or `*.example.com` for every subdomain, never a public suffix. Lowercase, with internationalized names in their `xn--` form. `cidr`: an IPv4 range in canonical form (`203.0.113.0/24`), never inside private or reserved space.
- `pattern`, string, required
- `ports`, EgressPorts
- `rental_id`, string (uuid): The rental the destination is for. Omit it for the whole organization (needs `network.manage`).
- `justification`, string, required: Why the destination is needed. Legion reads it.

Example:

```json
{
  "kind": "domain",
  "pattern": "string",
  "ports": [
    1
  ],
  "rental_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "justification": "string"
}
```

## Responses

### 201

The pending request.

- `id`, string (uuid), required
- `scope`, EgressRequestScope, required: The scope in force. Legion may widen a rental request to the organization, so it can differ from `requested_scope`.
- `rental_id`, string (uuid): The rental, when `scope` is `rental`.
- `kind`, EgressKind, required: `domain`: a host name (`example.com`) or `*.example.com` for every subdomain, never a public suffix. Lowercase, with internationalized names in their `xn--` form. `cidr`: an IPv4 range in canonical form (`203.0.113.0/24`), never inside private or reserved space.
- `pattern`, string, required
- `ports`, EgressPorts, required: The ports in force. Legion may narrow them, so they can be fewer than `requested_ports`.
- `requested_scope`, EgressRequestScope, required: `rental`: the destination is allowed for one rental and ends with it. `organization`: for every rental of the organization until revoked or `expires_at`.
- `requested_ports`, EgressPorts, required: TCP ports, at most 8.
- `state`, EgressRequestState, required: `pending`: waiting for review. `approved`: on the allow-list. `denied`: refused, with a reason. `withdrawn`: the requester took it back. `expired`: nobody decided within 14 days, the approval's `expires_at` passed, or the rental ended. `revoked`: Legion took the approval away, with a reason.
- `justification`, string, required
- `decision_reason`, string: What the reviewer wrote when denying or revoking (and, optionally, when approving). Never names the reviewer.
- `requested_by`, User, required
  - `id`, string (uuid), required
  - `email`, string (email), required
  - `name`, string, required
- `decided_at`, string (date-time): When Legion approved or denied the request.
- `expires_at`, string (date-time): When the approval ends. Absent until approved, and for an approval without an expiry.
- `created_at`, string (date-time), required

Example:

```json
{
  "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "scope": "rental",
  "rental_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "kind": "domain",
  "pattern": "string",
  "ports": [
    1
  ],
  "requested_scope": "rental",
  "requested_ports": [
    1
  ],
  "state": "pending",
  "justification": "string",
  "decision_reason": "string",
  "requested_by": {
    "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
    "email": "you@example.com",
    "name": "string"
  },
  "decided_at": "2026-10-15T12:00:00Z",
  "expires_at": "2026-10-15T12:00:00Z",
  "created_at": "2026-10-15T12:00:00Z"
}
```

### 400

The request is malformed (`invalid_request`), the pattern is not a valid domain or CIDR
(`invalid_pattern`: the name must end in a delegated public top-level domain), is too broad
(`pattern_too_broad`: a wildcard over a public suffix, over a zone that holds one or that anyone
can publish into, or over a user-controlled platform, an exact public suffix, a shared object
storage endpoint or paste or chat service, a wildcard with a port other than 80 or 443, or a
range wider than /16), or lies in private or reserved space (`denied_range`); a name with a non-ASCII or `xn--` label is refused as a renter's request (ask Ambient to add such a site). Port 25 and
port 853 are `invalid_request`: the agent always blocks them.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission (`forbidden`: organization scope needs `network.manage`),
requests are turned off for the organization (`requests_disabled`), or the usual
`no_organization` and sign-in refusals.

### 404

The resource does not exist or belongs to another organization.

### 409

The same destination is already waiting for review (`egress_request_exists`; the
problem's `resource_id` is the pending request), the allow-list already covers it
(`egress_already_allowed`), the organization has 50 requests pending
(`too_many_pending`), or the rental has been deleted or has failed (`rental_not_live`).

### 422

The Idempotency-Key was already used with a different request body.

### 429

Rate limited (`code` is `rate_limited`), or the organization asked the
pull-through mirror to copy in too many different tags or digests of one
repository today (`mirror_quota_exceeded`). Retry after the `Retry-After`
seconds.

### 500

An unexpected server error. Safe to retry.

## Errors

- 400 [`denied_range`](https://legion.ambient.xyz/docs/errors#denied_range)
- 400 [`invalid_pattern`](https://legion.ambient.xyz/docs/errors#invalid_pattern)
- 400 [`pattern_too_broad`](https://legion.ambient.xyz/docs/errors#pattern_too_broad)
- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 403 [`requests_disabled`](https://legion.ambient.xyz/docs/errors#requests_disabled)
- 409 [`egress_already_allowed`](https://legion.ambient.xyz/docs/errors#egress_already_allowed)
- 409 [`egress_request_exists`](https://legion.ambient.xyz/docs/errors#egress_request_exists)
- 409 [`rental_not_live`](https://legion.ambient.xyz/docs/errors#rental_not_live)
- 422 [`idempotency_key_reused`](https://legion.ambient.xyz/docs/errors#idempotency_key_reused)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/egress-requests" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "kind": "domain",
  "pattern": "string",
  "ports": [
    1
  ],
  "rental_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "justification": "string"
}'
```
