openapi: 3.0.0
info:
  title: TikTok Autocomplete API
  description: |
    The TikTok Autocomplete API turns a partial or full search query into the ranked list of suggestions
    TikTok's own search box offers for it, in the order TikTok shows them. Suggestions follow the language
    of the query itself, so a Japanese query returns Japanese suggestions and a Spanish query Spanish ones.
    Set country to get the suggestions TikTok shows in that market (by default, the United States), and
    language to rank them for a user whose TikTok app is set to that language (by default, English).

    **Cross-linking**: Each suggestion's `value` is a ready-made TikTok search query. Pass it as the `q`
    parameter of the TikTok Search API to retrieve the matching videos, photos and profiles.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Autocomplete
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["tiktok_autocomplete"]
            default: "tiktok_autocomplete"
        - name: q
          in: query
          required: true
          description: The partial or full search text to autocomplete.
          schema:
            type: string
            maxLength: 200
        - name: country
          in: query
          required: false
          description: Two-letter country code whose TikTok market the suggestions come from.
          schema:
            type: string
            default: "US"
            enum: ["US", "GB", "CA", "AU", "NZ", "IE", "DE", "FR", "ES", "IT", "PT", "NL", "BE", "AT", "CH", "SE", "NO", "DK", "FI", "PL", "CZ", "RO", "HU", "GR", "TR", "IL", "AE", "SA", "EG", "MA", "BR", "MX", "AR", "CO", "CL", "PE", "JP", "KR", "TW", "PH", "ID", "TH", "VN", "MY", "SG", "PK", "BD", "NG", "ZA", "KE", "UA", "KZ"]
        - name: language
          in: query
          required: false
          description: >-
            Code of the language the TikTok app is set to for the user the suggestions are ranked
            for. It changes which suggestions rank highest within the country.
          schema:
            type: string
            default: "en"
            enum: ["en", "sq", "ar", "az", "bn", "bg", "my", "ca", "ceb", "zh-cn", "zh-tw", "hr", "cs", "da", "nl", "et", "fil", "fi", "fr", "de", "el", "he", "hi", "hu", "is", "id", "ga", "it", "ja", "jv", "kk", "km", "ko", "lv", "lt", "ms", "nb", "pl", "pt", "ro", "ru", "sk", "sl", "es", "sw", "sv", "th", "tr", "uk", "ur", "uz", "vi"]
      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.
          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'
        suggestions:
          type: array
          description: >-
            The suggestions for the query in the order TikTok's search box shows them, empty when
            TikTok has none.
          items:
            $ref: '#/components/schemas/Suggestion'
    Suggestion:
      type: object
      required: [position, type, value]
      properties:
        position:
          type: integer
          description: 1-based position of the suggestion in the list
        type:
          type: string
          enum: ["query", "profile"]
          description: Whether the suggestion is a search phrase or a TikTok account
        value:
          type: string
          description: The suggested search text, usable as the q parameter of the TikTok Search API
        language:
          type: string
          description: Language code TikTok assigns to a query suggestion (e.g. en, ja, vi)
        score:
          type: number
          format: float
          description: TikTok's predicted click-through rate for the suggestion, between 0 and 1
        username:
          type: string
          description: TikTok username of a profile suggestion
        name:
          type: string
          description: Display name of a profile suggestion
        link:
          type: string
          description: URL of a profile suggestion's TikTok page
        is_verified:
          type: boolean
          description: Whether a profile suggestion is a verified account
    SearchMetadata:
      type: object
      required: [id, 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
        q:
          type: string
          description: Search text autocompleted
        country:
          type: string
          description: Country whose TikTok market the suggestions come from
        language:
          type: string
          description: Language of the TikTok app the suggestions are ranked for
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
