## POST /api/v2/vps/{id}/network

**Change VPS network state**

Perform one whitelisted network operation for a VPS. Read `GET /api/v2/vps/{id}/network` first to get interface names, assigned IP IDs, available IP IDs, subnet IDs, private-network choices, and action gates. `action` selects exactly one operation; send only the fields listed for that action because unknown fields are rejected. Action guide: `update_rdns` sets reverse DNS for an assigned IP using `ip` and `rdns`; `assign_ip` attaches one available or reserved public IP using `ipId` when possible; `assign_ips` attaches multiple IPs to one interface using `ips[]`; `remove_ip` removes one assigned IP from an interface and requires `ipType`; `get_available_subnets` requires `ipType` (`ipv4` or `ipv6`) and returns sanitized public subnet groups immediately; `change_ip` replaces an assigned IP and requires `ipId` or `ipAddress` for one concrete available IP. To satisfy a request such as "change my VPS to 64.112.125.0/24 or another IPv4 from a different /24", first call `get_available_subnets` with `{ "action": "get_available_subnets", "ipType": "ipv4" }`, filter the returned `subnets[]` by `parentCidr` when the user named a subnet, choose one returned `subnets[].ips[].id`, then call `change_ip` with that `ipId` and `interfaceName` (usually `net0`). `reserveOldIp: true` keeps the previous public IP as a reserved public IP instead of returning it to the pool. `ipType` is optional for `change_ip` because the server infers the family from the selected address, and `subnetId` may be sent with `ipId`/`ipAddress` to prove the selected IP came from the chosen subnet. `subnetId` alone does not choose an IP, and `confirm` is not a valid `change_ip` field. `create_public_interface` creates a public interface with a selected public IP; `create_private_interface` creates a private-network interface from a private subnet; `delete_interface` removes a non-primary interface by `interfaceName`; `delete_primary_interface` removes the primary public interface only when `confirm: true` and the network state allows it. Mutating actions return an operation envelope. If the operation completed inline, `operation.status` is `completed` and `operation.pollUrl` is `null`; if a restart/reconfigure job was queued, the response is `202` with a poll URL. `get_available_subnets` is read-style and returns `{ subnets }` synchronously.

### Related Endpoints

- `GET /api/v2/vps/{id}/network`: Get VPS network state
- `GET /api/v2/vps/{id}`: Get VPS details
- `GET /api/v2/vps/{id}/iso`: List VPS ISO media

### Headers

- `Accept`: application/json
- `Authorization`: Bearer YOUR_API_KEY
- Required API scopes: `write:vm`, `write:network`
- `Content-Type`: application/json

### Parameters

- `id` (path, string, required): Public VPS ID from `GET /api/v2/vps` `data[].id`. Do not invent this value; use the exact ID returned by the referenced API response. Example: `vps_01hxa3b4c5d6e7f8g9h0j1k2m3`

### Request Body

- `action` (string, required): Network action to perform. Each action accepts only its documented fields; unknown fields are rejected. Example: `update_rdns`
  Allowed values: assign_ip, assign_ips, remove_ip, change_ip, update_rdns, get_available_subnets, create_public_interface, create_private_interface, delete_interface, delete_primary_interface
- `ipId` (string,null, optional): Public IP address ID from `GET /api/v2/vps/{id}/network` `availableIPv4[].id`, `availableIPv6[].id`, or interface `ips[].id`. Prefer this over `ipAddress` when both are available. Example: `ip_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `ipType` (string,null, optional): IP family. Required for `get_available_subnets` and `remove_ip`; optional for `assign_ip` and `change_ip` when `ipId` or `ipAddress` identifies an address. Example: `ipv4`
  Allowed values: ipv4, ipv6, 
- `interfaceName` (string,null, optional): Interface name from `GET /api/v2/vps/{id}/network` `interfaces[].id`. Required when assigning/removing/changing IPs or deleting an interface. For private-interface creation, omit it unless the network state tells you to use a specific name. Example: `net0`
- `subnetId` (string,null, optional): Subnet ID from network availability results. Accepted by `assign_ip`, `create_public_interface`, `create_private_interface`, and by `change_ip` only together with `ipId` or `ipAddress` to validate the selected IP. It does not choose an IP by itself. Example: `subnet_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `ipAddress` (string,null, optional): Raw IP address fallback when no `ipId` is available. Prefer `ipId` for public IP operations. Example: `203.0.113.10`
- `reserveOldIp` (boolean, optional): Only accepted for `change_ip`. When true, the old public IP is kept as a reserved public IP instead of being returned to the pool. Example: `true`
- `ips` (array<object>, optional): Batch assignment list for `assign_ips`. Each item identifies one IP to attach to the same interface.
- `ips[].ipId` (string,null, required) Example: `ip_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `ips[].ipAddress` (string,null, required) Example: `203.0.113.10`
- `ips[].ipType` (string,null, required) Example: `ipv4`
- `ip` (string,null, optional): Assigned IP address whose reverse DNS should change for `update_rdns`. Example: `203.0.113.42`
- `rdns` (string,null, optional): Reverse DNS hostname for `update_rdns`. The hostname must pass upstream reverse-DNS validation. Example: `app-01.example.com`
- `vlan` (number,null, optional): Optional VLAN tag for `create_private_interface`. Usually omit this and use the subnet/private-network defaults from the network state. Example: `220`
- `confirm` (boolean, optional): Required and must be true only for `delete_primary_interface`. Example: `true`

### Request Examples

#### Set reverse DNS

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "update_rdns",
    "ip": "203.0.113.42",
    "rdns": "app-01.example.com"
  }'
```

```json
{
  "action": "update_rdns",
  "ip": "203.0.113.42",
  "rdns": "app-01.example.com"
}
```

#### Assign one public IPv4 address

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "assign_ip",
    "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "ipType": "ipv4",
    "interfaceName": "net0"
  }'
```

```json
{
  "action": "assign_ip",
  "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "ipType": "ipv4",
  "interfaceName": "net0"
}
```

#### Assign multiple IP addresses

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "assign_ips",
    "interfaceName": "net0",
    "ips": [
      {
        "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
        "ipAddress": "203.0.113.10",
        "ipType": "ipv4"
      },
      {
        "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m4",
        "ipAddress": "2001:db8::10",
        "ipType": "ipv6"
      }
    ]
  }'
```

```json
{
  "action": "assign_ips",
  "interfaceName": "net0",
  "ips": [
    {
      "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
      "ipAddress": "203.0.113.10",
      "ipType": "ipv4"
    },
    {
      "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m4",
      "ipAddress": "2001:db8::10",
      "ipType": "ipv6"
    }
  ]
}
```

#### Remove an assigned IP address

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "remove_ip",
    "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "ipType": "ipv4",
    "interfaceName": "net0"
  }'
```

```json
{
  "action": "remove_ip",
  "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "ipType": "ipv4",
  "interfaceName": "net0"
}
```

#### Change an assigned IP address

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "change_ip",
    "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "interfaceName": "net0",
    "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "reserveOldIp": true
  }'
```

```json
{
  "action": "change_ip",
  "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "interfaceName": "net0",
  "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "reserveOldIp": true
}
```

#### Change IPv4 after selecting an IP from a requested subnet

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "change_ip",
    "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "interfaceName": "net0"
  }'
```

```json
{
  "action": "change_ip",
  "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "interfaceName": "net0"
}
```

#### Get available public IPv4 subnets

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "get_available_subnets",
    "ipType": "ipv4"
  }'
```

```json
{
  "action": "get_available_subnets",
  "ipType": "ipv4"
}
```

#### Create a public interface

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "create_public_interface",
    "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m3"
  }'
```

```json
{
  "action": "create_public_interface",
  "ipId": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m3"
}
```

#### Create a private network interface

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "create_private_interface",
    "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m4",
    "ipAddress": "10.42.0.10"
  }'
```

```json
{
  "action": "create_private_interface",
  "subnetId": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m4",
  "ipAddress": "10.42.0.10"
}
```

#### Delete a non-primary interface

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "delete_interface",
    "interfaceName": "net1"
  }'
```

```json
{
  "action": "delete_interface",
  "interfaceName": "net1"
}
```

#### Delete the primary interface

```bash
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/network" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "delete_primary_interface",
    "confirm": true
  }'
```

```json
{
  "action": "delete_primary_interface",
  "confirm": true
}
```

### Response Schema

- `subnets` (array<object>, required)
- `subnets[].id` (string,null, required) Example: `subnet_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `subnets[].parentCidr` (string,null, required) Example: `203.0.113.0/24`
- `subnets[].isCurrentNetwork` (boolean, required) Example: `true`
- `subnets[].availableCount` (integer, required) Example: `2`
- `subnets[].ips` (array<object>, required)
- `subnets[].ips[].id` (string,null, required) Example: `ip_01hxa3b4c5d6e7f8g9h0j1k2m3`
- `subnets[].ips[].ip` (string, required) Example: `203.0.113.10`
- `subnets[].ips[].status` (string, required) Example: `available`
- `subnets[].ips[].subnet` (object,null, required) Example: `null`

### Responses

#### 200 - Network action completed or subnet availability returned.
```json
{
  "subnets": [
    {
      "id": "subnet_01hxa3b4c5d6e7f8g9h0j1k2m3",
      "parentCidr": "203.0.113.0/24",
      "isCurrentNetwork": true,
      "availableCount": 2,
      "ips": [
        {
          "id": "ip_01hxa3b4c5d6e7f8g9h0j1k2m3",
          "ip": "203.0.113.10",
          "status": "available",
          "subnet": null
        }
      ]
    }
  ]
}
```

#### 202 - Network action queued and should be polled.
```json
{
  "operation": {
    "status": "queued",
    "jobId": "job_01hxa3b4c5d6e7f8g9h0j1k2m3",
    "pollUrl": "/api/jobs/job_01hxa3b4c5d6e7f8g9h0j1k2m3"
  }
}
```

#### 400 - Invalid request. The response body is an RFC 7807 Problem Details document.
```json
{
  "type": "https://developer.hostup.se/errors/invalid_request",
  "title": "Invalid request",
  "status": 400,
  "detail": "The request body failed validation.",
  "code": "invalid_request",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z",
  "errors": [
    {
      "pointer": "/items/0/domainName",
      "detail": "`domainName` is required.",
      "code": "invalid_request"
    }
  ]
}
```

#### 401 - Unauthorized. Authentication is required.
```json
{
  "type": "https://developer.hostup.se/errors/unauthorized",
  "title": "Unauthorized",
  "status": 401,
  "detail": "Authentication is required.",
  "code": "unauthorized",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 403 - Forbidden. The caller lacks a required scope or does not own the resource.
```json
{
  "type": "https://developer.hostup.se/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "The caller lacks a required scope or does not own the resource.",
  "code": "forbidden",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 404 - Not found. The resource does not exist or is not owned by the caller.
```json
{
  "type": "https://developer.hostup.se/errors/not_found",
  "title": "Not found",
  "status": 404,
  "detail": "The requested resource could not be found.",
  "code": "not_found",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 429 - Rate limited. Retry after the limit resets. 429 responses include `Retry-After` seconds plus `X-RateLimit-*` headers.
```json
{
  "type": "https://developer.hostup.se/errors/rate_limit_exceeded",
  "title": "Too many requests",
  "status": 429,
  "detail": "Too many requests. Retry after the limit resets.",
  "code": "rate_limit_exceeded",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```

#### 500 - Internal error. Retry later or contact support if the issue persists.
```json
{
  "type": "https://developer.hostup.se/errors/internal_error",
  "title": "Internal server error",
  "status": 500,
  "detail": "An unexpected error occurred. Retry later or contact support if the issue persists.",
  "code": "internal_error",
  "instance": "/api/v2/resource",
  "requestId": "req_01hxa3b4c5d6e7f8g9h0j1k2m3",
  "timestamp": "2026-04-27T12:34:56.000Z"
}
```
