{
  "openapi": "3.0.3",
  "info": {
    "title": "Structured Pages Catalog API",
    "version": "1.0.0",
    "description": "Read-only catalog API for Structured Pages. Authenticate with an API key. Default rate limit: 60 requests per 60 seconds per key."
  },
  "servers": [
    {
      "url": "https://structuredpages.com"
    }
  ],
  "tags": [
    {
      "name": "Products",
      "description": "Single catalog entities."
    },
    {
      "name": "Categories",
      "description": "Entities grouped by category slug."
    },
    {
      "name": "Search",
      "description": "Keyword search across the tenant catalog."
    },
    {
      "name": "Ask",
      "description": "Natural-language questions mapped onto search and filters."
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "Send `Authorization: Bearer hvce_…` (key issued for this tenant)."
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Alternative to Bearer: `X-Api-Key: hvce_…`."
      }
    },
    "schemas": {
      "Entity": {
        "type": "object",
        "required": [
          "slug",
          "title",
          "externalId",
          "externalIdType",
          "categories"
        ],
        "properties": {
          "slug": {
            "type": "string",
            "description": "Stable URL slug for the entity."
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "dataset": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "externalId": {
            "type": "string",
            "nullable": true,
            "description": "Natural business key when the catalog has one (for example a SKU); otherwise null."
          },
          "externalIdType": {
            "type": "string",
            "nullable": true,
            "description": "Kind of externalId (sku, product_id, …); null when externalId is null."
          },
          "attributes": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Qualitative attributes as plain strings."
          },
          "metrics": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                }
              ]
            },
            "description": "Quantitative attributes as display values."
          }
        }
      },
      "ApiEntity": {
        "type": "object",
        "required": [
          "slug",
          "title",
          "externalId",
          "externalIdType",
          "categories"
        ],
        "properties": {
          "slug": {
            "type": "string",
            "description": "Stable URL slug for the entity."
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "dataset": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "externalId": {
            "type": "string",
            "nullable": true,
            "description": "Natural business key when the catalog has one (for example a SKU); otherwise null."
          },
          "externalIdType": {
            "type": "string",
            "nullable": true,
            "description": "Kind of externalId (sku, product_id, …); null when externalId is null."
          },
          "attributes": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Qualitative attributes as plain strings."
          },
          "metrics": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                }
              ]
            },
            "description": "Quantitative attributes as display values."
          }
        }
      },
      "AskIntent": {
        "type": "object",
        "properties": {
          "q": {
            "type": "string",
            "description": "Keyword fragment derived from the question."
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Category slugs matched from the question."
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/v1/products/{slug}": {
      "get": {
        "tags": [
          "Products"
        ],
        "summary": "Get one product by slug",
        "operationId": "getProductBySlug",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Entity slug."
          }
        ],
        "responses": {
          "200": {
            "description": "Product entity.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Entity"
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, unknown, or revoked API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "unauthorized"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "API key belongs to a different tenant than this site.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "forbidden_tenant"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No matching product or category in this tenant catalog.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "not_found"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this API key (default 60 per 60s).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds until the rate-limit window resets."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "rate_limited"
                    },
                    "retryAfterSec": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/categories/{slug}": {
      "get": {
        "tags": [
          "Categories"
        ],
        "summary": "List products in a category",
        "operationId": "listCategoryProducts",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Category listing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "slug": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Entity"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, unknown, or revoked API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "unauthorized"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "API key belongs to a different tenant than this site.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "forbidden_tenant"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No matching product or category in this tenant catalog.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "not_found"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this API key (default 60 per 60s).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds until the rate-limit window resets."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "rate_limited"
                    },
                    "retryAfterSec": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/search": {
      "get": {
        "tags": [
          "Search"
        ],
        "summary": "Keyword search",
        "operationId": "searchCatalog",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2
            },
            "description": "Search text (at least 2 characters)."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search hits.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Entity"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Query too short.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "query_too_short"
                    },
                    "minLength": {
                      "type": "integer",
                      "example": 2
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, unknown, or revoked API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "unauthorized"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "API key belongs to a different tenant than this site.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "forbidden_tenant"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this API key (default 60 per 60s).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds until the rate-limit window resets."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "rate_limited"
                    },
                    "retryAfterSec": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/ask": {
      "post": {
        "tags": [
          "Ask"
        ],
        "summary": "Ask a natural-language question",
        "operationId": "askCatalog",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "question"
                ],
                "properties": {
                  "question": {
                    "type": "string",
                    "description": "Plain-language question (alias field: q).",
                    "example": "herbicides safe for corn"
                  },
                  "q": {
                    "type": "string",
                    "description": "Alias for question."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Interpreted intent plus matching entities.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "question": {
                      "type": "string"
                    },
                    "intent": {
                      "$ref": "#/components/schemas/AskIntent"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Entity"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing question.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "question_required"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, unknown, or revoked API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "unauthorized"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "API key belongs to a different tenant than this site.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "forbidden_tenant"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests for this API key (default 60 per 60s).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds until the rate-limit window resets."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "rate_limited"
                    },
                    "retryAfterSec": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}