{
  "openapi": "3.1.0",
  "info": {
    "title": "What’s Trending API",
    "version": "1.1.0",
    "description": "Workspace-scoped API for reading source-backed customer-interest trends and public evidence or triggering a rate-limited live scan. All operations require an active Pro workspace API key.",
    "contact": {
      "name": "What’s Trending",
      "url": "https://whatstrending.cc/contact",
      "email": "privacy@whatstrending.cc"
    },
    "x-versioning-policy": {
      "strategy": "URL path major versions",
      "currentMajor": "v1",
      "documentation": "https://whatstrending.cc/api.md"
    }
  },
  "externalDocs": {
    "description": "Developer and agent integration guide",
    "url": "https://whatstrending.cc/for-agents"
  },
  "servers": [
    {
      "url": "https://api.whatstrending.cc",
      "description": "Production API"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Workspace",
      "description": "Configured market, WordBank, and competitor watchlist."
    },
    {
      "name": "Research",
      "description": "Ranked trends and source-linked public evidence."
    },
    {
      "name": "Scans",
      "description": "State-changing collection operations limited by the active plan."
    }
  ],
  "paths": {
    "/v1/workspace": {
      "get": {
        "operationId": "getWorkspace",
        "summary": "Get the configured market workspace",
        "description": "Returns the workspace configuration associated with the Bearer API key.",
        "tags": [
          "Workspace"
        ],
        "responses": {
          "200": {
            "description": "Workspace configuration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/trends": {
      "get": {
        "operationId": "getTrends",
        "summary": "Get ranked customer-interest trends",
        "description": "Returns ranked topics for a supported lookback window. Omit days to use the workspace default.",
        "tags": [
          "Research"
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "required": false,
            "description": "Lookback window in days.",
            "schema": {
              "type": "integer",
              "enum": [
                7,
                30,
                90,
                180,
                365
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked trends",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrendsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/evidence": {
      "get": {
        "operationId": "listEvidence",
        "summary": "List public source evidence and engagement",
        "description": "Returns stored public evidence for the authenticated workspace. Missing source metrics remain null or absent rather than being treated as zero.",
        "tags": [
          "Research"
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "required": false,
            "description": "Lookback window. Use 0 for all stored evidence.",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                7,
                30,
                90,
                180,
                365
              ]
            }
          },
          {
            "name": "platform",
            "in": "query",
            "required": false,
            "description": "Filter to one supported source.",
            "schema": {
              "type": "string",
              "enum": [
                "reddit",
                "facebook",
                "instagram",
                "x",
                "youtube"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Case-insensitive evidence-text or matched-term filter.",
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum evidence records returned.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Evidence posts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvidenceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/scans": {
      "post": {
        "operationId": "runScan",
        "summary": "Run a fresh market scan",
        "description": "Collects and persists public evidence for the authenticated workspace. This is state-changing. Pro agent-triggered scans are limited to once per hour per workspace; confirm user intent before calling. Send an Idempotency-Key to make retries replay-safe for 24 hours.",
        "tags": [
          "Scans"
        ],
        "responses": {
          "200": {
            "description": "Previously completed scan replayed for the same Idempotency-Key",
            "headers": {
              "Idempotency-Replayed": {
                "description": "Always true for a replayed response.",
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          },
          "201": {
            "description": "Scan completed and persisted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            },
            "headers": {
              "Idempotency-Replayed": {
                "description": "False when a supplied key produced a new scan.",
                "schema": {
                  "type": "string",
                  "const": "false"
                }
              }
            }
          },
          "400": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Authentication or request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "A scan with the same Idempotency-Key is still processing",
            "headers": {
              "Retry-After": {
                "description": "Seconds before retrying with the same key.",
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "The workspace scan interval has not elapsed",
            "headers": {
              "Retry-After": {
                "description": "Seconds until the next permitted scan when available.",
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              },
              "RateLimit-Limit": {
                "description": "Maximum scan starts allowed in the current one-hour window.",
                "schema": {
                  "type": "integer",
                  "const": 1
                }
              },
              "RateLimit-Remaining": {
                "description": "Scan starts remaining in the current window.",
                "schema": {
                  "type": "integer",
                  "const": 0
                }
              },
              "RateLimit-Reset": {
                "description": "Seconds until the scan-start limit resets.",
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Retry key scoped to the authenticated workspace. The first successful scan is retained for 24 hours; a completed retry replays that response without collecting again.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._:-]+$"
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "wt_live_",
        "description": "Workspace-scoped API key created in Settings → Agent access. Keep it server-side."
      }
    },
    "responses": {
      "Error": {
        "description": "Request failed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable error message."
          }
        },
        "additionalProperties": false
      },
      "WorkspaceResponse": {
        "type": "object",
        "required": [
          "workspace"
        ],
        "properties": {
          "workspace": {
            "$ref": "#/components/schemas/Workspace"
          }
        },
        "additionalProperties": false
      },
      "Workspace": {
        "type": "object",
        "required": [
          "id",
          "name",
          "productName",
          "productUrl",
          "words",
          "competitorUrls",
          "handles",
          "lookbackDays"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "productName": {
            "type": "string"
          },
          "productUrl": {
            "type": "string",
            "format": "uri"
          },
          "words": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "competitorUrls": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "handles": {
            "type": "object",
            "properties": {
              "reddit": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "facebook": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "instagram": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "x": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": false
          },
          "lookbackDays": {
            "type": "integer",
            "enum": [
              7,
              30,
              90,
              180,
              365
            ]
          }
        },
        "additionalProperties": false
      },
      "TrendsResponse": {
        "type": "object",
        "required": [
          "windowDays",
          "trends"
        ],
        "properties": {
          "windowDays": {
            "type": "integer"
          },
          "trends": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Trend"
            }
          }
        },
        "additionalProperties": false
      },
      "Trend": {
        "type": "object",
        "required": [
          "id",
          "topic",
          "score",
          "mentions",
          "uniqueAuthors",
          "platforms",
          "engagement"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "topic": {
            "type": "string"
          },
          "score": {
            "type": "number"
          },
          "status": {
            "type": "string"
          },
          "mentions": {
            "type": "integer"
          },
          "uniqueAuthors": {
            "type": "integer"
          },
          "platforms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "engagement": {
            "type": "number"
          },
          "summary": {
            "type": "string"
          },
          "postIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "idea": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "EvidenceResponse": {
        "type": "object",
        "required": [
          "windowDays",
          "total",
          "posts"
        ],
        "properties": {
          "windowDays": {
            "type": "integer"
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "posts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Post"
            }
          }
        },
        "additionalProperties": false
      },
      "Post": {
        "type": "object",
        "required": [
          "platform",
          "id",
          "text",
          "url",
          "publishedAt"
        ],
        "properties": {
          "platform": {
            "type": "string",
            "enum": [
              "reddit",
              "facebook",
              "instagram",
              "x",
              "youtube"
            ]
          },
          "id": {
            "type": "string"
          },
          "authorHandle": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "commentsUrl": {
            "type": "string",
            "format": "uri"
          },
          "publishedAt": {
            "type": "string",
            "format": "date-time"
          },
          "matchedTerms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metrics": {
            "type": "object",
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "additionalProperties": true
      },
      "ScanResponse": {
        "type": "object",
        "required": [
          "run"
        ],
        "properties": {
          "run": {
            "$ref": "#/components/schemas/ScanRun"
          }
        },
        "additionalProperties": false
      },
      "ScanRun": {
        "type": "object",
        "required": [
          "id",
          "mode",
          "startedAt",
          "completedAt",
          "collectors",
          "posts",
          "trends"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "const": "live"
          },
          "startedAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": "string",
            "format": "date-time"
          },
          "collectors": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "posts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Post"
            }
          },
          "trends": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Trend"
            }
          }
        },
        "additionalProperties": true
      }
    }
  }
}
