---
title: "Generate Audience Rule"
method: POST
path: "/v2/campaigns/{id}/audiences/{audience_id}/generate-rule"
tags: ["Campaigns V2"]
---

# Generate Audience Rule

`POST /v2/campaigns/{id}/audiences/{audience_id}/generate-rule`

## Request

- Base URL: `https://api.superwall.com`
- URL: `https://api.superwall.com/v2/campaigns/{id}/audiences/{audience_id}/generate-rule`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `accounts_superwall_token`
  - HTTP bearer

Uses an LLM to turn a natural-language prompt into a structured audience targeting rule (RuleConditions AST). The suggestion is returned for the caller to review and save; it is not persisted by this endpoint. Requires campaigns:write scope.

## Path parameters

- `id` string, required
- `audience_id` string, required

## Request body

- object: Prompt for an AI-generated audience targeting rule
  - `prompt` string, required: Natural-language description of the audience to target

## Response `200`

AI-generated audience targeting rule

- object: AI-generated audience targeting rule
  - `rule_conditions` RuleConditions1, required: The structured targeting rule (RuleConditions AST) produced from the prompt
    - `operator` 'and' | 'or', required
    - `conditions` RuleCondition[], required
      - union
        - object
          - `type` 'condition', required
          - `lhs` union, required
            - object
              - …
            - object
              - …
          - `operator` 'eq' | 'neq' | 'c' | 'nc' | 'gt' | 'gte' | 'lt' | 'lte' | 't' | 'f' | 'null' | 'nnull', required
          - `rhs` union, required
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
        - object
          - `type` 'group', required
          - `operator` 'and' | 'or', required
          - `conditions` RuleCondition[], required
    - `entitlements` object
      - `type` 'entitlement', required
      - `rule` union, required
        - object
          - `type` 'no_active_entitlements', required
        - object
          - `type` 'always_true', required
        - object
          - `type` 'entitlement_conditions', required
          - `conditions` object[], required
            - `type` 'entitlement_condition', required
            - `identifier` string, required
            - `status` 'active' | 'inactive' | 'will_not_renew' | 'in_trial' | 'expired' | 'in_billing_retry', required
        - object
          - `type` 'any_will_not_renew', required
        - object
          - `type` 'any_in_trial', required
        - object
          - `type` 'any_expired_no_active', required
        - object
          - `type` 'any_active_subs_auto_renew_disabled', required
        - object
          - `type` 'any_in_billing_retry', required

## Other responses

- `400`: The request did not match the expected schema | The request was invalid or malformed
- `401`: No API key was provided in the request | The API key does not have a valid format | The API key is invalid or has been revoked | An error occurred while validating the API key | The session cookie is invalid or expired
- `403`: The API key does not have permission to perform this action
- `404`: The requested resource was not found
- `429`: Too many requests have been made in a short period
- `500`: An unexpected error occurred on the server

## Changes

- **2026-10-29** `778a11cd2c15`: 5 warning, 2 info
  - added the new `credentials_missing` enum value to the `anyOf[subschema #2]/code` response property for the response status `400`
  - added the new `credentials_missing` enum value to the `code/anyOf[subschema #1]/` response property for the response status `403`
  - added the new `credentials_missing` enum value to the `code/anyOf[subschema #1]/` response property for the response status `404`
  - added the new `credentials_missing` enum value to the `code/anyOf[subschema #1]/` response property for the response status `429`
  - …3 more
- **2026-09-09** `217c96dc9a29`: 23 breaking, 126 info
  - the `code` response's property type changed from `string` to no type for status `403`
  - the `code` response's property type changed from `string` to no type for status `404`
  - the `code` response's property type changed from `string` to no type for status `429`
  - the `code` response's property type changed from `string` to no type for status `500`
  - …145 more
  - …this revision’s changelog is incomplete

[Operation history](https://skmtc.dev/superwall/apis/superwall-api-v2/changes/v2/campaigns/:id/audiences/:audience_id/generate-rule/post.md)

---

[API](https://skmtc.dev/superwall/apis/superwall-api-v2.md) - [All operations](https://skmtc.dev/superwall/apis/superwall-api-v2/llms.txt) - [OpenAPI document](https://skmtc.dev/superwall/apis/superwall-api-v2/revisions/523b4734dfab?raw)
