{
  "openapi": "3.1.0",
  "info": {
    "title": "StatPilot API",
    "version": "1.0.0",
    "description": "Fast-growing US advertisers on Meta: new-ad velocity, month-over-month growth and estimated spend. Spend figures are estimates, not verified numbers. Get a key by subscribing to the API plan at /account/api."
  },
  "servers": [
    {
      "url": "https://statpilot.dev/api/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer sp_live_..."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Advertiser": {
        "type": "object",
        "properties": {
          "page_id": {
            "type": "string",
            "description": "Meta page id."
          },
          "rank": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Momentum rank (1 = fastest-growing). Null for live rows."
          },
          "name": {
            "type": "string"
          },
          "domain": {
            "type": "string",
            "example": "chomps.com"
          },
          "url": {
            "type": [
              "string",
              "null"
            ]
          },
          "product": {
            "type": [
              "string",
              "null"
            ]
          },
          "category": {
            "type": "string",
            "enum": [
              "Software",
              "Home & Auto",
              "Fashion",
              "Apps",
              "Fitness & Outdoors",
              "Food & Drink",
              "Supplements",
              "Beauty",
              "Health & Recovery",
              "Kids",
              "Pets",
              "Hobbies & Games",
              "Sports nutrition",
              "Tech & Gadgets",
              "Other"
            ]
          },
          "vertical": {
            "type": "string",
            "description": "Finer product category from the research data."
          },
          "lists": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "heavy",
                "young"
              ]
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "accelerating",
              "new",
              "stable",
              "declining",
              "unknown"
            ]
          },
          "mom_growth_pct": {
            "type": [
              "number",
              "null"
            ],
            "description": "Change in new ads launched, last 30 days vs the 30 before. Null for new launches."
          },
          "ads_last_30d": {
            "type": [
              "integer",
              "null"
            ]
          },
          "ads_prior_30d": {
            "type": [
              "integer",
              "null"
            ]
          },
          "live_ads": {
            "type": [
              "integer",
              "null"
            ]
          },
          "total_ads": {
            "type": [
              "integer",
              "null"
            ]
          },
          "est_daily_spend_usd": {
            "type": "object",
            "description": "Estimated daily Meta spend in USD. An estimate, not a verified number.",
            "properties": {
              "low": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "mid": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "high": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "confidence": {
                "type": "string",
                "enum": [
                  "good",
                  "fair",
                  "rough"
                ]
              }
            }
          },
          "est_monthly_spend_usd": {
            "type": "object",
            "description": "Daily estimate x 30.",
            "properties": {
              "low": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "mid": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "high": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "first_ad_seen": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "first_ad_seen_is_minimum": {
            "type": "boolean",
            "description": "True when Meta only listed recent ads, so the brand started earlier than first_ad_seen."
          },
          "age_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "creative_angle": {
            "type": [
              "string",
              "null"
            ]
          },
          "funnel": {
            "type": [
              "string",
              "null"
            ]
          },
          "ad_library_url": {
            "type": "string"
          },
          "data_notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "snapshot_date": {
            "type": "string",
            "format": "date",
            "description": "When the data was collected (the fetch date for live rows)."
          },
          "source": {
            "type": "string",
            "enum": [
              "snapshot",
              "live"
            ],
            "description": "snapshot = researched monthly data; live = fetched on demand from the Meta Ad Library."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/advertisers/lookup": {
      "get": {
        "summary": "Look up one advertiser by domain, URL, Meta page id or brand name",
        "description": "Returns 200 with found=false when there is no match, so enrichment tools don't treat a miss as an error. Brands outside the monthly snapshot are fetched live from the Meta Ad Library and scored with the same model (source=live, rank=null). If the fetch takes longer than `wait` seconds the response is 202 with live.status=processing: repeat the request ~15s later. A live brand uses 10 requests the first time an account asks for it in 7 days.",
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "url",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "live",
            "in": "query",
            "description": "Fetch brands outside the snapshot live (default true).",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "wait",
            "in": "query",
            "description": "Seconds to wait for a live fetch before answering 202.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 25,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lookup result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "found": {
                      "type": "boolean"
                    },
                    "advertiser": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/Advertiser"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "other_matches": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "page_id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "rank": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "The key's API plan isn't active",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (60 requests/minute per key) or the monthly request allowance is used up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/advertisers": {
      "get": {
        "summary": "Search and list advertisers",
        "parameters": [
          {
            "name": "list",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "heavy",
                "young"
              ],
              "default": "all"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "Software",
                "Home & Auto",
                "Fashion",
                "Apps",
                "Fitness & Outdoors",
                "Food & Drink",
                "Supplements",
                "Beauty",
                "Health & Recovery",
                "Kids",
                "Pets",
                "Hobbies & Games",
                "Sports nutrition",
                "Tech & Gadgets"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "accelerating",
                "new",
                "stable",
                "declining",
                "unknown"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Search name, domain, product or vertical",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_daily_spend",
            "in": "query",
            "description": "Minimum estimated daily spend midpoint (USD)",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "momentum",
                "spend",
                "launches",
                "growth"
              ],
              "default": "momentum"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of advertisers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Advertiser"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "next_offset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "The key's API plan isn't active",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (60 requests/minute per key) or the monthly request allowance is used up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/advertisers/{page_id}": {
      "get": {
        "summary": "Get one advertiser by Meta page id",
        "parameters": [
          {
            "name": "page_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The advertiser",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "advertiser": {
                      "$ref": "#/components/schemas/Advertiser"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "The key's API plan isn't active",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (60 requests/minute per key) or the monthly request allowance is used up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/meta": {
      "get": {
        "summary": "Snapshot date, size and allowed filter values",
        "responses": {
          "200": {
            "description": "Metadata"
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "The key's API plan isn't active",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (60 requests/minute per key) or the monthly request allowance is used up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}