{
  "openapi": "3.1.0",
  "info": {
    "title": "Onyx M3 — Public content API (read-only)",
    "version": "1.0.0",
    "summary": "Read-only content-discovery endpoints for onyxm3.com: semantic knowledge-base search and deploy-time data feeds.",
    "description": "Onyx M3 inc. is an independent industrial compressed-air expert in Québec, Canada (services, training, equipment). Independence: Onyx M3 sells no air compressors.\n\nThis API is READ-ONLY and UNAUTHENTICATED BY DESIGN — the site has no protected resources, which is why no OAuth/OIDC discovery metadata is published.\n\nRate limit: endpoints under /api/* are limited to 20 requests per minute per IP; HTTP 429 on excess — back off at least 60 seconds.\n\nQuotes and transactions are HUMAN flows: https://onyxm3.com/devis (quote cart), https://onyxm3.com/consultation (free 30-min consultation), https://onyxm3.com/contact. The site's POST form endpoints are for its own pages and are intentionally undocumented; agents must not call them.\n\nContent is bilingual: French at the site root, English twin under /en/ (same slugs). Note (FR) : contenu français à la racine, jumeau anglais sous /en/ ; cette API réfère des articles, elle ne rédige rien.\n\nHuman/agent documentation: https://onyxm3.com/docs/api.md",
    "contact": {
      "name": "Onyx M3 inc.",
      "email": "info@onyxm3.com",
      "url": "https://onyxm3.com/contact"
    },
    "termsOfService": "https://onyxm3.com/conditions-utilisation"
  },
  "servers": [{ "url": "https://onyxm3.com" }],
  "paths": {
    "/api/kb-search": {
      "get": {
        "operationId": "kbSearch",
        "summary": "Semantic search over the knowledge base (returns article references, never generated text)",
        "description": "Embeds the query with Workers AI (bge-m3, multilingual) and ranks the knowledge-base sheets by cosine similarity. The API only REFERS to articles — it never generates prose (zero-hallucination design). Fetch the returned `url` to read the article, then cite that URL.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Search query, natural language (French or English). Trimmed server-side; empty → 400 empty_query; longer than 300 characters → 400 query_too_long.",
            "schema": { "type": "string", "minLength": 1, "maxLength": 300 }
          },
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "description": "Corpus language. Any value other than \"en\" falls back to \"fr\" (default).",
            "schema": { "type": "string", "enum": ["fr", "en"], "default": "fr" }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked article references (top 5). If the corpus has no sheet in the requested language, returns `{ \"results\": [], \"best\": 0 }` without `model`.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/KbSearchResults" } }
            }
          },
          "400": {
            "description": "Invalid query. `error` is `empty_query` or `query_too_long`.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "429": {
            "description": "Rate limited (20 requests/min/IP). `error` is `rate_limited`. Back off at least 60 seconds.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "502": {
            "description": "Corpus unavailable. `error` is `corpus_unavailable`.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "503": {
            "description": "Embedding backend unavailable. `error` is `ai_unavailable`.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    },
    "/search-index.json": {
      "get": {
        "operationId": "getSearchIndex",
        "summary": "Site-wide search index (pages, product ranges, models/SKUs, tools, knowledge-base sheets), built at deploy time",
        "description": "Static JSON regenerated on every deployment; served with Cache-Control: public, max-age=300. Useful to resolve a model number / SKU (entries with g=\"modele\", keywords in `k`) or to enumerate tools and pages in both languages.",
        "responses": {
          "200": {
            "description": "Full index plus query-expansion synonym maps.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/SearchIndex" } }
            }
          }
        }
      }
    },
    "/kb-corpus.json": {
      "get": {
        "operationId": "getKbCorpus",
        "summary": "Full knowledge-base corpus (plain text per sheet), built at deploy time",
        "description": "Static JSON regenerated on every deployment; served with Cache-Control: public, max-age=300. Same corpus the semantic search runs on. `text` is the article text deterministically enriched with lay synonyms.",
        "responses": {
          "200": {
            "description": "All knowledge-base sheets, both languages.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/KbCorpus" } }
            }
          }
        }
      }
    },
    "/products-index.json": {
      "get": {
        "operationId": "getProductsIndex",
        "summary": "Sellable model/SKU index with indicative CAD prices, built at deploy time",
        "description": "Static JSON regenerated on every deployment; served with Cache-Control: public, max-age=300. One entry per sellable model/part × language, across every product catalog (dryers, filters, drains, condensate treatment, safety valves, power meters, desiccant media, training equipment, network accessories, IoT devices). Best way to resolve a model number or SKU to its page and price. `priceCAD: null` means the item is quote-only (\"sur devis\") — never inferred or estimated.",
        "responses": {
          "200": {
            "description": "Full product index, both languages.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ProductsIndex" } }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "KbSearchResults": {
        "type": "object",
        "required": ["results", "best"],
        "properties": {
          "results": {
            "type": "array",
            "maxItems": 5,
            "items": { "$ref": "#/components/schemas/KbResult" }
          },
          "best": {
            "type": "number",
            "description": "Score of the best result (0 when there are no results)."
          },
          "model": {
            "type": "string",
            "description": "Embedding model used (currently \"@cf/baai/bge-m3\"). Absent when the corpus has no sheet in the requested language."
          }
        }
      },
      "KbResult": {
        "type": "object",
        "required": ["title", "category", "url", "score"],
        "properties": {
          "title": { "type": "string" },
          "category": { "type": "string", "description": "Human-readable category label, localized." },
          "url": { "type": "string", "description": "Site-relative path of the article (prefix with https://onyxm3.com)." },
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Cosine similarity between the query and the article, rounded to 3 decimals. Higher is better; no official relevance threshold is defined."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error", "results"],
        "properties": {
          "error": {
            "type": "string",
            "enum": ["empty_query", "query_too_long", "rate_limited", "corpus_unavailable", "ai_unavailable"]
          },
          "results": { "type": "array", "maxItems": 0, "description": "Always empty on error." }
        }
      },
      "SearchIndex": {
        "type": "object",
        "required": ["items", "syn"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/SearchIndexItem" }
          },
          "syn": {
            "type": "object",
            "description": "Query-expansion synonym maps (layperson term → technical terms), one map per language.",
            "properties": { "fr": { "type": "object" }, "en": { "type": "object" } }
          }
        }
      },
      "SearchIndexItem": {
        "type": "object",
        "required": ["t", "u", "c", "g", "k", "l"],
        "properties": {
          "t": { "type": "string", "description": "Title (page name, range name, or model number)." },
          "u": { "type": "string", "description": "Site-relative URL, already localized." },
          "c": { "type": "string", "description": "Context / category label." },
          "g": {
            "type": "string",
            "enum": ["modele", "gamme", "outil", "service", "page", "kb"],
            "description": "Entry group: modele = sellable model/SKU, gamme = product range, outil = interactive tool, service = service page, page = other page, kb = knowledge-base sheet."
          },
          "k": { "type": "string", "description": "Extra keywords (e.g. part numbers / SKUs, space-separated). May be empty." },
          "l": { "type": "string", "enum": ["fr", "en"], "description": "Language of the entry." },
          "x": { "type": "string", "description": "Optional extended text (knowledge-base entries only: description + body excerpt)." }
        }
      },
      "KbCorpus": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/KbCorpusItem" }
          }
        }
      },
      "KbCorpusItem": {
        "type": "object",
        "required": ["slug", "lang", "title", "category", "url", "text"],
        "properties": {
          "slug": { "type": "string" },
          "lang": { "type": "string", "enum": ["fr", "en"] },
          "title": { "type": "string" },
          "category": { "type": "string", "description": "Human-readable category label, localized." },
          "url": { "type": "string", "description": "Site-relative path of the article." },
          "text": { "type": "string", "description": "Article text, deterministically enriched with lay synonyms for semantic search." }
        }
      },
      "ProductsIndex": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ProductsIndexItem" }
          }
        }
      },
      "ProductsIndexItem": {
        "type": "object",
        "required": ["ref", "nom", "gamme", "marque", "categorie", "url", "lang", "prixCAD"],
        "properties": {
          "ref": { "type": "string", "description": "Cart key / model reference." },
          "sku": { "type": "string", "description": "Manufacturer part number, when distinct from `ref`. Absent when unknown." },
          "nom": { "type": "string", "description": "Display name of the model/part." },
          "gamme": { "type": "string", "description": "Product range/family name, localized." },
          "marque": { "type": "string", "description": "Brand (e.g. Purestream, BEKO, Walker Filtration, Fluke, EQOfluids)." },
          "categorie": { "type": "string", "description": "Human-readable category label, localized." },
          "url": { "type": "string", "description": "Site-relative path of the product page (prefix with https://onyxm3.com)." },
          "lang": { "type": "string", "enum": ["fr", "en"] },
          "prixCAD": { "type": ["number", "null"], "description": "Indicative CAD list price. null means quote-only (\"sur devis\") — never invented or estimated." }
        }
      }
    }
  }
}
