# Create a cost alert

Source: https://docs.levelfour.ai/api-reference/cost-alerts/post-cost-alerts


## POST /api/v1/cost-alerts

### Authentication

Send `Authorization: Bearer <token>`.

### Request body

Required. Content type `application/json`.

- `name` (string, required)
- `params` (object, required)
  - Variant 1: BudgetParams
    - `kind` (`budget`, default `budget`)
    - `budget` (number or string, required)
    - `reset` (one of `monthly`, `quarterly`, required)
    - `rules` (array of object, required)
      - `amount` (number or string, required)
      - `unit` (one of `percent`, `absolute`, required)
      - `window` (one of `within`, `any`, default `any`)
      - `days` (integer, nullable)
      - `reference` (one of `start_of_month`, `end_of_month`, nullable)
    - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
  - Variant 2: ChangesParams
    - `kind` (`changes`, default `changes`)
    - `amount` (number or string, required)
    - `comparison` (one of `same_days_previous_week`, `same_days_previous_month`, `previous_7_days`, required)
    - `floor` (number or string, nullable)
    - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
  - Variant 3: CommitmentParams
    - `kind` (`commitment`, default `commitment`)
    - `watch` (one of `expiry`, `lapsed`, `utilization`, `saturation`, `contract_overage`, required)
    - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
    - `threshold` (number or string, default `30`)
    - `coverage_below` (number or string, default `80`)
- `source_id` (string, required)
- `recipients` (array of object, required)
  - `name` (string, required)
  - `email` (string, required)
  - `member` (boolean, required)
- `slack_channel_ids` (array of string, nullable): Slack channel ids to post in, public or private. Omitted, the alert takes the organization's default channel when one is set; an empty list posts in no channel
- `slack_channel` (string, nullable): Deprecated and never read: use slack_channel_ids

### Responses

#### 201: Successful Response

- `success` (boolean, default `true`)
- `timestamp` (date-time string)
- `data` (object, required)
  - `id` (string, required)
  - `name` (string, required)
  - `params` (object, required)
    - Variant 1: BudgetParams
      - `kind` (`budget`, default `budget`)
      - `budget` (string, required)
      - `reset` (one of `monthly`, `quarterly`, required)
      - `rules` (array of object, required)
      - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
    - Variant 2: ChangesParams
      - `kind` (`changes`, default `changes`)
      - `amount` (string, required)
      - `comparison` (one of `same_days_previous_week`, `same_days_previous_month`, `previous_7_days`, required)
      - `floor` (string, nullable)
      - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
    - Variant 3: CommitmentParams
      - `kind` (`commitment`, default `commitment`)
      - `watch` (one of `expiry`, `lapsed`, `utilization`, `saturation`, `contract_overage`, required)
      - `cost_basis` (one of `unblended`, `blended`, `amortized`, `net_unblended`, `net_amortized`, default `net_amortized`)
      - `threshold` (string, default `30`)
      - `coverage_below` (string, default `80`)
  - `source_id` (string, required)
  - `recipients` (array of object, required)
    - `name` (string, required)
    - `email` (string, required)
    - `member` (boolean, required)
  - `slack_channels` (array of object): The Slack channels this alert posts in, each once per firing
    - `id` (string, required)
    - `name` (string, required): The channel's name when the alert was saved, without the #
  - `slack_channel` (string, nullable): Deprecated and always null: read slack_channels
  - `enabled` (boolean, required)
  - `paused_by` (string, nullable)
  - `sent_to_me` (boolean, default `false`)
  - `watching` (array of object): The live state of each thing this alert watches. Empty until a sweep has measured it
    - `key` (string, required): Empty for a rule that watches one thing, the slice for a split rule, the commitment id for a commitment rule
    - `state` (one of `ok`, `pending`, `firing`, required): pending is a crossing waiting for a second sweep to agree; firing has been announced
    - `period` (string, nullable): The period the firing was announced for
    - `observed_usd` (number, nullable): The last figure measured: dollars for a spend rule, days or a percentage for a commitment rule

#### Errors

- `400`: Bad Request
- `401`: Authentication Error
- `403`: Authorization Error
- `404`: Not Found
- `409`: Conflict
- `422`: Validation Error
- `429`: Rate Limit Exceeded
- `500`: Internal Server Error

Body of `400`, `401`, `403`, `404`, `409`, `422`, `429`, `500`:

- `success` (`false`, required)
- `error` (object, required)
  - `code` (string, required)
  - `message` (string, required)
  - `details` (any)
- `timestamp` (date-time string, required)
