Skip to content

Calculate record overlap between two criteria sets

POST
/v1/discovery/overlap
curl --request POST \
--url https://dev-api.infiniteaudience.ai/v1/discovery/overlap \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "a": { "segment_id": "seg_1a2b3c" }, "b": { "audience_id": "aud_9z8y7x" } }'

Computes the number and percentage of records that appear in both of two criteria sets, plus side-by-side demographic deltas. Requires ‘discovery’ scope. Each side (a and b) independently accepts exactly one discovery input shape (filters, filter_groups, segment_id, audience_id, or segment_ids + set_logic) — the legacy flat audience_id_a / audience_id_b fields are also still accepted. A side that provides more than one shape, or combines the structured object with its legacy field, returns 400 AMBIGUOUS_INPUT. A side that provides nothing returns 400 NO_INPUT_SPECIFIED. Each side preserves full group/combinator structure independently: if a side is a segment, audience, or filter groups, each segment’s own AND/OR groups are evaluated intact, multiple composed segments are combined by set_logic, and an audience’s excluded segments are always subtracted (AND NOT), regardless of set_logic — before the two sides are joined for the overlap count.

Media typeapplication/json
object
a

Side A. Mutually exclusive with audience_id_a.

object
filters

Flat filter list.

Array<object>

A single filter condition for audience discovery or job execution

object
field
required

The canonical attribute name (e.g. ‘age’, ‘state’)

string
op
required

Comparison operator

string
Allowed values: = != < <= > >= IN NOT IN BETWEEN LIKE ARRAY_CONTAINS ARRAY_CONTAINS_ANY IS NULL IS NOT NULL
value
One of:
string
filter_groups

Compound boolean filter groups.

Array<object>

A group of Filter conditions. All filters within a single group are always ANDed together — there is no per-group intra-operator. The combinator attribute is an inter-group operator: it controls how this group is joined to the immediately preceding group in the array. The combinator on the first group (index 0) is always ignored.

Example — (city = "NYC" AND state = "NY") OR (state = "CA"):

  { "id": "g1", "filters": [{"field":"city","op":"=","value":"NYC"},
                            {"field":"state","op":"=","value":"NY"}],
    "combinator": "AND" },
  { "id": "g2", "filters": [{"field":"state","op":"=","value":"CA"}],
    "combinator": "OR" }
] ```
Group g1's `combinator` is irrelevant (it is the first group). Group g2's `combinator: "OR"` means the result is `(g1) OR (g2)`.
object
id
required

Stable identifier (UUID or NanoID). Used to track groups across edits.

string
filters
required

One or more filter conditions. All conditions in this array are combined with AND. Provide at least one filter per group.

Array<object>

A single filter condition for audience discovery or job execution

object
field
required

The canonical attribute name (e.g. ‘age’, ‘state’)

string
op
required

Comparison operator

string
Allowed values: = != < <= > >= IN NOT IN BETWEEN LIKE ARRAY_CONTAINS ARRAY_CONTAINS_ANY IS NULL IS NOT NULL
value
One of:
string
combinator
required

Inter-group operator. Joins this group to the previous group in the array. AND narrows the result; OR broadens it. Ignored on the first group (index 0) — that group has no predecessor to join.

string
Allowed values: AND OR
segment_id

ID of a saved segment.

string
audience_id

ID of a saved audience.

string
segment_ids

IDs of multiple segments to combine (requires set_logic).

Array<string>
set_logic

How to combine segment_ids: union = match ANY segment (OR); intersection = match EVERY segment (AND).

string
Allowed values: union intersection
b

Side B. Mutually exclusive with audience_id_b.

object
filters

Flat filter list.

Array<object>

A single filter condition for audience discovery or job execution

object
field
required

The canonical attribute name (e.g. ‘age’, ‘state’)

string
op
required

Comparison operator

string
Allowed values: = != < <= > >= IN NOT IN BETWEEN LIKE ARRAY_CONTAINS ARRAY_CONTAINS_ANY IS NULL IS NOT NULL
value
One of:
string
filter_groups

Compound boolean filter groups.

Array<object>

A group of Filter conditions. All filters within a single group are always ANDed together — there is no per-group intra-operator. The combinator attribute is an inter-group operator: it controls how this group is joined to the immediately preceding group in the array. The combinator on the first group (index 0) is always ignored.

Example — (city = "NYC" AND state = "NY") OR (state = "CA"):

  { "id": "g1", "filters": [{"field":"city","op":"=","value":"NYC"},
                            {"field":"state","op":"=","value":"NY"}],
    "combinator": "AND" },
  { "id": "g2", "filters": [{"field":"state","op":"=","value":"CA"}],
    "combinator": "OR" }
] ```
Group g1's `combinator` is irrelevant (it is the first group). Group g2's `combinator: "OR"` means the result is `(g1) OR (g2)`.
object
id
required

Stable identifier (UUID or NanoID). Used to track groups across edits.

string
filters
required

One or more filter conditions. All conditions in this array are combined with AND. Provide at least one filter per group.

Array<object>

A single filter condition for audience discovery or job execution

object
field
required

The canonical attribute name (e.g. ‘age’, ‘state’)

string
op
required

Comparison operator

string
Allowed values: = != < <= > >= IN NOT IN BETWEEN LIKE ARRAY_CONTAINS ARRAY_CONTAINS_ANY IS NULL IS NOT NULL
value
One of:
string
combinator
required

Inter-group operator. Joins this group to the previous group in the array. AND narrows the result; OR broadens it. Ignored on the first group (index 0) — that group has no predecessor to join.

string
Allowed values: AND OR
segment_id

ID of a saved segment.

string
audience_id

ID of a saved audience.

string
segment_ids

IDs of multiple segments to combine (requires set_logic).

Array<string>
set_logic

How to combine segment_ids: union = match ANY segment (OR); intersection = match EVERY segment (AND).

string
Allowed values: union intersection
audience_id_a

(Legacy) First audience ID. Mutually exclusive with a.

string
audience_id_b

(Legacy) Second audience ID. Mutually exclusive with b.

string
Example
{
"a": {
"segment_id": "seg_1a2b3c"
},
"b": {
"audience_id": "aud_9z8y7x"
}
}

Overlap result with demographic deltas.

Media typeapplication/json
object
a_name
required
string
b_name
required
string
a_count
required
integer
b_count
required
integer
overlap_count
required
integer
overlap_pct
required

Overlap as a percentage of the smaller side.

number
demographic_deltas
required

Side-by-side demographic comparison. Each entry: {metric, label, a, b, delta}.

Array<object>
object
metric
required
string
label
required
string
a
required
number | null
b
required
number | null
delta
required
number | null
distribution_a

Optional paired distribution buckets for side A.

Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
distribution_b

Optional paired distribution buckets for side B.

Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
distribution_field

Attribute the paired distributions are bucketed on.

string
distribution_label

Human-readable label for the distribution attribute.

string
age_distribution_a
Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
age_distribution_b
Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
gender_distribution_a
Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
gender_distribution_b
Array<object>

One bucket of a categorical distribution.

object
label
required
string
count
required
integer
warnings

Present only when at least one side resolves to a non-filter or mixed-subtype composition. Two cases: “One or both sides had no composable segments” when a side’s composition is empty (counts are all 0); or “Demographic breakdowns are not yet available for non-filter or mixed-subtype compositions” when counts/ overlap were computed directly but demographic_deltas could not be (returned as an empty array in that case).

Array<string>
Example
{
"a_name": "CA Homeowners",
"b_name": "TX Families",
"a_count": 1204551,
"b_count": 988102,
"overlap_count": 51233,
"overlap_pct": 5.2,
"demographic_deltas": [
{
"metric": "median_age",
"label": "Median age",
"a": 44,
"b": 39,
"delta": -5
}
]
}

Invalid request — malformed body, missing required attribute, or failed validation. See error and message for details.

Media typeapplication/json
object
error
required

Stable machine-readable error code (e.g. INVALID_STATUS_TRANSITION, BILLING_INSUFFICIENT_BALANCE). Always present.

string
message

Human-readable explanation of the error.

string
code

Alternate machine-readable code — present on some endpoints as an alias for error for backward compatibility.

string
request_id

Opaque support/debug identifier when available.

string
key
additional properties
any
Examples
Examplevalidation_error
{
"error": "Bad Request",
"code": "MISSING_SEGMENTS",
"message": "segment_ids is required for filter audiences."
}

Missing or invalid Bearer token. Obtain one via POST /v1/auth/token. When a token was supplied but rejected, code distinguishes TOKEN_EXPIRED (the token’s lifetime has passed — request a new one via POST /v1/auth/token and retry) from TOKEN_INVALID (malformed or revoked — re-authenticate).

Media typeapplication/json
object
error
required

Stable machine-readable error code (e.g. INVALID_STATUS_TRANSITION, BILLING_INSUFFICIENT_BALANCE). Always present.

string
message

Human-readable explanation of the error.

string
code

Alternate machine-readable code — present on some endpoints as an alias for error for backward compatibility.

string
request_id

Opaque support/debug identifier when available.

string
key
additional properties
any
Examples
{
"error": "Unauthorized: Missing or invalid Authorization header"
}

Token is valid but lacks the required scope for this endpoint. Check the endpoint description for the required scope (discovery, purchase, or account).

Media typeapplication/json
object
error
required

Stable machine-readable error code (e.g. INVALID_STATUS_TRANSITION, BILLING_INSUFFICIENT_BALANCE). Always present.

string
message

Human-readable explanation of the error.

string
code

Alternate machine-readable code — present on some endpoints as an alias for error for backward compatibility.

string
request_id

Opaque support/debug identifier when available.

string
key
additional properties
any
Examples
Examplemissing_scope
{
"error": "SCOPE_REQUIRED",
"message": "This endpoint requires the purchase scope."
}

The underlying BigQuery query failed, or (AGGREGATION_FLOOR_NOT_MET) the result set is too small to return while preserving individual-level privacy. message is always a friendly, client-safe description — the raw BigQuery error is never returned.

Media typeapplication/json
object
error
required

Stable machine-readable error code (e.g. INVALID_STATUS_TRANSITION, BILLING_INSUFFICIENT_BALANCE). Always present.

string
message

Human-readable explanation of the error.

string
code

Alternate machine-readable code — present on some endpoints as an alias for error for backward compatibility.

string
request_id

Opaque support/debug identifier when available.

string
key
additional properties
any
Examples
{
"error": "Bad Gateway",
"code": "AGGREGATION_FLOOR_NOT_MET",
"message": "For privacy reasons, a minimum of 50 records is required to view this information."
}