openapi: 3.0.0
info:
  title: TikTok Collection API
  description: |
    Retrieve the videos saved in a public TikTok collection, up to 15 per page, together with the
    collection's name, cover, video count and owner. Each video includes its author, caption,
    publish time, duration, thumbnail, engagement counts, the sound it uses, and the hashtags
    and mentions parsed from the caption. Page through the whole collection with next_page_token
    until pagination.has_more is no longer returned.

    **Cross-linking**: pass a video's `id` and `author.username` to the TikTok Video API for its
    full detail, or the `author.username` and `owner.username` to the TikTok Profile API.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Collection Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["tiktok_collection"]
            default: "tiktok_collection"
        - name: collection_id
          in: query
          required: false
          description: Numeric TikTok collection ID, the trailing number of a collection page link. Required unless url or next_page_token is given.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,18}$'
        - name: url
          in: query
          required: false
          description: TikTok collection page link (https://www.tiktok.com/@username/collection/name-1234567890123456789), used instead of collection_id.
          schema:
            type: string
        - name: next_page_token
          in: query
          required: false
          description: Token to retrieve the next page of videos, returned as pagination.next_page_token when pagination.has_more is true. The collection is recovered from the token when collection_id and url are omitted.
          schema:
            type: string
      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'
        collection:
          $ref: '#/components/schemas/Collection'
        videos:
          type: array
          items:
            $ref: '#/components/schemas/Video'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Error message when the collection has no videos, does not exist or does not show its videos

    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: TikTok 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
        url:
          type: string
          description: TikTok collection page link used for this request
        collection_id:
          type: string
          description: TikTok collection ID used for this request
        next_page_token:
          type: string
          description: Pagination token used for this request

    Collection:
      type: object
      required: [id]
      properties:
        id:
          type: string
          description: TikTok collection ID
        name:
          type: string
          description: Collection name
        link:
          type: string
          description: URL of the collection page
        cover:
          type: string
          description: Collection cover image URL (signed by TikTok, expires after ~48 hours)
        videos_count:
          type: integer
          description: Number of videos TikTok counts in the collection
        owner:
          $ref: '#/components/schemas/Owner'

    Owner:
      type: object
      description: The creator who shared the collection
      properties:
        id:
          type: string
          description: TikTok numeric user ID
        username:
          type: string
          description: TikTok username
        link:
          type: string
          description: URL of the owner's profile

    Video:
      type: object
      required: [position, id, link, type, author]
      properties:
        position:
          type: integer
          description: 1-based position of the video in the returned page
        id:
          type: string
          description: TikTok video ID
        link:
          type: string
          description: Canonical URL to the video (or /photo/ for image posts)
        type:
          type: string
          enum: ["video", "photo", "carousel"]
          description: Post type. A photo is a single-image post and a carousel a multi-image post, both with /photo/ links
        title:
          type: string
          description: Photo post title, separate from the caption
        caption:
          type: string
          description: Video caption
        language:
          type: string
          description: Caption language code (e.g. en, es)
        hashtags:
          type: array
          description: Hashtags parsed from the caption
          items:
            type: string
        mentions:
          type: array
          description: Usernames mentioned in the caption
          items:
            type: string
        iso_date:
          type: string
          format: date-time
          description: Publish time in ISO 8601 format
        duration:
          type: integer
          description: Video duration in seconds
        width:
          type: integer
          description: Video width in pixels
        height:
          type: integer
          description: Video height in pixels
        is_pinned:
          type: boolean
          description: Whether the video is pinned to the top of its author's profile
        is_ad:
          type: boolean
          description: Whether the video is a sponsored or promoted post
        is_duet_enabled:
          type: boolean
          description: Whether duets are allowed on the video
        is_stitch_enabled:
          type: boolean
          description: Whether stitches are allowed on the video
        views:
          type: integer
          description: Number of views (plays)
        likes:
          type: integer
          description: Number of likes (diggs)
        comments:
          type: integer
          description: Number of comments
        shares:
          type: integer
          description: Number of shares
        saves:
          type: integer
          description: Number of saves (collects)
        thumbnail:
          type: string
          description: Cover image URL (signed by TikTok, expires after ~48 hours)
        dynamic_thumbnail:
          type: string
          description: Animated cover image URL (signed by TikTok, expires after ~48 hours)
        carousel_items:
          type: array
          description: Carousel slides
          items:
            $ref: '#/components/schemas/CarouselItem'
        video_meta:
          $ref: '#/components/schemas/VideoMeta'
        music:
          $ref: '#/components/schemas/Music'
        location:
          $ref: '#/components/schemas/Location'
        subtitles:
          type: array
          description: Available closed captions
          items:
            $ref: '#/components/schemas/Subtitle'
        author:
          $ref: '#/components/schemas/Author'

    Author:
      type: object
      description: The creator who posted the video or photo
      properties:
        id:
          type: string
          description: TikTok numeric user ID
        sec_uid:
          type: string
          description: TikTok secure user ID (secUid)
        username:
          type: string
          description: TikTok username
        link:
          type: string
          description: URL of the creator's profile
        name:
          type: string
          description: Display name
        bio:
          type: string
          description: Profile bio or description
        avatar:
          type: string
          description: URL to the author's avatar image (signed by TikTok, expires after ~48 hours)
        avatar_hd:
          type: string
          description: URL to the author's 1080x1080 avatar image (signed by TikTok, expires after ~48 hours)
        is_verified:
          type: boolean
          description: Whether the author is verified
        is_private:
          type: boolean
          description: Whether the author's account is private
        followers:
          type: integer
          description: Author's follower count
        following:
          type: integer
          description: Number of accounts the author follows
        hearts:
          type: integer
          description: Total hearts (likes) received across all posts
        posts:
          type: integer
          description: Total number of posts
        liked_videos:
          type: integer
          description: Number of videos the author has liked

    VideoMeta:
      type: object
      description: Video quality and encoding metadata
      properties:
        definition:
          type: string
          description: Playback definition label (e.g. 540p, 720p)
        ratio:
          type: string
          description: Aspect/quality ratio label
        format:
          type: string
          description: Container format (e.g. mp4)
        codec_type:
          type: string
          description: Video codec (e.g. h264)
        size:
          type: integer
          description: Encoded size in bytes of the default rendition
        bitrate:
          type: integer
          description: Bitrate in bits per second of the default rendition
        bitrates:
          type: array
          description: Per-codec encoding variants
          items:
            $ref: '#/components/schemas/Bitrate'

    Bitrate:
      type: object
      properties:
        gear_name:
          type: string
          description: TikTok internal rendition name
        bitrate:
          type: integer
          description: Bitrate in bits per second
        fps:
          type: integer
          description: Frames per second
        codec_type:
          type: string
          description: Video codec (e.g. h264, h265_hvc1)
        format:
          type: string
          description: Container format (e.g. mp4)

    Subtitle:
      type: object
      properties:
        language:
          type: string
          description: Caption language code (e.g. eng-US)
        format:
          type: string
          description: Caption file format (e.g. webvtt)
        source:
          type: string
          description: How the caption was produced (e.g. ASR for auto-generated)
        url:
          type: string
          description: Caption file URL (signed by TikTok, expires)
        url_expires_at:
          type: string
          format: date-time
          description: UTC ISO 8601 timestamp when the subtitle url expires

    CarouselItem:
      type: object
      properties:
        position:
          type: integer
          description: 1-based slide position
        image:
          type: string
          description: Full-resolution slide image URL
        width:
          type: integer
          description: Slide image width in pixels
        height:
          type: integer
          description: Slide image height in pixels

    Location:
      type: object
      description: Venue tagged on the post
      properties:
        id:
          type: string
          description: TikTok place ID
        name:
          type: string
          description: Venue name
        address:
          type: string
          description: Street address
        city:
          type: string
          description: City
        category:
          type: string
          description: Venue category (e.g. Food and Drink)

    Music:
      type: object
      properties:
        id:
          type: string
          description: TikTok sound ID
        title:
          type: string
          description: Sound title
        album:
          type: string
          description: Album the sound belongs to
        author:
          type: string
          description: Sound author name
        cover:
          type: string
          description: Sound cover art URL (signed by TikTok, expires after ~48 hours)
        duration:
          type: integer
          description: Sound duration in seconds
        play_url:
          type: string
          description: Direct audio stream URL (signed by TikTok, expires)
        is_original:
          type: boolean
          description: Whether the sound is an original creation
        is_copyrighted:
          type: boolean
          description: Whether the sound is copyrighted
        link:
          type: string
          description: URL to the sound's TikTok page

    Pagination:
      type: object
      properties:
        has_more:
          type: boolean
          description: Whether more videos are available on a following page
        next_page_token:
          type: string
          description: Token to pass back as next_page_token to retrieve the next page of videos

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