# Spend Alerts

## List organization spend alerts

`SpendAlertListPage admin().organization().spendAlerts().list(SpendAlertListParamsparams = SpendAlertListParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**get** `/organization/spend_alerts`

Lists organization spend alerts.

### Parameters

- `SpendAlertListParams params`

  - `Optional<String> after`

    Cursor for pagination. Provide the ID of the last spend alert from the previous response to fetch the next page.

  - `Optional<String> before`

    Cursor for pagination. Provide the ID of the first spend alert from the previous response to fetch the previous page.

  - `Optional<Long> limit`

    A limit on the number of spend alerts to return. Defaults to 20.

  - `Optional<Order> order`

    Sort order for the returned spend alerts.

    - `ASC("asc")`

    - `DESC("desc")`

### Returns

- `class OrganizationSpendAlert:`

  Represents a spend alert configured at the organization level.

  - `String id`

    The identifier, which can be referenced in API endpoints.

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `JsonValue; object_ "organization.spend_alert"constant`

    The object type, which is always `organization.spend_alert`.

    - `ORGANIZATION_SPEND_ALERT("organization.spend_alert")`

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Example

```java
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.spendalerts.SpendAlertListPage;
import com.openai.models.admin.organization.spendalerts.SpendAlertListParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        SpendAlertListPage page = client.admin().organization().spendAlerts().list();
    }
}
```

#### Response

```json
{
  "data": [
    {
      "id": "id",
      "currency": "USD",
      "interval": "month",
      "notification_channel": {
        "recipients": [
          "string"
        ],
        "type": "email",
        "subject_prefix": "subject_prefix"
      },
      "object": "organization.spend_alert",
      "threshold_amount": 0
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}
```

## Create organization spend alert

`OrganizationSpendAlert admin().organization().spendAlerts().create(SpendAlertCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

**post** `/organization/spend_alerts`

Creates an organization spend alert.

### Parameters

- `SpendAlertCreateParams params`

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Returns

- `class OrganizationSpendAlert:`

  Represents a spend alert configured at the organization level.

  - `String id`

    The identifier, which can be referenced in API endpoints.

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `JsonValue; object_ "organization.spend_alert"constant`

    The object type, which is always `organization.spend_alert`.

    - `ORGANIZATION_SPEND_ALERT("organization.spend_alert")`

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Example

```java
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert;
import com.openai.models.admin.organization.spendalerts.SpendAlertCreateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        SpendAlertCreateParams params = SpendAlertCreateParams.builder()
            .currency(SpendAlertCreateParams.Currency.USD)
            .interval(SpendAlertCreateParams.Interval.MONTH)
            .notificationChannel(SpendAlertCreateParams.NotificationChannel.builder()
                .addRecipient("string")
                .build())
            .thresholdAmount(0L)
            .build();
        OrganizationSpendAlert organizationSpendAlert = client.admin().organization().spendAlerts().create(params);
    }
}
```

#### Response

```json
{
  "id": "id",
  "currency": "USD",
  "interval": "month",
  "notification_channel": {
    "recipients": [
      "string"
    ],
    "type": "email",
    "subject_prefix": "subject_prefix"
  },
  "object": "organization.spend_alert",
  "threshold_amount": 0
}
```

## Retrieve organization spend alert

`OrganizationSpendAlert admin().organization().spendAlerts().retrieve(SpendAlertRetrieveParamsparams = SpendAlertRetrieveParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**get** `/organization/spend_alerts/{alert_id}`

Retrieves an organization spend alert.

### Parameters

- `SpendAlertRetrieveParams params`

  - `Optional<String> alertId`

### Returns

- `class OrganizationSpendAlert:`

  Represents a spend alert configured at the organization level.

  - `String id`

    The identifier, which can be referenced in API endpoints.

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `JsonValue; object_ "organization.spend_alert"constant`

    The object type, which is always `organization.spend_alert`.

    - `ORGANIZATION_SPEND_ALERT("organization.spend_alert")`

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Example

```java
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert;
import com.openai.models.admin.organization.spendalerts.SpendAlertRetrieveParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        OrganizationSpendAlert organizationSpendAlert = client.admin().organization().spendAlerts().retrieve("alert_id");
    }
}
```

#### Response

```json
{
  "id": "id",
  "currency": "USD",
  "interval": "month",
  "notification_channel": {
    "recipients": [
      "string"
    ],
    "type": "email",
    "subject_prefix": "subject_prefix"
  },
  "object": "organization.spend_alert",
  "threshold_amount": 0
}
```

## Update organization spend alert

`OrganizationSpendAlert admin().organization().spendAlerts().update(SpendAlertUpdateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

**post** `/organization/spend_alerts/{alert_id}`

Updates an organization spend alert.

### Parameters

- `SpendAlertUpdateParams params`

  - `Optional<String> alertId`

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Returns

- `class OrganizationSpendAlert:`

  Represents a spend alert configured at the organization level.

  - `String id`

    The identifier, which can be referenced in API endpoints.

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `JsonValue; object_ "organization.spend_alert"constant`

    The object type, which is always `organization.spend_alert`.

    - `ORGANIZATION_SPEND_ALERT("organization.spend_alert")`

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Example

```java
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlert;
import com.openai.models.admin.organization.spendalerts.SpendAlertUpdateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        SpendAlertUpdateParams params = SpendAlertUpdateParams.builder()
            .alertId("alert_id")
            .currency(SpendAlertUpdateParams.Currency.USD)
            .interval(SpendAlertUpdateParams.Interval.MONTH)
            .notificationChannel(SpendAlertUpdateParams.NotificationChannel.builder()
                .addRecipient("string")
                .build())
            .thresholdAmount(0L)
            .build();
        OrganizationSpendAlert organizationSpendAlert = client.admin().organization().spendAlerts().update(params);
    }
}
```

#### Response

```json
{
  "id": "id",
  "currency": "USD",
  "interval": "month",
  "notification_channel": {
    "recipients": [
      "string"
    ],
    "type": "email",
    "subject_prefix": "subject_prefix"
  },
  "object": "organization.spend_alert",
  "threshold_amount": 0
}
```

## Delete organization spend alert

`OrganizationSpendAlertDeleted admin().organization().spendAlerts().delete(SpendAlertDeleteParamsparams = SpendAlertDeleteParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**delete** `/organization/spend_alerts/{alert_id}`

Deletes an organization spend alert.

### Parameters

- `SpendAlertDeleteParams params`

  - `Optional<String> alertId`

### Returns

- `class OrganizationSpendAlertDeleted:`

  Confirmation payload returned after deleting an organization spend alert.

  - `String id`

    The deleted spend alert ID.

  - `boolean deleted`

    Whether the spend alert was deleted.

  - `JsonValue; object_ "organization.spend_alert.deleted"constant`

    Always `organization.spend_alert.deleted`.

    - `ORGANIZATION_SPEND_ALERT_DELETED("organization.spend_alert.deleted")`

### Example

```java
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.spendalerts.OrganizationSpendAlertDeleted;
import com.openai.models.admin.organization.spendalerts.SpendAlertDeleteParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        OrganizationSpendAlertDeleted organizationSpendAlertDeleted = client.admin().organization().spendAlerts().delete("alert_id");
    }
}
```

#### Response

```json
{
  "id": "id",
  "deleted": true,
  "object": "organization.spend_alert.deleted"
}
```

## Domain Types

### Organization Spend Alert

- `class OrganizationSpendAlert:`

  Represents a spend alert configured at the organization level.

  - `String id`

    The identifier, which can be referenced in API endpoints.

  - `Currency currency`

    The currency for the threshold amount.

    - `USD("USD")`

  - `Interval interval`

    The time interval for evaluating spend against the threshold.

    - `MONTH("month")`

  - `NotificationChannel notificationChannel`

    Email notification settings for a spend alert.

    - `List<String> recipients`

      Email addresses that receive the spend alert notification.

    - `JsonValue; type "email"constant`

      The notification channel type. Currently only `email` is supported.

      - `EMAIL("email")`

    - `Optional<String> subjectPrefix`

      Optional subject prefix for alert emails.

  - `JsonValue; object_ "organization.spend_alert"constant`

    The object type, which is always `organization.spend_alert`.

    - `ORGANIZATION_SPEND_ALERT("organization.spend_alert")`

  - `long thresholdAmount`

    The alert threshold amount, in cents.

### Organization Spend Alert Deleted

- `class OrganizationSpendAlertDeleted:`

  Confirmation payload returned after deleting an organization spend alert.

  - `String id`

    The deleted spend alert ID.

  - `boolean deleted`

    Whether the spend alert was deleted.

  - `JsonValue; object_ "organization.spend_alert.deleted"constant`

    Always `organization.spend_alert.deleted`.

    - `ORGANIZATION_SPEND_ALERT_DELETED("organization.spend_alert.deleted")`
