openapi: 3.0.0
info:
  title: Hacker News Item API
  description: |
    The Hacker News Item API returns one Hacker News story, comment, job, poll or poll option by its ID or link: its author, time, points, comment count, title, link and text, the item it replies to, and the IDs of its direct replies in the order Hacker News ranks them. Deleted and dead items come back with the fields Hacker News still keeps, marked with `is_deleted` or `is_dead`. An ID Hacker News doesn't have returns an `error`.

    **Cross-linking**: every ID in `child_ids`, `parent_id`, `poll_id` and `option_ids` can be passed back as `item_id` to fetch that item.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Hacker News Item
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `hacker_news_item`'
          schema:
            type: string
            enum: ["hacker_news_item"]
        - name: item_id
          in: query
          required: false
          description: ID of the Hacker News item, such as `8863`. Required if url is not provided, and cannot be combined with it.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,18}$'
        - name: url
          in: query
          required: false
          description: Link to the item's page on news.ycombinator.com, such as `https://news.ycombinator.com/item?id=8863`. Required if item_id is not provided, and cannot be combined with it.
          schema:
            type: string
            maxLength: 2048
        - name: zero_retention
          in: query
          required: false
          description: Set to true to disable logging and persistent storage for this request. Enterprise plans only.
          schema:
            type: boolean
            default: false
      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'
        '403':
          description: Forbidden. Zero data retention is not available to the account, or the account requires `zero_retention=true`.
          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'
        error:
          type: string
          description: Error message explaining why no item was returned.
        item:
          $ref: '#/components/schemas/Item'
    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: "Hacker News page of the item"
        html_url:
          type: string
          description: "URL to view HTML results"
        json_url:
          type: string
          description: "URL to view JSON results"
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine used
        item_id:
          type: string
          description: ID of the item requested
        url:
          type: string
          description: Link to the item requested
        zero_retention:
          type: boolean
          description: Whether zero data retention was requested
    Item:
      type: object
      required: [item_id, type, discussion_link, created_at]
      properties:
        item_id:
          type: string
          description: Hacker News ID of the item.
        type:
          type: string
          enum: ["story", "comment", "job", "poll", "pollopt"]
          description: Kind of item, where Ask HN and Show HN posts are `story`.
        title:
          type: string
          description: Title of the story, job or poll.
        link:
          type: string
          description: Link the story or job points to.
        discussion_link:
          type: string
          description: Link to the item's page on Hacker News.
        author:
          type: string
          description: Username of the item's author.
        points:
          type: integer
          description: Points the item has, which for a poll option are its votes.
        comments:
          type: integer
          description: Number of comments in the item's thread, replies to replies included.
        text:
          type: string
          description: Text of the item as plain text, with a blank line between paragraphs and each link written out in full.
        parent_id:
          type: string
          description: ID of the item this comment replies to.
        poll_id:
          type: string
          description: ID of the poll this option belongs to.
        option_ids:
          type: array
          description: IDs of the poll's options, in the order the poll lists them.
          items:
            type: string
        child_ids:
          type: array
          description: IDs of the item's direct replies, in the order Hacker News ranks them.
          items:
            type: string
        created_at:
          type: string
          format: date-time
          description: Time the item was posted, in UTC.
        is_deleted:
          type: boolean
          description: Whether the item was deleted.
        is_dead:
          type: boolean
          description: Whether Hacker News killed the item, which hides it from most readers.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
