openapi: 3.0.0
info:
  title: Reddit User API
  description: |
    The Reddit User API returns the profile of one Reddit user: their karma, account age, bio and avatar, how many posts and comments they have made, whether they have Reddit Premium, a verification badge or an automated account, and the communities Reddit lists them as active in. Users can hide those communities, and the response leaves them out then. A deleted, suspended or unknown account returns an error, and an NSFW profile is returned only when `safe` is `off`.

    **Cross-linking**: pass the `author.username` of a post from the Reddit Search API or the Reddit Post API as `username`.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Reddit User
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine to use
          schema:
            type: string
            enum: ["reddit_user"]
            default: "reddit_user"
        - name: username
          in: query
          required: true
          description: Reddit username, such as `spez`, or a link to the user's profile.
          schema:
            type: string
        - name: safe
          in: query
          required: false
          description: Set to `off` to return an NSFW profile.
          schema:
            type: string
            enum: ["active", "off"]
            default: "active"
      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 profile was returned.
        profile:
          $ref: '#/components/schemas/Profile'
        active_communities:
          type: array
          description: Communities Reddit lists the user as active in, in the order Reddit shows them.
          items:
            $ref: '#/components/schemas/ActiveCommunity'
    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 profile
        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 profile requested
        safe:
          type: string
          description: NSFW filter setting
    Profile:
      type: object
      required: [username, link, post_karma, comment_karma, total_karma, created_at]
      properties:
        username:
          type: string
          description: Username of the user.
        id:
          type: string
          description: Reddit fullname of the user, prefixed with `t2_`.
        link:
          type: string
          description: Link to the user's profile on Reddit.
        bio:
          type: string
          description: Bio the user wrote on their profile.
        avatar:
          type: string
          description: Avatar or profile picture of the user.
        post_karma:
          type: integer
          description: Karma the user earned from posts.
        comment_karma:
          type: integer
          description: Karma the user earned from comments.
        total_karma:
          type: integer
          description: Post and comment karma of the user added together.
        posts:
          type: integer
          description: Number of posts the user has made, which Reddit updates once a day.
        comments:
          type: integer
          description: Number of comments the user has made, which Reddit updates once a day.
        created_at:
          type: string
          format: date-time
          description: Date the account was created, in ISO 8601.
        is_verified:
          type: boolean
          description: Whether Reddit shows a verification badge for the user.
        is_premium:
          type: boolean
          description: Whether the user has Reddit Premium.
        is_bot:
          type: boolean
          description: Whether Reddit labels the account as automated.
        is_nsfw:
          type: boolean
          description: Whether the profile is marked NSFW.
    ActiveCommunity:
      type: object
      required: [position, id, name, link]
      properties:
        position:
          type: integer
          description: Position of the community in the list.
        id:
          type: string
          description: Reddit fullname of the community, prefixed with `t5_`.
        name:
          type: string
          description: Name of the community.
        link:
          type: string
          description: Link to the community on Reddit.
        description:
          type: string
          description: Public description of the community.
        icon:
          type: string
          description: Icon image of the community.
        subscribers:
          type: integer
          description: Number of members of the community.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
