openapi: 3.0.0
info:
  title: X Profile API
  description: |
    Retrieve an X (formerly Twitter) account's public profile, with its follower, following and post counts, verification and professional labels, and the newest posts its public profile page shows: up to 5 posts, the pinned post first, each with its like, repost, comment, quote and save counts, views where X shows them, media, links and quoted post.

    The posts are the account's most recent posts, not its full timeline, and there is no pagination.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: X Profile Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["x_profile"]
            default: "x_profile"
        - name: username
          in: query
          required: true
          description: X username, with or without the leading @, such as NASA or @NASA. Names of X's own pages, such as home or explore, are refused.
          schema:
            type: string
            pattern: '^@?[A-Za-z0-9_]{1,15}$'
        - 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. Please try again later.
          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'
        profile:
          $ref: '#/components/schemas/Profile'
        posts:
          type: array
          description: Newest posts the profile page shows, up to 5, with the pinned post first.
          items:
            $ref: '#/components/schemas/Post'
        error:
          type: string
          description: Reason no profile was returned, such as an account that doesn't exist, is suspended, is age-restricted or is withheld.

    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: X URL for this search
        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 identifier
        username:
          type: string
          description: X username, without the leading @
        zero_retention:
          type: boolean
          description: Whether zero data retention was requested

    Profile:
      type: object
      required: [id, username, name, link, followers, following, posts, media_posts, created_at, avatar]
      properties:
        id:
          type: string
          description: Numeric X user ID
        username:
          type: string
          description: X username, without the leading @
        name:
          type: string
          description: Display name
        link:
          type: string
          description: URL of the profile on X
        bio:
          type: string
          description: Profile bio, with shortened links expanded
        external_link:
          type: string
          description: Website link shown on the profile
        location:
          type: string
          description: Location shown on the profile
        followers:
          type: integer
          description: Number of followers
        following:
          type: integer
          description: Number of accounts the profile follows
        posts:
          type: integer
          description: Number of posts the account has published
        media_posts:
          type: integer
          description: Number of posts with photos or videos
        is_verified:
          type: boolean
          description: Whether the account shows a verified checkmark
        verified_type:
          type: string
          description: Verification category of the checkmark, such as Business or Government
        is_private:
          type: boolean
          description: Whether the account's posts are protected and visible to approved followers only
        is_business:
          type: boolean
          description: Whether the account is an X Professional account
        professional_type:
          type: string
          description: Kind of X Professional account, Business or Creator
        category:
          type: string
          description: Category the professional account lists, such as Science & Technology
        affiliation:
          type: string
          description: Organization the account is affiliated with, as shown on its affiliate badge
        affiliates:
          type: integer
          description: Number of accounts affiliated with this organization
        birth_date:
          type: string
          format: date
          description: Birth date the account shows publicly
        created_at:
          type: string
          format: date-time
          description: Date and time the account was created
        avatar:
          type: string
          description: URL of the profile picture
        avatar_hd:
          type: string
          description: URL of the larger profile picture the profile header shows, up to 400 by 400 pixels
        banner:
          type: string
          description: URL of the profile banner image

    Post:
      type: object
      required: [position, id, link, iso_date, likes, reposts, comments, quotes, saves]
      properties:
        position:
          type: integer
          description: Position of the post on the profile, starting at 1
        id:
          type: string
          description: Numeric post ID
        link:
          type: string
          description: URL of the post on X
        text:
          type: string
          description: Full text of the post, with shortened links expanded
        iso_date:
          type: string
          format: date-time
          description: Date and time the post was published
        language:
          type: string
          description: Language code X detected for the post text
        likes:
          type: integer
          description: Number of likes
        reposts:
          type: integer
          description: Number of reposts, not counting quote posts
        comments:
          type: integer
          description: Number of replies
        quotes:
          type: integer
          description: Number of quote posts
        saves:
          type: integer
          description: Number of bookmarks
        views:
          type: integer
          description: Number of views
        is_pinned:
          type: boolean
          description: Whether the post is pinned to the profile
        is_nsfw:
          type: boolean
          description: Whether X marks the post as possibly sensitive
        media:
          type: array
          description: Photos, videos and GIFs attached to the post
          items:
            $ref: '#/components/schemas/Media'
        content_links:
          type: array
          description: Links in the post text
          items:
            $ref: '#/components/schemas/ContentLink'
        mentions:
          type: array
          description: Usernames the post mentions, without the leading @
          items:
            type: string
        hashtags:
          type: array
          description: Hashtags in the post, without the leading #
          items:
            type: string
        quoted_post:
          $ref: '#/components/schemas/QuotedPost'

    QuotedPost:
      type: object
      description: Post this post quotes
      required: [id, link, author, iso_date, likes, reposts, comments, quotes]
      properties:
        id:
          type: string
          description: Numeric post ID
        link:
          type: string
          description: URL of the post on X
        author:
          $ref: '#/components/schemas/Author'
        text:
          type: string
          description: Full text of the post, with shortened links expanded
        iso_date:
          type: string
          format: date-time
          description: Date and time the post was published
        language:
          type: string
          description: Language code X detected for the post text
        likes:
          type: integer
          description: Number of likes
        reposts:
          type: integer
          description: Number of reposts, not counting quote posts
        comments:
          type: integer
          description: Number of replies
        quotes:
          type: integer
          description: Number of quote posts
        views:
          type: integer
          description: Number of views
        is_nsfw:
          type: boolean
          description: Whether X marks the post as possibly sensitive
        media:
          type: array
          description: Photos, videos and GIFs attached to the post
          items:
            $ref: '#/components/schemas/Media'
        content_links:
          type: array
          description: Links in the post text
          items:
            $ref: '#/components/schemas/ContentLink'
        mentions:
          type: array
          description: Usernames the post mentions, without the leading @
          items:
            type: string
        hashtags:
          type: array
          description: Hashtags in the post, without the leading #
          items:
            type: string

    Author:
      type: object
      description: Account that published the quoted post
      required: [id, username, name, link, avatar]
      properties:
        id:
          type: string
          description: Numeric X user ID
        username:
          type: string
          description: X username, without the leading @
        name:
          type: string
          description: Display name
        link:
          type: string
          description: URL of the profile on X
        avatar:
          type: string
          description: URL of the profile picture
        is_verified:
          type: boolean
          description: Whether the account shows a verified checkmark
        verified_type:
          type: string
          description: Verification category of the checkmark, such as Business or Government

    Media:
      type: object
      required: [type, width, height]
      properties:
        type:
          type: string
          enum: ["image", "video", "gif"]
          description: Kind of media
        link:
          type: string
          description: URL of the image, or of the highest-quality MP4 for a video or GIF
        thumbnail:
          type: string
          description: URL of the preview image of a video or GIF
        width:
          type: integer
          description: Width of the original media in pixels
        height:
          type: integer
          description: Height of the original media in pixels
        alt_text:
          type: string
          description: Image description the author added
        duration:
          type: number
          description: Length of the video in seconds

    ContentLink:
      type: object
      required: [text, link]
      properties:
        text:
          type: string
          description: Link text as shown in the post
        link:
          type: string
          description: Full URL of the link

    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
