openapi: 3.0.0
info:
  title: Wikipedia Search API
  description: |
    Search the full text of one Wikipedia edition.

    Each result carries the page id, title, link, a snippet with the words the search matched, the short description, the Wikidata id, a thumbnail, the time of the last edit and the page's size and word count. A result can also name the section, the redirect or the categories the search matched.

    `search_information.did_you_mean` is the spelling Wikipedia suggests, which it also gives for some correctly spelled terms.

    The `q` parameter takes Wikipedia's own search operators, such as `intitle:`, `incategory:` and quoted phrases. Wikipedia serves the first 10,000 results of a search, and the order can change slightly between requests, so a result can repeat on the next page.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Wikipedia Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `wikipedia_search`'
          schema:
            type: string
            enum: ["wikipedia_search"]
        - name: q
          in: query
          required: true
          description: The terms to search for, up to 300 characters. Wikipedia's search operators, such as `intitle:` and `incategory:`, are supported.
          schema:
            type: string
            maxLength: 300
        - name: language
          in: query
          required: false
          description: Wikipedia edition to search, by the code in its address, such as `en`, `de` or `zh-yue`.
          schema:
            type: string
            enum: ["ab", "ace", "ady", "af", "als", "alt", "am", "ami", "an", "ang", "ann", "anp", "ar", "arc", "ary", "arz", "as", "ast", "atj", "av", "avk", "awa", "ay", "az", "azb", "ba", "ban", "bar", "bat-smg", "bbc", "bcl", "bdr", "be", "be-tarask", "bew", "bg", "bh", "bi", "bjn", "blk", "bm", "bn", "bo", "bol", "bpy", "br", "bs", "btm", "bug", "bxr", "ca", "cbk-zam", "cdo", "ce", "ceb", "ch", "chr", "chy", "ckb", "co", "crh", "cs", "csb", "cu", "cv", "cy", "da", "dag", "de", "dga", "din", "diq", "dsb", "dtp", "dty", "dv", "dz", "ee", "el", "eml", "en", "eo", "es", "et", "eu", "ext", "fa", "fat", "ff", "fi", "fiu-vro", "fj", "fo", "fon", "fr", "frp", "frr", "fur", "fy", "ga", "gag", "gan", "gcr", "gd", "gl", "glk", "gn", "gom", "gor", "got", "gpe", "gu", "guc", "gur", "guw", "gv", "ha", "hak", "haw", "he", "hi", "hif", "hr", "hsb", "ht", "hu", "hy", "hyw", "ia", "iba", "id", "ie", "ig", "igl", "ik", "ilo", "inh", "io", "is", "isv", "it", "iu", "ja", "jam", "jbo", "jv", "ka", "kaa", "kab", "kai", "kaj", "kbd", "kbp", "kcg", "kg", "kge", "ki", "kk", "km", "kn", "knc", "ko", "koi", "krc", "ks", "ksh", "ku", "kus", "kv", "kw", "ky", "la", "lad", "lb", "lbe", "lez", "lfn", "lg", "li", "lij", "lld", "lmo", "ln", "lo", "lt", "ltg", "lv", "mad", "mag", "mai", "map-bms", "mdf", "mg", "mhr", "mi", "min", "mk", "ml", "mn", "mni", "mnw", "mos", "mr", "mrj", "ms", "mt", "mwl", "my", "myv", "mzn", "nah", "nap", "nds", "nds-nl", "ne", "new", "nia", "nl", "nn", "no", "nov", "nqo", "nr", "nrm", "nso", "nup", "nv", "ny", "oc", "olo", "om", "or", "os", "pa", "pag", "pam", "pap", "pcd", "pcm", "pdc", "pfl", "pi", "pl", "pms", "pnb", "pnt", "ppl", "ps", "pt", "pwn", "qu", "rki", "rm", "rmy", "rn", "ro", "roa-rup", "roa-tara", "rsk", "ru", "rue", "rw", "sa", "sah", "sat", "sc", "scn", "sco", "sd", "se", "sg", "sh", "shi", "shn", "si", "simple", "sk", "skr", "sl", "sm", "smn", "sn", "so", "sq", "sr", "srn", "ss", "st", "stq", "su", "sv", "sw", "syl", "szl", "szy", "ta", "tay", "tcy", "tdd", "te", "tet", "tg", "th", "ti", "tig", "tk", "tl", "tly", "tn", "to", "tok", "tpi", "tr", "trv", "ts", "tt", "tum", "tw", "ty", "tyv", "udm", "ug", "uk", "ur", "uz", "ve", "vec", "vep", "vi", "vls", "vo", "wa", "war", "wo", "wuu", "xal", "xh", "xmf", "yi", "yo", "za", "zea", "zgh", "zh", "zh-classical", "zh-min-nan", "zh-yue", "zu"]
            default: "en"
        - name: sort_by
          in: query
          required: false
          description: Sorts the results by relevance, by the time of the last edit, by the time the page was created, by the number of links to the page, by title, or at random.
          schema:
            type: string
            enum: ["relevance", "last_edit_desc", "last_edit_asc", "create_timestamp_desc", "create_timestamp_asc", "incoming_links_desc", "incoming_links_asc", "title_natural_asc", "title_natural_desc", "random"]
            default: "relevance"
        - name: namespace
          in: query
          required: false
          description: Namespaces to search, as ids comma-separated, such as `0` for articles or `14` for categories, or `all` for every namespace.
          schema:
            type: string
            pattern: '^(all|\d+(,\d+)*)$'
            default: "0"
        - name: page
          in: query
          required: false
          description: Page of results. Wikipedia serves the first 10,000 results, so the last page is 500 when `num` is 20.
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: num
          in: query
          required: false
          description: Number of results per page.
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Validation Error. There is an issue with query parameters, such as missing required parameters or invalid values.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication Error. The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate Limit Exceeded. The number of allowed requests has been exceeded. Consider upgrading your plan or waiting for the limit to reset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server Error. Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Timeout. We could not retrieve results in 90 seconds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'Use Bearer authentication. Format: "Bearer YOUR_API_KEY"'
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api_key
      description: Pass API key as query parameter
  schemas:
    SearchResponse:
      type: object
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        search_information:
          $ref: '#/components/schemas/SearchInformation'
        organic_results:
          type: array
          description: Pages Wikipedia lists for the search, in Wikipedia's order.
          items:
            $ref: '#/components/schemas/OrganicResult'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Why the search returned no pages.
    SearchMetadata:
      type: object
      required: [status, created_at]
      properties:
        id:
          type: string
          description: "Unique identifier for the search request"
        status:
          type: string
          description: "Status of the search request"
        created_at:
          type: string
          format: date-time
          description: "Timestamp when the search was created"
        request_time_taken:
          type: number
          description: "Time taken to make the request in seconds"
        parsing_time_taken:
          type: number
          description: "Time taken to parse the results in seconds"
        total_time_taken:
          type: number
          description: "Total time taken for the search in seconds"
        request_url:
          type: string
          description: "Wikipedia search page for this search"
        html_url:
          type: string
          description: "URL to view the raw results"
        json_url:
          type: string
          description: "URL to view JSON results"
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine used
        q:
          type: string
          description: The terms searched for
        language:
          type: string
          description: Wikipedia edition searched
        sort_by:
          type: string
          description: Sort order
        namespace:
          type: string
          description: Namespaces searched
        num:
          type: integer
          description: Number of results per page
        page:
          type: integer
          description: Page of results
    SearchInformation:
      type: object
      required: [total_results]
      properties:
        total_results:
          type: integer
          description: Number of pages matching the search.
        did_you_mean:
          type: string
          description: Spelling Wikipedia suggests for the search terms.
    OrganicResult:
      type: object
      required: [position, link]
      properties:
        position:
          type: integer
          description: Position of the page in the results, counted across pages.
        page_id:
          type: integer
          description: Wikipedia page id of the page.
        title:
          type: string
          description: Page title.
        link:
          type: string
          description: Link to the page.
        snippet:
          type: string
          description: Text from the page around the words the search matched.
        snippet_highlighted_words:
          type: array
          description: Words Wikipedia highlights in the snippet.
          items:
            type: string
        description:
          type: string
          description: Short description of the page's subject.
        wikidata_id:
          type: string
          description: Wikidata item id of the page's subject.
        thumbnail:
          type: string
          description: Lead image of the page.
        updated_at:
          type: string
          format: date-time
          description: Time of the page's last edit, in UTC.
        size_bytes:
          type: integer
          description: Size of the page's source text in bytes.
        word_count:
          type: integer
          description: Number of words on the page.
        matched_section:
          $ref: '#/components/schemas/MatchedSection'
        redirect_title:
          type: string
          description: Title of the redirect to the page that the search matched.
        category_snippet:
          type: string
          description: Categories of the page that the search matched.
        is_disambiguation:
          type: boolean
          description: Whether the page is a disambiguation page.
        namespace:
          type: integer
          description: Id of the page's namespace.
    MatchedSection:
      type: object
      required: [title, link]
      properties:
        title:
          type: string
          description: Title of the section the search matched.
        link:
          type: string
          description: Link to the section.
    Pagination:
      type: object
      required: [current]
      properties:
        current:
          type: integer
          description: Current page.
        next:
          type: string
          description: Wikipedia search page with the next results.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
