{
  "openapi": "3.1.0",
  "info": {
    "title": "Scaff Search API",
    "version": "2.0.0",
    "summary": "Free web meta-search API. No API key.",
    "description": "Web search results as JSON, aggregated from several engines via SearXNG. No authentication. Requests are logged for research: https://search.scaff.dev/privacy",
    "termsOfService": "https://search.scaff.dev/privacy"
  },
  "servers": [{ "url": "https://search.scaff.dev" }],
  "externalDocs": { "url": "https://search.scaff.dev/docs" },
  "paths": {
    "/api/search": {
      "get": {
        "operationId": "searchWeb",
        "summary": "Search the web",
        "description": "Returns web search results with title, url and snippet.",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "description": "Search query (max 400 chars)", "schema": { "type": "string", "maxLength": 400 }, "example": "rust async runtime" },
          { "name": "num", "in": "query", "description": "Number of results", "schema": { "type": "integer", "minimum": 1, "maximum": 20, "default": 10 } },
          { "name": "page", "in": "query", "description": "Result page", "schema": { "type": "integer", "minimum": 1, "maximum": 10, "default": 1 } },
          { "name": "lang", "in": "query", "description": "Language code", "schema": { "type": "string", "default": "en" } },
          { "name": "safe", "in": "query", "description": "Safe search", "schema": { "type": "integer", "enum": [0, 1], "default": 0 } }
        ],
        "responses": {
          "200": { "description": "Search results", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } } } },
          "400": { "description": "Missing q", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "503": { "description": "All backends unavailable; retry later", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/status": {
      "get": {
        "operationId": "getStatus",
        "summary": "Backend engine health",
        "responses": { "200": { "description": "Status", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    }
  },
  "components": {
    "schemas": {
      "Result": {
        "type": "object",
        "required": ["title", "url", "snippet"],
        "properties": {
          "title": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "snippet": { "type": "string" },
          "engine": { "type": "string", "description": "Engine that returned the result" },
          "published": { "type": ["string", "null"], "description": "Publication date if known" }
        }
      },
      "SearchResponse": {
        "type": "object",
        "required": ["query", "count", "results"],
        "properties": {
          "query": { "type": "string" },
          "page": { "type": "integer" },
          "count": { "type": "integer" },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/Result" } },
          "suggestions": { "type": "array", "items": { "type": "string" } },
          "source": { "type": "string" },
          "engines": { "type": "array", "items": { "type": "string" } },
          "cached": { "type": "boolean" },
          "duration": { "type": "number", "description": "Seconds" }
        }
      },
      "Error": {
        "type": "object",
        "properties": { "error": { "type": "string" }, "usage": { "type": "string" }, "docs": { "type": "string" } }
      }
    }
  }
}