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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Audiences

> Rule-based groups that update as profiles change, addressed with audience_id. Filter on profile fields, nest AND and OR rules, and scope sends to a tenant.

An audience is a group Courier maintains. You write rules, and membership updates as profiles change.

Target one on a send with `audience_id`:

```json theme={null}
{
  "to": { "audience_id": "active-business-users" }
}
```

Create or update an audience with [`PUT /audiences/{audience_id}`](https://www.courier.com/docs/api-reference/audiences/update-an-audience), passing a `filter`. See the [Audiences API](https://www.courier.com/docs/api-reference/audiences/get-an-audience.md) for the full schema.

## How it works

Each condition in a filter names a profile `path`, an `operator`, and a `value`. The `path` starts at the profile root, so a profile's `custom.plan` field is `custom.plan`, with no `profile.` prefix.

Comparisons match the value's type as well as its content. A field stored as the number `0` matches `"value": 0` but not `"value": "0"`, so send `value` in the same type the profile stores.

### Audience operators

Console labels and their API values:

| Category | Console | Code | Use case |
| - | - | - | - |
| Equality | is | `EQ` | Match an exact value (a plan, role, or status) |
| | is not | `NEQ` | Exclude a value |
| String | includes | `INCLUDES` | Substring match (email domain, title) |
| | does not include | `OMIT` | Exclude a substring |
| | starts with | `STARTS_WITH` | Prefix match |
| | ends with | `ENDS_WITH` | Suffix match (`@acme-corp.com`) |
| Numeric | is greater than | `GT` | Above a threshold |
| | is greater than or equal to | `GTE` | At or above a limit |
| | less than | `LT` | Below a threshold |
| | less than or equal to | `LTE` | At or below a cap |
| Date | is after | `IS_AFTER` | After a date |
| | is before | `IS_BEFORE` | Before a date |
| Existence | exists | `EXISTS` | The field is present |

### Combining conditions

A filter is a group with an `operator` and a `filters` array. Use `AND` so every condition must match, or `OR` so at least one must. A condition inside `filters` can be another group. That nests rules like "on the pro plan AND (admin OR owner)":

```json theme={null}
{
  "filter": {
    "operator": "AND",
    "filters": [
      { "operator": "EQ", "path": "custom.plan", "value": "pro" },
      {
        "operator": "OR",
        "filters": [
          { "operator": "EQ", "path": "custom.role", "value": "admin" },
          { "operator": "EQ", "path": "custom.role", "value": "owner" }
        ]
      }
    ]
  }
}
```

### How membership works

Courier pre-computes membership instead of evaluating every rule against every profile at send time. When a profile changes, Courier updates whether that user belongs to each audience. Changing an audience's rules starts a rebuild of its membership list.

At send time, Courier reads the stored membership. A rebuild of a large audience can take many minutes. A send during the rebuild reads a partially updated list. Wait for membership to settle before a large send. Check [`GET /audiences/{audience_id}`](https://www.courier.com/docs/api-reference/audiences/get-an-audience) and spot-check [`GET /audiences/{audience_id}/members`](https://www.courier.com/docs/api-reference/audiences/list-audience-members). A [list](https://www.courier.com/docs/recipients/lists-and-audiences/lists.md) member, by contrast, is present the moment you add them.

### Scoping a send to a tenant

`context.tenant_id` on a send controls branding, preferences, and template variables for that tenant. It does **not** restrict which audience members receive the message. To send only to users in one tenant, add an inline `filters` array on the recipient. Use the `MEMBER_OF` operator with `path: tenant_id`:

```json theme={null}
{
  "to": {
    "audience_id": "active-business-users",
    "filters": [
      { "operator": "MEMBER_OF", "path": "tenant_id", "value": "acme-corp" }
    ]
  },
  "context": { "tenant_id": "acme-corp" }
}
```

A user must have tenant membership to pass the filter. Set it with [`PUT /users/{user_id}/tenants/{tenant_id}`](https://www.courier.com/docs/api-reference/tenant-memberships/add-a-user-to-a-tenant).

## FAQ

> [accordion] Should I use an audience or a list?
>
> Use an audience when membership follows from profile data and should update itself, like all pro-plan users. Use a [list](https://www.courier.com/docs/recipients/lists-and-audiences/lists.md) when you decide membership by hand.

> [accordion] Can I nest AND and OR in one filter?
>
> Any condition in a `filters` array can be a group with its own `operator` and `filters`.
