{
  "openapi": "3.1.0",
  "info": {
    "title": "PolyPatch-11k API",
    "version": "1.0.0",
    "summary": "Open API over a multi-language GitHub issue-and-patch corpus.",
    "description": "PolyPatch-11k is a corpus of 11,611 real-world issue-and-patch instances mined from 3,886 GitHub repositories across 7 languages. It is a training and mining corpus, NOT an execution-verified benchmark: `fail_to_pass` ids are derived statically from each test patch and no test was ever executed. The gold solution `patch` column is deliberately withheld from every response. Access is free and unauthenticated, rate limited to 120 requests per minute per IP.",
    "contact": {
      "name": "Lateos",
      "email": "partnerships@lateos.ai",
      "url": "https://lateos.ai/categories/datasets/polypatch/"
    },
    "license": {
      "name": "MIT (compilation and derived columns only; each instance's code carries its upstream repository's license)",
      "url": "https://lateos.ai/licensing/"
    }
  },
  "servers": [
    { "url": "https://polypatch.lateos.ai", "description": "Production" }
  ],
  "tags": [
    { "name": "instances", "description": "Retrieve corpus instances." },
    { "name": "metadata", "description": "Schema, counts, and bulk access." }
  ],
  "paths": {
    "/v1/instances/fetch": {
      "post": {
        "tags": ["instances"],
        "operationId": "fetchInstances",
        "summary": "Sample instances from the corpus",
        "description": "Returns a random sample of instances from the filtered subset. Use /v1/instances/search to find specific instances, and /v1/bulk if you need a large portion of the corpus.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/FetchRequest" },
              "examples": {
                "default": { "summary": "Ten random instances", "value": { "limit": 10 } },
                "rust_with_ci": {
                  "summary": "Rust instances carrying CI metadata",
                  "value": { "language": "rust", "ci_annotated": true, "min_tests": 2, "limit": 5 }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matching instances.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/FetchResponse" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/instances/search": {
      "post": {
        "tags": ["instances"],
        "operationId": "searchInstances",
        "summary": "Full-text search over problem statements",
        "description": "BM25-ranked FTS5 search across issue text. Filters combine with the query.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SearchRequest" },
              "examples": {
                "default": {
                  "summary": "Find race-condition issues in Go",
                  "value": { "q": "race condition", "language": "go", "limit": 10 }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ranked matches.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/instances/{instance_id}": {
      "get": {
        "tags": ["instances"],
        "operationId": "getInstance",
        "summary": "Retrieve a single instance",
        "parameters": [
          {
            "name": "instance_id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "example": "tokio-rs__tokio-6978"
          }
        ],
        "responses": {
          "200": {
            "description": "The instance.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "instance": { "$ref": "#/components/schemas/Instance" },
                    "caveats": { "type": "string" }
                  }
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/schema": {
      "get": {
        "tags": ["metadata"],
        "operationId": "getSchema",
        "summary": "Field contract, withheld columns, caveats, license, and citation",
        "responses": {
          "200": {
            "description": "Schema document.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/v1/count": {
      "get": {
        "tags": ["metadata"],
        "operationId": "getCorpusStats",
        "summary": "Corpus totals and per-language breakdown",
        "responses": {
          "200": {
            "description": "Corpus statistics.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/CorpusStats" } }
            }
          },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/v1/bulk": {
      "get": {
        "tags": ["metadata"],
        "operationId": "bulkDownload",
        "summary": "Redirect to the full compressed corpus dump",
        "description": "302 to a 27.5 MB zstd-compressed JSONL file containing all 11,611 instances. Use this instead of paging through /v1/instances/fetch.",
        "responses": {
          "302": {
            "description": "Redirect to the dump.",
            "headers": {
              "Location": { "schema": { "type": "string", "format": "uri" } }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": ["metadata"],
        "operationId": "mcpJsonRpc",
        "summary": "MCP server (Streamable HTTP, JSON-RPC 2.0)",
        "description": "Tools: fetch_instances, search_instances, get_instance, get_corpus_stats. No authentication. GET on this path returns server metadata and the tool list.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "type": "object" },
              "examples": {
                "tools_list": {
                  "summary": "List tools",
                  "value": { "jsonrpc": "2.0", "id": 1, "method": "tools/list" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "InstanceFilters": {
        "type": "object",
        "properties": {
          "language": {
            "type": "string",
            "enum": ["python", "rust", "go", "cpp", "php", "java", "javascript"],
            "description": "Language filter."
          },
          "repo": { "type": "string", "description": "Exact repository, e.g. \"tokio-rs/tokio\"." },
          "ci_annotated": {
            "type": "boolean",
            "description": "Only instances carrying CI workflow metadata (2,681 instances, 23.1%)."
          },
          "min_tests": {
            "type": "integer",
            "minimum": 0,
            "description": "Only instances with at least this many attributed test ids."
          }
        }
      },
      "FetchRequest": {
        "allOf": [
          { "$ref": "#/components/schemas/InstanceFilters" },
          {
            "type": "object",
            "properties": {
              "limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 10 }
            }
          }
        ]
      },
      "SearchRequest": {
        "allOf": [
          { "$ref": "#/components/schemas/InstanceFilters" },
          {
            "type": "object",
            "required": ["q"],
            "properties": {
              "q": { "type": "string", "minLength": 1, "maxLength": 200 },
              "limit": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10 }
            }
          }
        ]
      },
      "Provenance": {
        "type": "object",
        "properties": {
          "instance_id": { "type": "string" },
          "content_hash": {
            "type": "string",
            "description": "SHA-256 over the canonical task fields."
          },
          "source_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "The originating GitHub commit."
          },
          "corpus": { "type": "string" },
          "tier": { "type": "string", "enum": ["gold"] },
          "test_ids_verified": {
            "type": "boolean",
            "description": "Always false. No test in this corpus has been executed."
          }
        }
      },
      "Instance": {
        "type": "object",
        "description": "A task instance. The gold solution `patch` is never included.",
        "properties": {
          "instance_id": { "type": "string", "example": "tokio-rs__tokio-6978" },
          "repo": { "type": "string", "example": "tokio-rs/tokio" },
          "base_commit": { "type": ["string", "null"] },
          "environment_setup_commit": { "type": ["string", "null"] },
          "version": { "type": ["string", "null"] },
          "created_at": { "type": ["string", "null"] },
          "language": { "type": "string" },
          "problem_statement": { "type": "string", "description": "The issue text." },
          "test_patch": {
            "type": "string",
            "description": "Unified diff of the test changes that define the task."
          },
          "fail_to_pass": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Test ids attributed to the test patch. STATICALLY DERIVED, NOT EXECUTION-VERIFIED."
          },
          "test_count": { "type": "integer", "minimum": 1, "maximum": 20 },
          "ci_name_list": { "type": "array", "items": { "type": "string" } },
          "ci_annotated": { "type": "boolean" },
          "provenance": { "$ref": "#/components/schemas/Provenance" }
        }
      },
      "FetchResponse": {
        "type": "object",
        "properties": {
          "corpus": { "type": "string" },
          "instances": { "type": "array", "items": { "$ref": "#/components/schemas/Instance" } },
          "instances_returned": { "type": "integer" },
          "bulk_download": { "type": "string" },
          "caveats": { "type": "string" }
        }
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "corpus": { "type": "string" },
          "query": { "type": "string" },
          "instances": { "type": "array", "items": { "$ref": "#/components/schemas/Instance" } },
          "matches_returned": { "type": "integer" },
          "caveats": { "type": "string" }
        }
      },
      "CorpusStats": {
        "type": "object",
        "properties": {
          "corpus": { "type": "string" },
          "version": { "type": "string" },
          "tier": { "type": "string" },
          "total_instances": { "type": "integer", "example": 11611 },
          "repositories": { "type": "integer", "example": 3886 },
          "total_test_ids": { "type": "integer" },
          "ci_annotated": { "type": "integer", "example": 2681 },
          "ci_annotated_share": { "type": "number", "example": 23.1 },
          "by_language": { "type": "object", "additionalProperties": { "type": "integer" } },
          "caveats": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Malformed request body or invalid filter value.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "NotFound": {
        "description": "No instance with that id.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RateLimited": {
        "description": "More than 120 requests per minute from this IP. Use /v1/bulk for bulk access.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Unavailable": {
        "description": "Corpus database temporarily unreachable.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    }
  }
}
