openapi: 3.0.0
info:
  title: TikTok Music Videos API
  description: |
    The TikTok Music Videos API returns the videos that use a TikTok sound, in the order its sound page lists
    them, about 30 per page.

    **Pagination**: When `pagination.has_more` is true, pass `pagination.next_page_token` as the
    `next_page_token` parameter to get the next page. The token alone is enough; `url` and `music_id` can be omitted.

    **Cross-linking**: Every video's `music.id` in the TikTok APIs is a `music_id` for this API. Pass a video's
    `link` to the TikTok Video or TikTok Comments API and its author's `username` to the TikTok Profile API.
    The TikTok Music API returns the sound's own details.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Music Videos
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["tiktok_music_videos"]
            default: "tiktok_music_videos"
        - name: url
          in: query
          required: false
          description: TikTok sound page URL (e.g., "https://www.tiktok.com/music/MILLION-DOLLAR-BABY-VHS-7362317730454308880"). Required unless music_id or next_page_token is provided; do not combine with music_id
          schema:
            type: string
        - name: music_id
          in: query
          required: false
          description: Numeric TikTok sound ID, the number at the end of the sound page URL and the music.id of every TikTok video (e.g., "7362317730454308880"). Required unless url or next_page_token is provided
          schema:
            type: string
        - name: next_page_token
          in: query
          required: false
          description: Token for the next page of videos, taken from pagination.next_page_token of the previous response. The token is issued for one sound, so url and music_id can be omitted, and a different sound is rejected
          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, or TikTok answered but returned nothing usable. The body is a bare
            {"error": ...} rather than a search response, and the search is not billed.
            A sound that does not exist is not this case: it is a 200 with the error "TikTok Music not found.".
          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'
        videos:
          type: array
          description: Videos that use the sound, in the order its sound page lists them
          items:
            $ref: '#/components/schemas/Video'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Error message describing why no videos were returned
    Video:
      type: object
      required: [position, id, link, type, iso_date, views, likes, comments, shares, saves, author]
      properties:
        position:
          type: integer
          description: 1-based position of the video on the page
        id:
          type: string
          description: TikTok video ID
        link:
          type: string
          description: URL of the video on TikTok
        type:
          type: string
          enum: [video, photo, carousel]
          description: Post type, where photo is a single-image post and carousel a multi-image post
        title:
          type: string
          description: Title of a photo post, separate from its caption
        caption:
          type: string
          description: Caption of the video
        language:
          type: string
          description: Language code of the caption (e.g., en, es)
        hashtags:
          type: array
          description: Hashtags in the caption, without the leading "#"
          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_ad:
          type: boolean
          description: Whether the video is a promoted post
        is_pinned:
          type: boolean
          description: Whether the video is pinned to its author's profile
        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
        likes:
          type: integer
          description: Number of likes
        comments:
          type: integer
          description: Number of comments
        shares:
          type: integer
          description: Number of shares
        saves:
          type: integer
          description: Number of saves
        thumbnail:
          type: string
          description: Cover image URL, signed by TikTok and valid for about 48 hours
        dynamic_thumbnail:
          type: string
          description: Animated cover image URL, signed by TikTok and valid for about 48 hours
        carousel_items:
          type: array
          description: Slides of a photo post
          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: Closed captions available for the video
          items:
            $ref: '#/components/schemas/Subtitle'
        author:
          $ref: '#/components/schemas/Author'
    Author:
      type: object
      description: The creator who posted the video
      required: [id, username, link, name]
      properties:
        id:
          type: string
          description: TikTok numeric user ID
        sec_uid:
          type: string
          description: TikTok secure user ID
        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
        avatar:
          type: string
          description: URL of the 720x720 avatar image, signed by TikTok and valid for about 48 hours
        avatar_hd:
          type: string
          description: URL of the 1080x1080 avatar image, signed by TikTok and valid for about 48 hours
        is_verified:
          type: boolean
          description: Whether the creator is verified
        is_private:
          type: boolean
          description: Whether the account is private
        is_seller:
          type: boolean
          description: Whether the account is a TikTok Shop seller
        followers:
          type: integer
          description: Number of followers
        following:
          type: integer
          description: Number of accounts the creator follows
        hearts:
          type: integer
          description: Total likes received across all posts
        posts:
          type: integer
          description: Total number of posts
        liked_videos:
          type: integer
          description: Number of videos the account has liked
    Location:
      type: object
      description: Place tagged on the video
      properties:
        id:
          type: string
          description: TikTok place ID
        name:
          type: string
          description: Place name
        address:
          type: string
          description: Street address
        city:
          type: string
          description: City
        category:
          type: string
          description: Place category (e.g., Food and Drink)
    Music:
      type: object
      description: The sound the video uses
      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 and valid for about 48 hours
        duration:
          type: integer
          description: Sound duration in seconds
        play_url:
          type: string
          description: Audio stream URL, signed by TikTok and valid for a limited time
        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 of the sound's TikTok page
    VideoMeta:
      type: object
      description: Quality and encoding of the video
      properties:
        definition:
          type: string
          description: Playback definition label (e.g., 720p)
        ratio:
          type: string
          description: 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: Size in bytes of the default rendition
        bitrate:
          type: integer
          description: Bitrate in bits per second of the default rendition
        bitrates:
          type: array
          description: Encoding variants of the video
          items:
            $ref: '#/components/schemas/Bitrate'
    Bitrate:
      type: object
      properties:
        gear_name:
          type: string
          description: TikTok's name for the rendition
        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 and valid for a limited time
        url_expires_at:
          type: string
          format: date-time
          description: UTC time when the caption 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
    Pagination:
      type: object
      properties:
        has_more:
          type: boolean
          description: Whether another page of videos is available
        next_page_token:
          type: string
          description: Token to pass as next_page_token for the next page
    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: The sound page URL sent with the request
        music_id:
          type: string
          description: The sound ID requested
        next_page_token:
          type: string
          description: The page token sent with the request
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong

