# POST /api/v1/credit/lines/{credit_line_id}/covenants

> Add a covenant to a line

- **Tag:** credit
- **Operation ID:** `create_line_covenant`

## Description

Writes a covenant the nightly sweep tests against the borrower's books from tonight on. `comparison` defaults to the kind's own (gte for the minimums, lte for max_leverage) and is required for `custom_ratio`, which also needs a numerator and a denominator selector naming at least one ledger id, type or concept (`400` otherwise). A line with no `merchant_business_id` accepts covenants but every check reads `unmeasured` until the borrower's business is linked.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Parameters

- `credit_line_id` (path, string, required) — Credit line ID. The lender's routes need a line this business operates; the borrower's read also accepts a line it borrows on.

## Request body

Schema: `CovenantCreate`

- `kind` (string · required) (one of: min_cash, max_leverage, min_dscr, min_inventory_turns, min_current_ratio, custom_ratio) — min_cash (cash ledgers' balance, currency), max_leverage (total liabilities / total equity), min_dscr (debt service coverage, the underwriting measurer), min_inventory_turns (cost of goods sold over 365 days / average inventory), min_current_ratio (current assets / current liabilities) or custom_ratio (two selectors).
- `label` (string) — How the console names it.
- `threshold` (number · required) — Whole currency units for min_cash; a decimal ratio otherwise.
- `comparison` (string) — value <comparison> threshold passes. Defaults to the kind's own (gte for the minimums, lte for max_leverage); required for custom_ratio.
- `warn_band_bps` (integer) — A pass within this share of the threshold warns (1000 = 10%).
- `numerator_selector` (LedgerSelector) — custom_ratio only: the numerator's ledgers.
- `denominator_selector` (LedgerSelector) — custom_ratio only: the denominator's ledgers.
- `active` (boolean) — Checked nightly while true.
- `notes` (string) — Operator notes.

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_CovenantResponse_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (CovenantResponse)

### 400 — Bad Request - Invalid input

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 401 — Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 403 — Forbidden - Insufficient permissions

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 404 — Not Found - Resource does not exist

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 422 — Validation Error

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/covenants' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "kind": "min_cash",
  "threshold": 0
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/covenants', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "kind": "min_cash",
  "threshold": 0
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {'kind': 'min_cash', 'threshold': 0}

response = httpx.post("https://api.ondayzero.com/api/v1/credit/lines/{credit_line_id}/covenants", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/credit/create-line-covenant
- OpenAPI slice: https://www.ondayzero.com/docs/reference/credit/create-line-covenant/openapi.json
- Other endpoints in **credit**: https://www.ondayzero.com/docs/reference/credit (markdown bundle: https://www.ondayzero.com/docs/reference/credit.md, OpenAPI: https://www.ondayzero.com/docs/reference/credit/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
