openapi: 3.0.0
info:
  title: TikTok Music API
  description: |
    The TikTok Music API returns the details of a TikTok sound: its title, author, album, cover, duration, audio
    URL, whether it is an original sound and how many videos use it, together with the TikTok account behind it.

    **Cross-linking**: Every video's `music.id` in the TikTok APIs is a `music_id` for this API. Pass the same
    `music_id` to the TikTok Music Videos API for the videos that use the sound, and the author's `username` to
    the TikTok Profile API.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Music
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["tiktok_music"]
            default: "tiktok_music"
        - 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 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 is provided
          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'
        music:
          $ref: '#/components/schemas/Music'
        author:
          $ref: '#/components/schemas/Author'
        error:
          type: string
          description: Error message when the sound was not found
    Music:
      type: object
      description: The sound
      required: [id, title, link]
      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
        videos_count:
          type: integer
          description: Number of TikTok videos that use the sound
    Author:
      type: object
      description: The TikTok account behind the sound, the creator of an original sound or the artist's account of a licensed track
      required: [id, username, link]
      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
    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
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong

