{
  "openapi": "3.0.3",
  "info": {
    "title": "AfterLib Public API",
    "version": "1.0.0",
    "description": "Credit-gated public API for AfterLib member ad, page, and collection data."
  },
  "servers": [
    {
      "url": "https://api.afterlib.com"
    }
  ],
  "tags": [
    {
      "name": "Account"
    },
    {
      "name": "Credits"
    },
    {
      "name": "Collections"
    },
    {
      "name": "Ads"
    },
    {
      "name": "Pages"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use an API key generated from the AfterLib Developer Console."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "requestId"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string"
              },
              "details": {}
            }
          }
        },
        "$id": "#/components/schemas/Error"
      },
      "Account": {
        "example": {
          "userId": "00000000-0000-7001-8001-aa0000000001",
          "billingUserId": "00000000-0000-7001-8001-aa0000000001",
          "planId": "pro",
          "isTeamMember": false,
          "subscriptionStatus": "active"
        },
        "type": "object",
        "required": [
          "userId",
          "billingUserId",
          "planId",
          "isTeamMember",
          "subscriptionStatus"
        ],
        "properties": {
          "userId": {
            "format": "uuid",
            "type": "string"
          },
          "billingUserId": {
            "format": "uuid",
            "type": "string"
          },
          "planId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "isTeamMember": {
            "type": "boolean"
          },
          "subscriptionStatus": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "$id": "#/components/schemas/Account"
      },
      "UsageLimit": {
        "type": "object",
        "required": [
          "isLimitReached",
          "limitType",
          "hourlyCredits",
          "hourlyLimit",
          "dailyCredits",
          "dailyLimit"
        ],
        "properties": {
          "isLimitReached": {
            "type": "boolean"
          },
          "limitType": {
            "type": "string",
            "enum": [
              "none",
              "hourly",
              "daily"
            ]
          },
          "hourlyCredits": {
            "type": "number"
          },
          "hourlyLimit": {
            "type": "number"
          },
          "dailyCredits": {
            "type": "number"
          },
          "dailyLimit": {
            "type": "number"
          }
        },
        "$id": "#/components/schemas/UsageLimit"
      },
      "CreditStatus": {
        "example": {
          "planId": "pro",
          "billingUserId": "00000000-0000-7001-8001-aa0000000001",
          "periodStart": 1779254247,
          "periodEnd": 1781932647,
          "credits": 99968,
          "creditsMax": 100000,
          "usageLimit": {
            "isLimitReached": false,
            "limitType": "none",
            "hourlyCredits": 0,
            "hourlyLimit": 5000,
            "dailyCredits": 32,
            "dailyLimit": 18000
          }
        },
        "type": "object",
        "required": [
          "planId",
          "billingUserId",
          "periodStart",
          "periodEnd",
          "credits",
          "creditsMax",
          "usageLimit"
        ],
        "properties": {
          "planId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "billingUserId": {
            "format": "uuid",
            "type": "string"
          },
          "periodStart": {
            "nullable": true,
            "anyOf": [
              {
                "description": "Unix timestamp in seconds.",
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "periodEnd": {
            "nullable": true,
            "anyOf": [
              {
                "description": "Unix timestamp in seconds.",
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "credits": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "creditsMax": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "usageLimit": {
            "$ref": "UsageLimit"
          }
        },
        "$id": "#/components/schemas/CreditStatus"
      },
      "MediaAsset": {
        "additionalProperties": true,
        "type": "object",
        "required": [
          "type",
          "url"
        ],
        "properties": {
          "type": {
            "description": "Media role, such as THUMB, VID, PA_PP, CARD_THUMB, or CARD_VID.",
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "nr": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "referenceId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "mediaFormat": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "filename": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "width": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "height": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "durationSeconds": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "urls": {
            "type": "object",
            "patternProperties": {
              "^(.*)$": {
                "type": "string"
              }
            }
          }
        },
        "$id": "#/components/schemas/MediaAsset"
      },
      "Ad": {
        "example": {
          "id": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
          "pageId": "9000000000500",
          "metaPageExternalId": "9000000000500",
          "headline": "Bring home cleaner skin",
          "body": "A concise public ad response with creative metadata, media, page, and website context.",
          "startedAt": "2025-08-26T09:04:49.640Z",
          "lastSeenAt": "2025-09-03T09:04:49.640Z",
          "duplicates": 1228,
          "performancePublic": 100,
          "trendPublic": 0,
          "countries": [
            "US"
          ],
          "displayFormat": "video",
          "ctaType": "SHOP_NOW",
          "media": [
            {
              "type": "THUMB",
              "url": "creative-thumb.jpg",
              "mediaFormat": "jpg",
              "urls": {
                "preview": "https://box.afterlib.com/example-preview"
              }
            }
          ],
          "page": {
            "pageName": "Drift Wellness Company",
            "adsAmount": 4
          },
          "website": {
            "siteDomain": "seed-store.afterlib.local"
          }
        },
        "additionalProperties": true,
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "pageId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "metaPageExternalId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "headline": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "body": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "linkDescription": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "productTitle": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "offerLink": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "displayUrl": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "startedAt": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "lastSeenAt": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "endDate": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "productCreatedAt": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "productPrice": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "isShopifyBestSeller": {
            "nullable": true,
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          },
          "duplicates": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "trendPublic": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "performancePublic": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "audienceReach": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "countries": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "ctaType": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "displayFormat": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "publisherPlatform": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "media": {
            "type": "array",
            "items": {
              "$ref": "MediaAsset"
            }
          },
          "cards": {
            "type": "array",
            "items": {
              "additionalProperties": true,
              "type": "object",
              "properties": {}
            }
          },
          "changes": {
            "additionalProperties": true,
            "type": "object",
            "properties": {}
          },
          "page": {
            "additionalProperties": true,
            "type": "object",
            "properties": {}
          },
          "website": {
            "additionalProperties": true,
            "type": "object",
            "properties": {}
          },
          "adSpendMin": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "adSpendMax": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "revenueMin": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "revenueMax": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "$id": "#/components/schemas/Ad"
      },
      "Page": {
        "example": {
          "pageId": "9000000000500",
          "metaPageExternalId": "9000000000500",
          "pageName": "Drift Wellness Company",
          "pageLikes": 2778360,
          "pageIgFollowers": 992229,
          "pageCreatedAt": "2021-01-13T09:04:49.640Z",
          "adsAmount": 4,
          "adsTotalDuplicates": 1538,
          "audienceReach": 15436615,
          "averageDuplicates": 385,
          "performance": 84,
          "trend": 1,
          "countries": [
            "US",
            "CA"
          ],
          "languages": [
            "eng"
          ],
          "technologySlugs": [
            "shopify",
            "klaviyo"
          ],
          "thumbnails": [
            {
              "url": "https://box.afterlib.com/example-thumbnail",
              "isVideo": true
            }
          ]
        },
        "additionalProperties": true,
        "type": "object",
        "required": [
          "pageId",
          "pageName"
        ],
        "properties": {
          "pageId": {
            "type": "string"
          },
          "metaPageExternalId": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "pageName": {
            "type": "string"
          },
          "pageLikes": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "pageIgFollowers": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "pageCreatedAt": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "createdAt": {
            "nullable": true,
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "technologySlugs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "countries": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "languages": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "adsAmount": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "adsTotalDuplicates": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "audienceReach": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "averageDuplicates": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "trend": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "performance": {
            "nullable": true,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "detailsEstimated": {
            "nullable": true,
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          },
          "media": {
            "type": "array",
            "items": {
              "$ref": "MediaAsset"
            }
          },
          "thumbnails": {
            "type": "array",
            "items": {
              "additionalProperties": true,
              "type": "object",
              "properties": {}
            }
          }
        },
        "$id": "#/components/schemas/Page"
      },
      "AdListResult": {
        "example": {
          "items": [
            {
              "id": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
              "pageId": "9000000000500",
              "metaPageExternalId": "9000000000500",
              "headline": "Bring home cleaner skin",
              "body": "A concise public ad response with creative metadata, media, page, and website context.",
              "startedAt": "2025-08-26T09:04:49.640Z",
              "lastSeenAt": "2025-09-03T09:04:49.640Z",
              "duplicates": 1228,
              "performancePublic": 100,
              "trendPublic": 0,
              "countries": [
                "US"
              ],
              "displayFormat": "video",
              "ctaType": "SHOP_NOW",
              "media": [
                {
                  "type": "THUMB",
                  "url": "creative-thumb.jpg",
                  "mediaFormat": "jpg",
                  "urls": {
                    "preview": "https://box.afterlib.com/example-preview"
                  }
                }
              ],
              "page": {
                "pageName": "Drift Wellness Company",
                "adsAmount": 4
              },
              "website": {
                "siteDomain": "seed-store.afterlib.local"
              }
            }
          ],
          "cursor": null,
          "hasMore": false,
          "totalHits": 1
        },
        "type": "object",
        "required": [
          "items",
          "cursor",
          "hasMore"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "Ad"
            }
          },
          "cursor": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "hasMore": {
            "type": "boolean"
          },
          "totalHits": {
            "type": "number"
          }
        },
        "$id": "#/components/schemas/AdListResult"
      },
      "PageListResult": {
        "example": {
          "items": [
            {
              "pageId": "9000000000500",
              "metaPageExternalId": "9000000000500",
              "pageName": "Drift Wellness Company",
              "pageLikes": 2778360,
              "pageIgFollowers": 992229,
              "pageCreatedAt": "2021-01-13T09:04:49.640Z",
              "adsAmount": 4,
              "adsTotalDuplicates": 1538,
              "audienceReach": 15436615,
              "averageDuplicates": 385,
              "performance": 84,
              "trend": 1,
              "countries": [
                "US",
                "CA"
              ],
              "languages": [
                "eng"
              ],
              "technologySlugs": [
                "shopify",
                "klaviyo"
              ],
              "thumbnails": [
                {
                  "url": "https://box.afterlib.com/example-thumbnail",
                  "isVideo": true
                }
              ]
            }
          ],
          "cursor": null,
          "hasMore": false,
          "totalHits": 1
        },
        "type": "object",
        "required": [
          "items",
          "cursor",
          "hasMore"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "Page"
            }
          },
          "cursor": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "hasMore": {
            "type": "boolean"
          },
          "totalHits": {
            "type": "number"
          }
        },
        "$id": "#/components/schemas/PageListResult"
      },
      "Collection": {
        "example": {
          "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
          "name": "Favorites",
          "type": "private",
          "isDefault": true,
          "defaultType": "favorites",
          "isOwner": true,
          "adCount": 1,
          "pageCount": 1
        },
        "type": "object",
        "required": [
          "id",
          "name",
          "type",
          "isDefault",
          "defaultType",
          "isOwner",
          "adCount",
          "pageCount"
        ],
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "isDefault": {
            "type": "boolean"
          },
          "defaultType": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "isOwner": {
            "type": "boolean"
          },
          "adCount": {
            "type": "number"
          },
          "pageCount": {
            "type": "number"
          }
        },
        "$id": "#/components/schemas/Collection"
      },
      "CollectionListResult": {
        "example": {
          "items": [
            {
              "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
              "name": "Favorites",
              "type": "private",
              "isDefault": true,
              "defaultType": "favorites",
              "isOwner": true,
              "adCount": 1,
              "pageCount": 1
            }
          ]
        },
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "Collection"
            }
          }
        },
        "$id": "#/components/schemas/CollectionListResult"
      },
      "CollectionItemsQuery": {
        "type": "object",
        "required": [
          "itemType"
        ],
        "properties": {
          "itemType": {
            "type": "string",
            "enum": [
              "ads",
              "pages"
            ]
          },
          "limit": {
            "default": 50,
            "minimum": 1,
            "maximum": 100,
            "type": "number"
          },
          "cursor": {
            "type": "string"
          }
        },
        "$id": "#/components/schemas/CollectionItemsQuery"
      },
      "CollectionItemsResult": {
        "example": {
          "collection": {
            "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
            "name": "Favorites",
            "type": "private",
            "isDefault": true,
            "defaultType": "favorites",
            "isOwner": true,
            "adCount": 1,
            "pageCount": 1
          },
          "itemType": "ads",
          "items": [
            {
              "id": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
              "pageId": "9000000000500",
              "metaPageExternalId": "9000000000500",
              "headline": "Bring home cleaner skin",
              "body": "A concise public ad response with creative metadata, media, page, and website context.",
              "startedAt": "2025-08-26T09:04:49.640Z",
              "lastSeenAt": "2025-09-03T09:04:49.640Z",
              "duplicates": 1228,
              "performancePublic": 100,
              "trendPublic": 0,
              "countries": [
                "US"
              ],
              "displayFormat": "video",
              "ctaType": "SHOP_NOW",
              "media": [
                {
                  "type": "THUMB",
                  "url": "creative-thumb.jpg",
                  "mediaFormat": "jpg",
                  "urls": {
                    "preview": "https://box.afterlib.com/example-preview"
                  }
                }
              ],
              "page": {
                "pageName": "Drift Wellness Company",
                "adsAmount": 4
              },
              "website": {
                "siteDomain": "seed-store.afterlib.local"
              }
            }
          ],
          "cursor": null,
          "hasMore": false
        },
        "type": "object",
        "required": [
          "collection",
          "itemType",
          "items",
          "cursor",
          "hasMore"
        ],
        "properties": {
          "collection": {
            "$ref": "Collection"
          },
          "itemType": {
            "type": "string",
            "enum": [
              "ads",
              "pages"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "anyOf": [
                {
                  "$ref": "Ad"
                },
                {
                  "$ref": "Page"
                }
              ]
            }
          },
          "cursor": {
            "nullable": true,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "hasMore": {
            "type": "boolean"
          }
        },
        "$id": "#/components/schemas/CollectionItemsResult"
      },
      "AddCollectionItemRequest": {
        "example": {
          "itemType": "ads",
          "itemId": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1"
        },
        "type": "object",
        "required": [
          "itemType",
          "itemId"
        ],
        "properties": {
          "itemType": {
            "type": "string",
            "enum": [
              "ads",
              "pages"
            ]
          },
          "itemId": {
            "minLength": 1,
            "type": "string"
          }
        },
        "$id": "#/components/schemas/AddCollectionItemRequest"
      },
      "AddCollectionItemResult": {
        "example": {
          "collection": {
            "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
            "name": "Favorites",
            "type": "private",
            "isDefault": true,
            "defaultType": "favorites",
            "isOwner": true,
            "adCount": 1,
            "pageCount": 1
          },
          "itemType": "ads",
          "itemId": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
          "added": true
        },
        "type": "object",
        "required": [
          "collection",
          "itemType",
          "itemId",
          "added"
        ],
        "properties": {
          "collection": {
            "$ref": "Collection"
          },
          "itemType": {
            "type": "string",
            "enum": [
              "ads",
              "pages"
            ]
          },
          "itemId": {
            "type": "string"
          },
          "added": {
            "type": "boolean"
          }
        },
        "$id": "#/components/schemas/AddCollectionItemResult"
      },
      "SearchRequest": {
        "additionalProperties": true,
        "example": {
          "limit": 10
        },
        "type": "object",
        "properties": {},
        "$id": "#/components/schemas/SearchRequest"
      }
    }
  },
  "paths": {
    "/v1/account": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getAccount",
        "summary": "Get the authenticated API account",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Account summary",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing account:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits": {
      "get": {
        "tags": [
          "Credits"
        ],
        "operationId": "getCredits",
        "summary": "Get current credit and usage-limit state",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Credit status",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditStatus"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing credits:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/collections": {
      "get": {
        "tags": [
          "Collections"
        ],
        "operationId": "listCollections",
        "summary": "List collections visible to the authenticated member",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Collection list",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CollectionListResult"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing collections:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/collections/{collectionId}/items": {
      "get": {
        "tags": [
          "Collections"
        ],
        "operationId": "listCollectionItems",
        "summary": "List ads or pages from a collection",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Collection items",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CollectionItemsResult"
                },
                "examples": {
                  "ads": {
                    "summary": "Collection ads",
                    "value": {
                      "collection": {
                        "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
                        "name": "Favorites",
                        "type": "private",
                        "isDefault": true,
                        "defaultType": "favorites",
                        "isOwner": true,
                        "adCount": 1,
                        "pageCount": 1
                      },
                      "itemType": "ads",
                      "items": [
                        {
                          "id": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
                          "pageId": "9000000000500",
                          "metaPageExternalId": "9000000000500",
                          "headline": "Bring home cleaner skin",
                          "body": "A concise public ad response with creative metadata, media, page, and website context.",
                          "startedAt": "2025-08-26T09:04:49.640Z",
                          "lastSeenAt": "2025-09-03T09:04:49.640Z",
                          "duplicates": 1228,
                          "performancePublic": 100,
                          "trendPublic": 0,
                          "countries": [
                            "US"
                          ],
                          "displayFormat": "video",
                          "ctaType": "SHOP_NOW",
                          "media": [
                            {
                              "type": "THUMB",
                              "url": "creative-thumb.jpg",
                              "mediaFormat": "jpg",
                              "urls": {
                                "preview": "https://box.afterlib.com/example-preview"
                              }
                            }
                          ],
                          "page": {
                            "pageName": "Drift Wellness Company",
                            "adsAmount": 4
                          },
                          "website": {
                            "siteDomain": "seed-store.afterlib.local"
                          }
                        }
                      ],
                      "cursor": null,
                      "hasMore": false
                    }
                  },
                  "pages": {
                    "summary": "Collection pages",
                    "value": {
                      "collection": {
                        "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
                        "name": "Favorites",
                        "type": "private",
                        "isDefault": true,
                        "defaultType": "favorites",
                        "isOwner": true,
                        "adCount": 1,
                        "pageCount": 1
                      },
                      "itemType": "pages",
                      "items": [
                        {
                          "pageId": "9000000000500",
                          "metaPageExternalId": "9000000000500",
                          "pageName": "Drift Wellness Company",
                          "pageLikes": 2778360,
                          "pageIgFollowers": 992229,
                          "pageCreatedAt": "2021-01-13T09:04:49.640Z",
                          "adsAmount": 4,
                          "adsTotalDuplicates": 1538,
                          "audienceReach": 15436615,
                          "averageDuplicates": 385,
                          "performance": 84,
                          "trend": 1,
                          "countries": [
                            "US",
                            "CA"
                          ],
                          "languages": [
                            "eng"
                          ],
                          "technologySlugs": [
                            "shopify",
                            "klaviyo"
                          ],
                          "thumbnails": [
                            {
                              "url": "https://box.afterlib.com/example-thumbnail",
                              "isVideo": true
                            }
                          ]
                        }
                      ],
                      "cursor": null,
                      "hasMore": false
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Subscription or credits required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing required scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Collection not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid collection item query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "collectionId",
            "in": "path",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "name": "itemType",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "ads",
                "pages"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "default": 50,
              "minimum": 1,
              "maximum": 100,
              "type": "number"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "Collections"
        ],
        "operationId": "addCollectionItem",
        "summary": "Add an ad or page to a collection",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddCollectionItemRequest"
              },
              "examples": {
                "ad": {
                  "summary": "Add an ad",
                  "value": {
                    "itemType": "ads",
                    "itemId": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1"
                  }
                },
                "page": {
                  "summary": "Add a page",
                  "value": {
                    "itemType": "pages",
                    "itemId": "9000000000500"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Collection item write result",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AddCollectionItemResult"
                },
                "examples": {
                  "added": {
                    "summary": "New item added",
                    "value": {
                      "collection": {
                        "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
                        "name": "Favorites",
                        "type": "private",
                        "isDefault": true,
                        "defaultType": "favorites",
                        "isOwner": true,
                        "adCount": 1,
                        "pageCount": 1
                      },
                      "itemType": "ads",
                      "itemId": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
                      "added": true
                    }
                  },
                  "alreadyPresent": {
                    "summary": "Item already present",
                    "value": {
                      "collection": {
                        "id": "019e6387-e2e9-7478-9d6d-170158c523b0",
                        "name": "Favorites",
                        "type": "private",
                        "isDefault": true,
                        "defaultType": "favorites",
                        "isOwner": true,
                        "adCount": 1,
                        "pageCount": 1
                      },
                      "itemType": "pages",
                      "itemId": "9000000000500",
                      "added": false
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing required scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Collection or item not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid collection item body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "collectionId",
            "in": "path",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/ads/search": {
      "post": {
        "tags": [
          "Ads"
        ],
        "operationId": "searchAds",
        "summary": "Search ads with cursor pagination",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              },
              "examples": {
                "defaultSearch": {
                  "summary": "Default search",
                  "value": {
                    "limit": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ads search result",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdListResult"
                }
              }
            }
          },
          "402": {
            "description": "Subscription or credits required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing ads:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid ads search body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/ads/{adId}": {
      "get": {
        "tags": [
          "Ads"
        ],
        "operationId": "getAd",
        "summary": "Get one ad by id",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Ad detail",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ad"
                },
                "examples": {
                  "ad": {
                    "value": {
                      "id": "018f2f8e-8f32-7c11-a4a6-33c73a4d7ad1",
                      "pageId": "9000000000500",
                      "metaPageExternalId": "9000000000500",
                      "headline": "Bring home cleaner skin",
                      "body": "A concise public ad response with creative metadata, media, page, and website context.",
                      "startedAt": "2025-08-26T09:04:49.640Z",
                      "lastSeenAt": "2025-09-03T09:04:49.640Z",
                      "duplicates": 1228,
                      "performancePublic": 100,
                      "trendPublic": 0,
                      "countries": [
                        "US"
                      ],
                      "displayFormat": "video",
                      "ctaType": "SHOP_NOW",
                      "media": [
                        {
                          "type": "THUMB",
                          "url": "creative-thumb.jpg",
                          "mediaFormat": "jpg",
                          "urls": {
                            "preview": "https://box.afterlib.com/example-preview"
                          }
                        }
                      ],
                      "page": {
                        "pageName": "Drift Wellness Company",
                        "adsAmount": 4
                      },
                      "website": {
                        "siteDomain": "seed-store.afterlib.local"
                      }
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Subscription or credits required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing ads:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Ad not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid ad id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "adId",
            "in": "path",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/pages/search": {
      "post": {
        "tags": [
          "Pages"
        ],
        "operationId": "searchPages",
        "summary": "Search pages with cursor pagination",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              },
              "examples": {
                "defaultSearch": {
                  "summary": "Default search",
                  "value": {
                    "limit": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pages search result",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PageListResult"
                }
              }
            }
          },
          "402": {
            "description": "Subscription or credits required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing pages:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid pages search body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/pages/{pageId}": {
      "get": {
        "tags": [
          "Pages"
        ],
        "operationId": "getPage",
        "summary": "Get one page by id",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Page detail",
            "headers": {
              "X-Afterlib-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Afterlib-Credits-Remaining": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                },
                "examples": {
                  "page": {
                    "value": {
                      "pageId": "9000000000500",
                      "metaPageExternalId": "9000000000500",
                      "pageName": "Drift Wellness Company",
                      "pageLikes": 2778360,
                      "pageIgFollowers": 992229,
                      "pageCreatedAt": "2021-01-13T09:04:49.640Z",
                      "adsAmount": 4,
                      "adsTotalDuplicates": 1538,
                      "audienceReach": 15436615,
                      "averageDuplicates": 385,
                      "performance": 84,
                      "trend": 1,
                      "countries": [
                        "US",
                        "CA"
                      ],
                      "languages": [
                        "eng"
                      ],
                      "technologySlugs": [
                        "shopify",
                        "klaviyo"
                      ],
                      "thumbnails": [
                        {
                          "url": "https://box.afterlib.com/example-thumbnail",
                          "isVideo": true
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Subscription or credits required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing pages:read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Page not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid page id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "pageId",
            "in": "path",
            "required": true,
            "schema": {
              "minLength": 1,
              "type": "string"
            }
          }
        ]
      }
    }
  }
}
