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

# Update Circuit Breaker Settings

> Updates circuit breaker settings for an API proxy. Circuit breaker prevents cascading failures by stopping requests to failing backends.

## Endpoint

```
PATCH /apiops/projects/{projectName}/apiProxies/{apiProxyName}/settings/circuit-breaker/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value            | Required |
| ------------- | ---------------- | -------- |
| Authorization | Bearer {token}   | Yes      |
| Content-Type  | application/json | Yes      |

### Path Parameters

| Parameter    | Type   | Required | Description    |
| ------------ | ------ | -------- | -------------- |
| projectName  | string | Yes      | Project name   |
| apiProxyName | string | Yes      | API Proxy name |

### Request Body

#### Full JSON Body Example

```json theme={null}
{
  "circuitBreakerEnabled": true,
  "errorWindow": 60,
  "errorThresholdValue": 5,
  "enumErrorThresholdType": "COUNT",
  "sleepWindow": 30,
  "halfOpenEnabled": true,
  "deploy": false,
  "deployTargetEnvironmentNameList": []
}
```

#### Request Body Fields

| Field                           | Type           | Required | Default | Description                                                        |
| ------------------------------- | -------------- | -------- | ------- | ------------------------------------------------------------------ |
| circuitBreakerEnabled           | boolean        | No       | -       | Enable/disable circuit breaker                                     |
| errorWindow                     | integer        | No       | -       | Time window in seconds to count errors                             |
| errorThresholdValue             | integer        | No       | -       | Error threshold value (count or percentage)                        |
| enumErrorThresholdType          | string         | No       | -       | Error threshold type                                               |
| sleepWindow                     | integer        | No       | -       | Sleep window in seconds (circuit breaker stays open)               |
| halfOpenEnabled                 | boolean        | No       | -       | Enable half-open state (test requests)                             |
| deploy                          | boolean        | No       | false   | If true, deploy the API proxy after saving changes                 |
| deployTargetEnvironmentNameList | array\[string] | No       | -       | List of environment names to deploy to (required when deploy=true) |

### EnumErrorThresholdType

* `COUNT` - Error threshold is a count (e.g., 5 errors)
* `PERCENT` - Error threshold is a percentage (e.g., 50% error rate)

**Note:** All fields are optional. Only provided fields are updated.

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true
}
```

When `deploy=true` is specified:

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "deploymentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Deployment successful"
      }
    ]
  }
}
```

#### Response Fields

| Field                              | Type    | Description                                       |
| ---------------------------------- | ------- | ------------------------------------------------- |
| success                            | boolean | Indicates if the request was successful           |
| deploymentResult                   | object  | Deployment result (only present when deploy=true) |
| deploymentResult.success           | boolean | Overall deployment success                        |
| deploymentResult.deploymentResults | array   | Individual environment deployment results         |

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "Invalid circuit breaker settings"
}
```

### Error Response (401 Unauthorized)

```json theme={null}
{
  "error": "unauthorized_client",
  "error_description": "Invalid token"
}
```

### Error Response (404 Not Found)

```json theme={null}
{
  "error": "not_found",
  "error_description": "ApiProxy (name: MyAPI) was not found!"
}
```

## cURL Example

### Example 1: Enable Circuit Breaker with Count Threshold

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/circuit-breaker/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "circuitBreakerEnabled": true,
    "errorWindow": 60,
    "errorThresholdValue": 5,
    "enumErrorThresholdType": "COUNT",
    "sleepWindow": 30,
    "halfOpenEnabled": true
  }'
```

### Example 2: Enable Circuit Breaker with Percentage Threshold

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/circuit-breaker/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "circuitBreakerEnabled": true,
    "errorWindow": 120,
    "errorThresholdValue": 50,
    "enumErrorThresholdType": "PERCENT",
    "sleepWindow": 60,
    "halfOpenEnabled": false
  }'
```

### Example 3: Save and Deploy

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/circuit-breaker/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "circuitBreakerEnabled": true,
    "errorWindow": 60,
    "errorThresholdValue": 5,
    "enumErrorThresholdType": "COUNT",
    "sleepWindow": 30,
    "halfOpenEnabled": true,
    "deploy": true,
    "deployTargetEnvironmentNameList": ["production"]
  }'
```

## Notes and Warnings

* **Error Window**: Time window in seconds during which errors are counted
* **Error Threshold**: When threshold is reached, circuit breaker opens
* **Sleep Window**: Duration in seconds that circuit breaker stays open before attempting half-open
* **Half-Open**: When enabled, allows test requests to check if backend recovered
* **Threshold Type**: `COUNT` uses absolute number, `PERCENT` uses percentage of requests
* **Deploy**: When `deploy=true`, the API proxy is automatically deployed to the specified environments after saving

## Permissions

User must have **`API_MANAGEMENT` + `MANAGE`** permission in the project.

## Related Documentation

* [Update Connection Settings](/api-reference/api-proxies/settings/update-connection-settings) - Update connection settings
* [Get API Proxy](/api-reference/api-proxies/crud/get-api-proxy) - Get API proxy details
