{
  "openapi": "3.1.0",
  "info": {
    "title": "RND TV public agent API",
    "version": "1.0.0",
    "description": "Anonymous read and discovery endpoints for RND TV. The interactive agent control surface uses MCP at /mcp.",
    "contact": {
      "name": "Sergei Vorniches",
      "url": "https://vorniches.com",
      "email": "loto@grm.sh"
    }
  },
  "servers": [{ "url": "https://rndtv.me" }],
  "security": [],
  "paths": {
    "/ask": {
      "get": {
        "operationId": "askRndTvGet",
        "description": "Ask a bounded natural-language question about RND TV public documentation.",
        "parameters": [
          { "name": "query", "in": "query", "required": true, "schema": { "type": "string", "maxLength": 500 } },
          { "name": "streaming", "in": "query", "required": false, "schema": { "type": "boolean", "default": false } }
        ],
        "responses": {
          "200": { "description": "NLWeb JSON answer or SSE stream.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NLWebAnswer" } }, "text/event-stream": { "schema": { "type": "string" } } } },
          "422": { "description": "Missing or invalid query.", "content": { "application/json": { "schema": { "oneOf": [{ "$ref": "#/components/schemas/ErrorResponse" }, { "$ref": "#/components/schemas/ValidationErrorResponse" }] } } } }
        }
      },
      "post": {
        "operationId": "askRndTvPost",
        "description": "Ask about RND TV using the NLWeb request shape, optionally with SSE streaming.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NLWebRequest" } } } },
        "responses": {
          "200": { "description": "NLWeb JSON answer or SSE stream.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NLWebAnswer" } }, "text/event-stream": { "schema": { "type": "string" } } } },
          "400": { "description": "Malformed JSON body.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "422": { "description": "Missing or invalid query.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/feed": {
      "get": {
        "operationId": "getRandomRndTvFeed",
        "description": "Return a bounded batch of randomly dealt public Internet Archive channel records. MCP is preferred for stateful agent viewing.",
        "parameters": [
          { "name": "n", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10 } },
          { "name": "session", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Random channel records.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/ChannelRecord" } } } } },
          "422": { "description": "Invalid query parameter.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "NLWebRequest": {
        "type": "object",
        "required": ["query"],
        "properties": {
          "query": { "oneOf": [{ "type": "string" }, { "type": "object", "required": ["text"], "properties": { "text": { "type": "string", "maxLength": 500 } } }] },
          "prefer": { "type": "object", "properties": { "streaming": { "type": "boolean" } } },
          "query_id": { "type": "string", "minLength": 1, "maxLength": 128 }
        }
      },
      "NLWebAnswer": {
        "type": "object",
        "required": ["query_id", "results", "_meta"],
        "properties": {
          "query_id": { "type": "string" },
          "results": { "type": "array", "items": { "type": "object" } },
          "_meta": { "type": "object", "required": ["response_type", "version"], "properties": { "response_type": { "type": "string" }, "version": { "type": "string" } } }
        }
      },
      "ChannelRecord": {
        "type": "object",
        "required": ["id", "src"],
        "properties": {
          "id": { "type": "string" },
          "src": { "type": "string", "format": "uri" },
          "channel_title": { "type": ["string", "null"] },
          "post": { "type": ["string", "null"], "format": "uri" },
          "source": { "type": ["string", "null"] },
          "duration": { "type": ["string", "null"] },
          "text": { "type": ["string", "null"] }
        },
        "additionalProperties": true
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["detail"],
        "properties": { "detail": { "type": "string" } },
        "additionalProperties": false
      },
      "ValidationErrorResponse": {
        "type": "object",
        "required": ["detail"],
        "properties": {
          "detail": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["loc", "msg", "type"],
              "properties": {
                "loc": { "type": "array", "items": { "oneOf": [{ "type": "string" }, { "type": "integer" }] } },
                "msg": { "type": "string" },
                "type": { "type": "string" }
              },
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": false
      }
    }
  }
}
