{
  "openapi": "3.1.0",
  "info": {
    "title": "SimpleLab Product API",
    "version": "1.0.0",
    "description": "Public, read-only endpoints for finding SimpleLab laboratory tests. No authentication. Rate limit: 30 requests per minute per IP."
  },
  "servers": [
    {
      "url": "https://api.gosimplelab.com/api"
    }
  ],
  "security": [],
  "paths": {
    "/ai/products/search": {
      "get": {
        "operationId": "searchProducts",
        "summary": "Search products (AND logic)",
        "description": "Products testing for ALL requested contaminants, ordered by relevance.",
        "parameters": [
          {
            "name": "search_term",
            "in": "query",
            "description": "Free-text search. Also matches SKUs.",
            "schema": {
              "type": "string",
              "maxLength": 255
            }
          },
          {
            "name": "contaminants[]",
            "in": "query",
            "description": "Analyte names (exact, case-sensitive) or numeric analyte IDs. A product must test for all of them. \"Legionella\" and \"Total PFAS\" are accepted as group terms.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "matrices[]",
            "in": "query",
            "description": "Matrix IDs: 1 = Drinking Water, 2 = Wastewater, 3 = Non-Potable Water, 4 = Soil, 8 = Food, 9 = Solid, 12 = Surface (wipe, swab, tape and dust tests of surfaces, not surface water), 13 = Air, 14 = Sediment, 15 = Surface Water.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "description": "Values above 20 are capped at 20.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching products.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "summary",
                    "products"
                  ],
                  "properties": {
                    "summary": {
                      "$ref": "#/components/schemas/Summary"
                    },
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Invalid parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (30 requests per minute per IP).",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/ai/products/browse": {
      "get": {
        "operationId": "browseProducts",
        "summary": "Browse products (OR logic)",
        "description": "Products testing for ANY requested contaminant, sorted by match_strength (highest first).",
        "parameters": [
          {
            "name": "search_term",
            "in": "query",
            "description": "Free-text search. Also matches SKUs.",
            "schema": {
              "type": "string",
              "maxLength": 255
            }
          },
          {
            "name": "contaminants[]",
            "in": "query",
            "description": "Analyte names (exact, case-sensitive) or numeric analyte IDs. A product must test for at least one of them. \"Legionella\" and \"Total PFAS\" are accepted as group terms.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "matrices[]",
            "in": "query",
            "description": "Matrix IDs: 1 = Drinking Water, 2 = Wastewater, 3 = Non-Potable Water, 4 = Soil, 8 = Food, 9 = Solid, 12 = Surface (wipe, swab, tape and dust tests of surfaces, not surface water), 13 = Air, 14 = Sediment, 15 = Surface Water.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "description": "Values above 50 are capped at 50.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching products.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "summary",
                    "products"
                  ],
                  "properties": {
                    "summary": {
                      "$ref": "#/components/schemas/Summary"
                    },
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BrowseProduct"
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Invalid parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (30 requests per minute per IP).",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/ai/products/compare": {
      "get": {
        "operationId": "compareProducts",
        "summary": "Compare products by handle",
        "description": "Product-page detail for up to 5 products, in the order requested. Unknown handles are listed in not_found.",
        "parameters": [
          {
            "name": "handles[]",
            "in": "query",
            "required": true,
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "minItems": 1,
              "maxItems": 5,
              "items": {
                "type": "string",
                "maxLength": 255
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Requested products.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "not_found",
                    "products"
                  ],
                  "properties": {
                    "not_found": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CompareProduct"
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Invalid parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (30 requests per minute per IP).",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "required": [
          "name",
          "handle",
          "sku",
          "matrix",
          "price",
          "msrp",
          "rush",
          "paylater",
          "turnaround_time",
          "analytes_count",
          "description",
          "recommended_for",
          "analytes_by_category"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "handle": {
            "type": "string",
            "description": "Product identifier. Product page: https://gosimplelab.com/shop/products/{handle}"
          },
          "sku": {
            "type": [
              "string",
              "null"
            ]
          },
          "matrix": {
            "type": "string",
            "description": "Sample type, e.g. Drinking Water."
          },
          "price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Price in USD."
          },
          "msrp": {
            "type": [
              "number",
              "null"
            ],
            "description": "List price in USD."
          },
          "rush": {
            "type": "boolean",
            "description": "Whether a rush turnaround option exists."
          },
          "paylater": {
            "type": "boolean",
            "description": "Whether a pay-later option exists."
          },
          "turnaround_time": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Lab turnaround time in business days."
          },
          "analytes_count": {
            "type": "integer"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "recommended_for": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "analytes_by_category": {
            "type": "object",
            "description": "Analyte names tested by the product, grouped by category name.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "BrowseProduct": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Product"
          },
          {
            "type": "object",
            "required": [
              "matching_analytes",
              "match_strength"
            ],
            "properties": {
              "matching_analytes": {
                "type": "array",
                "description": "Requested contaminants this product tests for.",
                "items": {
                  "type": "string"
                }
              },
              "match_strength": {
                "type": "integer",
                "description": "Number of requested contaminants matched."
              }
            }
          }
        ]
      },
      "CompareProduct": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Product"
          },
          {
            "type": "object",
            "required": [
              "methods",
              "selftest_analytes",
              "compliance",
              "activation_price"
            ],
            "properties": {
              "methods": {
                "type": "array",
                "description": "Lab test methods, e.g. EPA 200.8.",
                "items": {
                  "type": "string"
                }
              },
              "selftest_analytes": {
                "type": "array",
                "description": "Analytes measured with an included self-test.",
                "items": {
                  "type": "string"
                }
              },
              "compliance": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Regulatory agency the test complies with."
              },
              "activation_price": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Upfront price in USD for the pay-later option, if offered."
              }
            }
          }
        ]
      },
      "Summary": {
        "type": "object",
        "required": [
          "total",
          "page",
          "page_size",
          "total_pages",
          "applied_filters"
        ],
        "properties": {
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "page_size": {
            "type": "integer"
          },
          "total_pages": {
            "type": "integer"
          },
          "applied_filters": {
            "type": "object",
            "required": [
              "contaminants",
              "matrices"
            ],
            "properties": {
              "contaminants": {
                "type": "array",
                "description": "Contaminant names after resolving numeric IDs.",
                "items": {
                  "type": "string"
                }
              },
              "matrices": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "ValidationError": {
        "type": "object",
        "required": [
          "result",
          "message"
        ],
        "properties": {
          "result": {
            "type": "string",
            "const": "ERROR"
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "description": "Per-field messages. Present only when the request sends Accept: application/json.",
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
