openapi: 3.0.0
info:
  title: TikTok Ads Library Advertiser Search API
  description: |
    The TikTok Ads Library Advertiser Search API provides suggestions for advertiser names and related keywords
    when searching the TikTok Ads Library. This API returns autocomplete-style results to help users discover
    advertisers and relevant ad keywords.

    **Key Features:**
    - Search for TikTok advertisers by name
    - Get advertiser suggestions with associated IDs
    - Discover related keyword suggestions
    - Lightweight autocomplete functionality for ad library exploration

    **Cross-linking**: The advertiser IDs returned by this API can potentially be used with other TikTok Ads 
    Library APIs to fetch detailed advertiser information or their associated advertisements.

  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: TikTok Ads Library Advertiser Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Must be set to `tiktok_ads_library_advertiser_search`
          schema:
            type: string
            enum: ["tiktok_ads_library_advertiser_search"]
        - name: q
          in: query
          required: true
          description: Search query for advertiser names
          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'
        advertisers:
          type: array
          description: Array of advertiser suggestions matching the search query
          items:
            $ref: '#/components/schemas/Advertiser'
        keyword_results:
          type: array
          description: Array of keyword suggestions related to the search query
          items:
            type: string
    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 Ads Library 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 used
        q:
          type: string
          description: Search query provided
    Advertiser:
      type: object
      required: [name, id]
      properties:
        name:
          type: string
          description: Name of the advertiser
        id:
          type: string
          description: Unique identifier for the advertiser
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong