*Cloud › Services*

# Update service settings

```http
PATCH https://devapi.dispralabs.com/v1/cloud/services/:svc/settings
```

Changes any of the service's settings in one step. Send `base_generation` (the `generation` you read) and only the fields you change.

The answer says how it applies: `applied_now` (health check, disk raised), or `needs_redeploy` (source, build, start, size, replicas). Send `redeploy: 1` to deploy at once. If someone changed the settings since you read them, the update is refused with `stale_generation`.

Needs a key with `full` access.

- **Authentication:** Secret key (send it as `Authorization: Bearer <key>`)
- **Idempotency:** Safe to retry. Send an `Idempotency-Key` header and repeated calls within 24 hours return the first result.

## Parameters

- `svc` (string, required): The service's id. Example: `svc_01jdk3n2f4g6h8j0k2l4z6x8ca`
- `base_generation` (number, required): The generation you read. Example: `7`
- `redeploy` (number, optional): 1 deploys after saving. Example: `1`
- `name` (string, optional): A new name. Example: `api`
- `source_kind` (string, optional): repo or image. Example: `image`
- `image_ref` (string, optional): The image, for an image service. Example: `ghcr.io/acme/api:1.4.2`
- `branch` (string, optional): The branch to deploy from.
- `root_dir` (string, optional): The folder of the repository to build.
- `build_cmd` (string, optional): The build command.
- `start_cmd` (string, optional): The start command. Example: `node dist/server.js`
- `restart_policy` (string, optional): always, on_failure or never.
- `cpu_millis` (number, optional): CPU per replica in millicores.
- `memory_mb` (number, optional): Memory per replica in MB.
- `disk_mb` (number, optional): Temporary disk per replica, whole GB in MB.
- `replicas` (number, optional): Replicas, 1 to 10. Example: `2`
- `healthcheck_path` (string, optional): The health check path, or null to clear it. Example: `/healthz`
- `healthcheck_timeout_s` (number, optional): Seconds before one check fails, or null for the default.

## Returns

- **200**: generation, apply (applied_now or needs_redeploy) and dep when a deployment started.

## Errors

| Status | Code | When |
|---|---|---|
| 400 | [invalid_request](https://docs.dispralabs.com/errors.md#invalid_request) | A field is missing or not valid. The message names it. |
| 404 | [not_found](https://docs.dispralabs.com/errors.md#not_found) | No such object in the key's project (or environment). |
| 409 | [stale_generation](https://docs.dispralabs.com/errors.md#stale_generation) | Someone changed it since you read it: read it again and retry. |
| 409 | [service_replicas_volume](https://docs.dispralabs.com/errors.md#service_replicas_volume) | A service with a volume runs one replica. |
| 409 | [account_frozen](https://docs.dispralabs.com/errors.md#account_frozen) | The workspace is out of credits: add credits on the dashboard to create, change or deploy. |

## Request samples

### Dispra Cloud CLI

```bash
dcloud api PATCH /v1/cloud/services/svc_01jdk3n2f4g6h8j0k2l4z6x8ca/settings --data '{"base_generation":7,"redeploy":1,"name":"api","source_kind":"image","image_ref":"ghcr.io/acme/api:1.4.2","start_cmd":"node dist/server.js","replicas":2,"healthcheck_path":"/healthz"}'
```

### cURL

```bash
curl -X PATCH "https://devapi.dispralabs.com/v1/cloud/services/svc_01jdk3n2f4g6h8j0k2l4z6x8ca/settings" \
  -H "Authorization: Bearer dsp_live_YOUR_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"base_generation":7,"redeploy":1,"name":"api","source_kind":"image","image_ref":"ghcr.io/acme/api:1.4.2","start_cmd":"node dist/server.js","replicas":2,"healthcheck_path":"/healthz"}'
```

### Node

```javascript
const res = await fetch("https://devapi.dispralabs.com/v1/cloud/services/svc_01jdk3n2f4g6h8j0k2l4z6x8ca/settings", {
  method: "PATCH",
  headers: { Authorization: "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({
    "base_generation": 7,
    "redeploy": 1,
    "name": "api",
    "source_kind": "image",
    "image_ref": "ghcr.io/acme/api:1.4.2",
    "start_cmd": "node dist/server.js",
    "replicas": 2,
    "healthcheck_path": "/healthz"
  }),
});
console.log(await res.json());
```

### Python

```python
import uuid, requests
res = requests.request("PATCH", "https://devapi.dispralabs.com/v1/cloud/services/svc_01jdk3n2f4g6h8j0k2l4z6x8ca/settings", headers={"Authorization": "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": str(uuid.uuid4())}, json={
  "base_generation": 7,
  "redeploy": 1,
  "name": "api",
  "source_kind": "image",
  "image_ref": "ghcr.io/acme/api:1.4.2",
  "start_cmd": "node dist/server.js",
  "replicas": 2,
  "healthcheck_path": "/healthz"
})
print(res.json())
```

### Go

```go
body := strings.NewReader(`{"base_generation":7,"redeploy":1,"name":"api","source_kind":"image","image_ref":"ghcr.io/acme/api:1.4.2","start_cmd":"node dist/server.js","replicas":2,"healthcheck_path":"/healthz"}`)
req, _ := http.NewRequest("PATCH", "https://devapi.dispralabs.com/v1/cloud/services/svc_01jdk3n2f4g6h8j0k2l4z6x8ca/settings", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer dsp_live_YOUR_KEY")
req.Header.Set("Idempotency-Key", uuid.NewString())
res, _ := http.DefaultClient.Do(req)
```

## Responses

### 200

```json
{}
```

### 400 invalid_request

```json
{
  "error": {
    "code": "invalid_request",
    "message": "A field is missing or not valid. The message names it.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 404 not_found

```json
{
  "error": {
    "code": "not_found",
    "message": "No such object in the key's project (or environment).",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 409 stale_generation

```json
{
  "error": {
    "code": "stale_generation",
    "message": "Someone changed it since you read it: read it again and retry.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 409 service_replicas_volume

```json
{
  "error": {
    "code": "service_replicas_volume",
    "message": "A service with a volume runs one replica.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 409 account_frozen

```json
{
  "error": {
    "code": "account_frozen",
    "message": "The workspace is out of credits: add credits on the dashboard to create, change or deploy.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```
