openapi: 3.0.0
info:
  title: Reddit User Comments API
  description: |
    The Reddit User Comments API returns the comments a Reddit user posted, sorted by new, hot, top or controversial, with top limited to a time range. Each comment comes with the post it was made on, its subreddit and, for a reply, the user it answers. Comments made in NSFW communities are left out unless `safe` is `off`, and an NSFW profile returns an error unless `safe` is `off`. Reddit returns no comments for users who hide them from their profile, and a deleted, suspended or unknown account returns an error.

    Pages are cursor-based: pass `pagination.next_page_token` from one response as `next_page_token`, with the same `username`, `sort_by` and `time_period`, to get the next page. A page holds about 25 comments, and Reddit lists up to about 1,000 comments per sort.

    **Cross-linking**: pass the `author.username` of a Reddit Search or Reddit Post API result, or the `profile.username` from the Reddit User API, as `username`, and a comment's `post.id` to the Reddit Post API as `post_id` for the post and its top comments.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Reddit User Comments
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine to use
          schema:
            type: string
            enum: ["reddit_user_comments"]
            default: "reddit_user_comments"
        - name: username
          in: query
          required: true
          description: Reddit username, such as `spez`, or a link to the user's profile.
          schema:
            type: string
        - name: sort_by
          in: query
          required: false
          description: Order of the comments.
          schema:
            type: string
            enum: ["new", "hot", "top", "controversial"]
            default: "new"
        - name: time_period
          in: query
          required: false
          description: Time range of the comments. Only accepted when `sort_by` is `top`. Reddit's default is `any_time`.
          schema:
            type: string
            enum: ["last_hour", "last_day", "last_week", "last_month", "last_year", "any_time"]
        - name: safe
          in: query
          required: false
          description: Set to `off` to include comments made in NSFW communities and the comments of an NSFW profile.
          schema:
            type: string
            enum: ["active", "off"]
            default: "active"
        - name: next_page_token
          in: query
          required: false
          description: Token for the next page of comments, from `pagination.next_page_token` of the previous response.
          schema:
            type: string
            pattern: '^dDFf[A-Za-z0-9+/]{2,40}={0,2}$'
      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'
        error:
          type: string
          description: Error message explaining why no comments were returned.
        comments:
          type: array
          description: Comments the user posted, in the order Reddit lists them.
          items:
            $ref: '#/components/schemas/Comment'
        pagination:
          $ref: '#/components/schemas/Pagination'
    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: Reddit URL of the user's comments
        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
        username:
          type: string
          description: Username of the user whose comments were listed
        sort_by:
          type: string
          description: Order of the comments
        time_period:
          type: string
          description: Time range of the comments
        safe:
          type: string
          description: NSFW filter setting
        next_page_token:
          type: string
          description: Token of the page requested
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Token to pass as `next_page_token` to get the next page of comments.
    Comment:
      type: object
      required: [position, id, author, link, score, iso_date, post, subreddit]
      properties:
        position:
          type: integer
          description: Position of the comment on the page.
        id:
          type: string
          description: Reddit fullname of the comment, prefixed with `t1_`.
        author:
          $ref: '#/components/schemas/CommentAuthor'
        text:
          type: string
          description: Text of the comment, with paragraphs separated by blank lines.
        text_links:
          type: array
          description: Links to pages outside Reddit found in the comment.
          items:
            type: string
        image:
          type: string
          description: Image or GIF posted in the comment.
        link:
          type: string
          description: Link to the comment on Reddit.
        score:
          type: integer
          description: Net vote score of the comment.
        iso_date:
          type: string
          format: date-time
          description: Date the comment was posted, in ISO 8601.
        distinguished:
          type: string
          description: Role the user commented with, such as `moderator` or `admin`.
        is_submitter:
          type: boolean
          description: Whether the user also wrote the post.
        is_pinned:
          type: boolean
          description: Whether the comment is pinned to the top of the post's comments.
        is_locked:
          type: boolean
          description: Whether the comment is locked for replies.
        is_removed:
          type: boolean
          description: Whether Reddit removed the comment.
        reply_to:
          $ref: '#/components/schemas/CommentReplyTo'
        post:
          $ref: '#/components/schemas/CommentPost'
        subreddit:
          $ref: '#/components/schemas/CommentSubreddit'
    CommentAuthor:
      type: object
      required: [username, id, link]
      properties:
        username:
          type: string
          description: Username of the author.
        id:
          type: string
          description: Reddit fullname of the author, prefixed with `t2_`.
        link:
          type: string
          description: Link to the author's profile.
    CommentReplyTo:
      type: object
      required: [username, link]
      properties:
        username:
          type: string
          description: Username of the author of the comment this one replies to.
        link:
          type: string
          description: Link to the profile of the author of the comment this one replies to.
    CommentPost:
      type: object
      required: [id, link]
      properties:
        id:
          type: string
          description: Reddit fullname of the post the comment was made on, prefixed with `t3_`.
        title:
          type: string
          description: Title of the post.
        link:
          type: string
          description: Link to the post on Reddit.
        removed_by:
          type: string
          description: Who removed the post, `author`, `moderator` or `reddit`.
    CommentSubreddit:
      type: object
      required: [name, link]
      properties:
        name:
          type: string
          description: Name of the subreddit the comment was made in, `u_` and the username for a post made on a profile.
        link:
          type: string
          description: Link to the subreddit, or to the profile for a post made on it.
        icon:
          type: string
          description: Icon image of the subreddit, or of the profile for a post made on it.
        is_nsfw:
          type: boolean
          description: Whether the subreddit is marked NSFW, judged only by the page's comments when `safe` is `off`.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
