{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/zernio-com/json-schema/zernio-com-targeting-spec-schema.json",
  "title": "TargetingSpec",
  "description": "Normalized, platform-agnostic ad-targeting spec. Every field is optional; an empty object targets the platform's default broadest audience.\n\nField names are camelCase and identical across `POST /v1/ads/create` (the `targeting` object), `POST /v1/ads/targeting/reach-estimate`, and `saved_targeting` audiences, so a spec resolved once can be reused verbatim.\n\n**Entity ids** (`regions[].key`, `cities[].key`, `zips[].key`, `metros[].key`, `interests[].id`, `behaviors[].id`) are the platform's opaque identifiers resolved via `GET /v1/ads/targeting/search`. A spec is therefore meaningful only for the platform it was built against.\n\n**Portable fields** carry across platforms: `countries`, `ageMin`/`ageMax`, `gender`, `incomeTier`, `languages`.\n\nFields a platform cannot honour are rejected on create, boost and targeting update with `INVALID_FIELD_VALUE` naming the offending field (never silently dropped).\n",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/zernio-com-openapi.json#/components/schemas/TargetingSpec",
  "type": "object",
  "properties": {
    "userOs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Meta only. Operating systems and version ranges, such as iOS_ver_14.0_and_above or Android. Emitted as user_os. May also be supplied inside targeting."
    },
    "userDevice": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Meta only. Device models such as iPhone. Emitted as user_device. May also be supplied inside targeting."
    },
    "countries": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "ISO 3166-1 alpha-2 country codes (e.g. ['US'])."
    },
    "regions": {
      "type": "array",
      "description": "Region/state targeting. `key` is the platform location ID from /v1/ads/targeting/search?dimension=geo&geoType=region. An entry may also be that id as a plain string (`\"20321\"` is `{ key: \"20321\" }`).",
      "items": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          }
        ]
      }
    },
    "cities": {
      "type": "array",
      "description": "City targeting. Optional `radius` + `distanceUnit` extend beyond the city limits; both must be set together or both omitted. `radius` is only honoured on platforms whose capability map allows city radius (Meta). An entry may also be the city id as a plain string (`\"1006410\"` is `{ key: \"1006410\" }`).",
      "items": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "radius": {
                "type": "number",
                "description": "Radius around the city. Requires distanceUnit. Meta enforces a minimum city radius (~17 km / 10 mi); smaller values resolve to a 0-size audience and the ad fails at launch. For a tighter catchment use customLocations (lat/lng), which allows a smaller radius."
              },
              "distanceUnit": {
                "type": "string",
                "enum": [
                  "mile",
                  "kilometer"
                ],
                "description": "Required if radius is set."
              }
            }
          }
        ]
      }
    },
    "zips": {
      "type": "array",
      "description": "Postal/ZIP targeting. `key` is the platform's postal location ID (e.g. Meta `US:94304`). Supported on Meta, Google, TikTok, Pinterest, X.",
      "items": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "metros": {
      "type": "array",
      "description": "DMA / metro-area targeting. `key` is the platform's metro ID (e.g. Meta `DMA:807`).",
      "items": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "countryGroups": {
      "type": "array",
      "description": "Meta only. Continents and trade blocs (`geo_locations.country_groups`),\nfor targeting a whole region without listing its countries. Combines\nwith `countries` rather than replacing it, and is also accepted under\n`excludedLocations`. Discoverable via\n`GET /v1/ads/targeting/search?dimension=geo&geoType=country_group`.\n",
      "items": {
        "type": "string",
        "enum": [
          "africa",
          "asia",
          "europe",
          "north_america",
          "south_america",
          "oceania",
          "central_america",
          "caribbean",
          "eea",
          "euro_area",
          "nafta",
          "mercosur",
          "afta",
          "apec",
          "gcc",
          "cisfta",
          "emerging_markets",
          "itunes_app_store",
          "android_free_store",
          "android_paid_store"
        ]
      }
    },
    "places": {
      "type": "array",
      "description": "Meta only. Named points of interest to target. `key` from /v1/ads/targeting/search.",
      "items": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string"
          }
        }
      }
    },
    "neighborhoods": {
      "type": "array",
      "description": "Meta only. Named neighbourhood areas to target. `key` from /v1/ads/targeting/search.",
      "items": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string"
          }
        }
      }
    },
    "customLocations": {
      "type": "array",
      "description": "Point-radius (lat/lng) targeting (Meta custom_locations / Google proximity). Honoured on Meta and Google; ignored on platforms without radius support.",
      "items": {
        "type": "object",
        "required": [
          "latitude",
          "longitude",
          "radius",
          "distanceUnit"
        ],
        "properties": {
          "latitude": {
            "type": "number",
            "minimum": -90,
            "maximum": 90
          },
          "longitude": {
            "type": "number",
            "minimum": -180,
            "maximum": 180
          },
          "radius": {
            "type": "number",
            "description": "Positive radius around the point."
          },
          "distanceUnit": {
            "type": "string",
            "enum": [
              "mile",
              "kilometer"
            ]
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "description": "Optional label, sent to Meta as `address_string`. latitude/longitude take precedence for the pin location."
          }
        }
      }
    },
    "excludedLocations": {
      "type": "object",
      "description": "Geo to exclude from the audience. Mirrors the inclusion geo shape.\n\n- Meta (excluded_geo_locations): excluded cities can carry a radius catchment, and excluded custom (lat/lng) pins are supported.\n- Google (Search, Display, Performance Max): excludes countries, regions, cities and zips as negative location criteria. countryGroups, places, neighborhoods, customLocations and a city radius return 400.\n- Google Demand Gen: returns 400 for any exclusion.\n",
      "properties": {
        "countries": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "countryGroups": {
          "type": "array",
          "description": "Meta only. Continents and trade blocs to exclude (`excluded_geo_locations.country_groups`).",
          "items": {
            "type": "string",
            "enum": [
              "africa",
              "asia",
              "europe",
              "north_america",
              "south_america",
              "oceania",
              "central_america",
              "caribbean",
              "eea",
              "euro_area",
              "nafta",
              "mercosur",
              "afta",
              "apec",
              "gcc",
              "cisfta",
              "emerging_markets",
              "itunes_app_store",
              "android_free_store",
              "android_paid_store"
            ]
          }
        },
        "regions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          }
        },
        "cities": {
          "type": "array",
          "description": "Cities to exclude. Optional `radius` + `distanceUnit` exclude a catchment around the city (both must be set together or both omitted); Meta honours the radius on excluded cities.",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "radius": {
                "type": "number",
                "description": "Radius around the excluded city. Requires distanceUnit."
              },
              "distanceUnit": {
                "type": "string",
                "enum": [
                  "mile",
                  "kilometer"
                ],
                "description": "Required if radius is set."
              }
            }
          }
        },
        "zips": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          }
        },
        "places": {
          "type": "array",
          "description": "Named points of interest to exclude. `key` from /v1/ads/targeting/search.",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              }
            }
          }
        },
        "neighborhoods": {
          "type": "array",
          "description": "Named neighbourhood areas to exclude. `key` from /v1/ads/targeting/search.",
          "items": {
            "type": "object",
            "required": [
              "key"
            ],
            "properties": {
              "key": {
                "type": "string"
              }
            }
          }
        },
        "customLocations": {
          "type": "array",
          "description": "Point-radius (lat/lng) pins to exclude (Meta excluded_geo_locations.custom_locations). Mirrors the inclusion customLocations shape.",
          "items": {
            "type": "object",
            "required": [
              "latitude",
              "longitude",
              "radius",
              "distanceUnit"
            ],
            "properties": {
              "latitude": {
                "type": "number",
                "minimum": -90,
                "maximum": 90
              },
              "longitude": {
                "type": "number",
                "minimum": -180,
                "maximum": 180
              },
              "radius": {
                "type": "number",
                "description": "Positive radius around the point."
              },
              "distanceUnit": {
                "type": "string",
                "enum": [
                  "mile",
                  "kilometer"
                ]
              },
              "name": {
                "type": "string"
              },
              "address": {
                "type": "string",
                "description": "Optional label, sent to Meta as `address_string`. latitude/longitude take precedence for the pin location."
              }
            }
          }
        }
      }
    },
    "ageMin": {
      "type": "integer",
      "minimum": 13,
      "maximum": 100,
      "description": "Minimum age.\n\n- Applied on Meta, TikTok, Pinterest, LinkedIn, X and Google Search/Display (Google excludes the age ranges outside the request).\n- Rejected with 400 on OpenAI, Reddit and Google Performance Max / Demand Gen.\n\nEach platform clamps to its own range:\n\n- Meta and Pinterest: effectively cap at 65 (65 = 65+).\n- Pinterest: no under-18 bucket, so an ageMin below 18 starts at 18.\n- TikTok: maps up to 100.\n- LinkedIn: rounds out to its buckets (18-24, 25-34, 35-54, 55+) and has no under-18 audience.\n- X: rounds out to the narrowest of its fixed ranges (e.g. 25-34 becomes 25-49, 18-65 becomes 18+)."
    },
    "ageMax": {
      "type": "integer",
      "minimum": 13,
      "maximum": 100,
      "description": "Maximum age. Same per-platform application and clamping as ageMin."
    },
    "gender": {
      "type": "string",
      "enum": [
        "all",
        "male",
        "female"
      ],
      "description": "Restrict by gender. 'all' (default) targets everyone. Applied on Meta, TikTok, Pinterest, LinkedIn, X, Reddit and Google Search/Display (Google excludes the other gender); rejected with 400 on OpenAI and on Google Performance Max / Demand Gen."
    },
    "incomeTier": {
      "type": "string",
      "enum": [
        "top_5",
        "top_10",
        "top_10_25",
        "top_25_50"
      ],
      "description": "Normalized household-income tier (ZIP/percentile based). Meta and TikTok\nexpress all four. Google maps only `top_10` (its INCOME_RANGE_90_UP); other\ntiers on Google, and any income tier on LinkedIn / X / Pinterest, are rejected.\nOn Meta, income/zip targeting requires the relevant `specialAdCategories` to be\nunset (housing/employment/credit ads cannot use it).\n"
    },
    "languages": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Language codes restricting the audience by language. Applied on Meta, Google, TikTok, LinkedIn, X, Pinterest and Reddit; rejected with 400 on OpenAI. A code the platform cannot target returns 400 listing the ones it can.\n\nOn Meta: ISO 639-1 codes (e.g. ['en']). A bare code targets all regional variants (\"en\" = all English); use a region-qualified code (\"en_GB\", \"pt_BR\") for a specific one. Meta numeric locale ids (e.g. \"24\" for English UK) are also accepted. Unknown values are rejected.\n\nPOST /v1/ads/create and POST /v1/ads/boost take the same format."
    },
    "interests": {
      "type": "array",
      "description": "Interest entities from /v1/ads/targeting/search?dimension=interest. Each carries the platform's opaque id.\n\n- Google: applied as ad-group interest criteria (affinity and in-market categories) on Display and Search ad groups the request creates. Interests are create-only.\n- Google rejections (400): on Performance Max, on Demand Gen (use the Demand Gen audience `userInterests` there), and when attaching to an existing ad group (`adSetId`).\n- OpenAI: rejected with 400.\n- TikTok: bare numeric ids are interest categories (`interest_category_ids`); ids like `keyword:123456` from `dimension=interestKeyword` are additional interests (`interest_keyword_ids`). Any other id returns 422 naming `targeting.interests`.\n- TikTok matching: people who fit ANY selected interest, additional interest or behavior (one OR'd group). That group is ANDed with location, age, gender and the other dimensions.\n",
      "items": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "behaviors": {
      "type": "array",
      "description": "Behaviour entities from /v1/ads/targeting/search?dimension=behavior (Meta, TikTok and LinkedIn).\n\n**On TikTok** they target people who, in the picked categories:\n\n- interacted with videos (watched to the end, liked, commented or shared, last 15 days);\n- interacted with creators (followed or viewed the profile);\n- or viewed videos with a picked hashtag (`hashtag:<id>` ids from `dimension=hashtag`, sent as a `HASHTAG_RELATED` action with `VIEW_HASHTAG`).\n\nThe ad group then uses the TikTok placement only. Behaviors are OR'd with interests and additional interests.\n",
      "items": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "workPositions": {
      "type": "array",
      "description": "Meta only. Job title entities from /v1/ads/targeting/search?dimension=workPosition. Not interchangeable with the LinkedIn `jobTitles` URN fragments.",
      "items": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "workEmployers": {
      "type": "array",
      "description": "Meta only. Employer entities from /v1/ads/targeting/search?dimension=workEmployer.",
      "items": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "workIndustries": {
      "type": "array",
      "description": "Meta only. Work-industry entities from /v1/ads/targeting/search?dimension=workIndustry. Not interchangeable with the LinkedIn `industries` URN fragments.",
      "items": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      }
    },
    "industries": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "LinkedIn B2B only. Industry URN id fragments, or the full urn:li:industry:* URN from /v1/ads/targeting/search?dimension=industry."
    },
    "companySizes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "LinkedIn B2B only. Single-letter size codes (A to I), or the full urn:li:staffCountRange:* URN from /v1/ads/targeting/search?dimension=companySize."
    },
    "seniorities": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "LinkedIn B2B only. Seniority URN id fragments, or the full urn:li:seniority:* URN from /v1/ads/targeting/search?dimension=seniority."
    },
    "jobFunctions": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "LinkedIn B2B only. Function URN id fragments, or the full urn:li:function:* URN from /v1/ads/targeting/search?dimension=jobFunction."
    },
    "skills": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "LinkedIn B2B only. Member skills (e.g. Python, Recruiting): skill URN id fragments, or the full urn:li:skill:* URN from /v1/ads/targeting/search?dimension=skill. Values are ORed; the facet is ANDed with the other facets. On an ad set update an empty list removes the skills."
    },
    "audienceInclude": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Platform audience IDs to include, as returned by GET /v1/ads/audiences:\n\n- Meta: custom audience ids.\n- TikTok: audience ids.\n- Pinterest: customer list ids.\n- LinkedIn: segment ids (the platformAudienceId from GET /v1/ads/audiences). Zernio resolves it to the targetable LinkedIn ad segment; an unknown id returns 400.\n- Google: user list ids.\n- X: custom audience ids.\n- Reddit: ids of custom audiences built in Reddit Ads Manager (GET /v1/ads/audiences does not list Reddit audiences).\n- OpenAI: not supported (400)."
    },
    "audienceExclude": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Platform audience IDs to exclude; same ID formats as audienceInclude. Not supported on OpenAI (400)."
    },
    "communities": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Reddit only (400 elsewhere). Subreddits to target, by name, with or without the `r/` prefix (e.g. `['marketing', 'r/startups']`), as returned by /v1/ads/targeting/search?dimension=community."
    },
    "excludedCommunities": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Reddit only (400 elsewhere). Subreddits to exclude, named like `communities`."
    },
    "conversationKeywords": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Reddit only (400 elsewhere). Keywords that place the ad in Reddit conversations about them, as returned by /v1/ads/targeting/search?dimension=conversationKeyword."
    },
    "excludedConversationKeywords": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "Reddit only (400 elsewhere). Conversation keywords to keep the ad away from."
    }
  }
}