openapi: 3.0.0
info:
  title: YouTube Autocomplete API
  description: |
    The YouTube Autocomplete API returns the suggestions YouTube shows in its search box as you type a query. Suggestions are search terms, channels or topics.

    **Cross-linking**: A suggestion's `value` can be passed as the `q` parameter of the YouTube Search API, and a channel suggestion's `channel.id` as the `channel_id` parameter of the YouTube Channel API.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: YouTube Autocomplete
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine to use
          schema:
            type: string
            enum: ["youtube_autocomplete"]
        - name: q
          in: query
          required: true
          description: Search query to get YouTube search suggestions for. Emoji and some symbols count as more than one character.
          schema:
            type: string
            maxLength: 100
        - name: gl
          in: query
          required: false
          description: Country code for localized results (ISO 3166-1 alpha-2)
          schema:
            type: string
            enum: ["DZ", "AR", "AU", "AT", "AZ", "BH", "BD", "BY", "BE", "BO", "BA", "BR", "BG", "KH", "CA", "CL", "CO", "CR", "HR", "CY", "CZ", "DK", "DO", "EC", "EG", "SV", "EE", "FI", "FR", "GE", "DE", "GH", "GR", "GT", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IL", "IT", "JM", "JP", "JO", "KZ", "KE", "KW", "LA", "LV", "LB", "LY", "LI", "LT", "LU", "MY", "MT", "MX", "ME", "MA", "NP", "NL", "NZ", "NI", "NG", "MK", "NO", "OM", "PK", "PA", "PG", "PY", "PE", "PH", "PL", "PT", "PR", "QA", "RO", "RU", "SA", "SN", "RS", "SG", "SK", "SI", "ZA", "KR", "ES", "LK", "SE", "CH", "TW", "TZ", "TH", "TN", "TR", "UG", "UA", "AE", "GB", "US", "UY", "VE", "VN", "YE", "ZW"]
            default: "US"
        - name: hl
          in: query
          required: false
          description: Language code for the interface language
          schema:
            type: string
            enum: ["af", "az", "id", "ms", "bs", "ca", "cs", "da", "de", "et", "en-in", "en-gb", "en", "es", "es-419", "es-us", "eu", "fil", "fr", "fr-ca", "gl", "hr", "zu", "is", "it", "sw", "lv", "lt", "hu", "nl", "no", "uz", "pl", "pt-pt", "pt", "ro", "sq", "sk", "sl", "sr-latn", "fi", "sv", "vi", "tr", "be", "bg", "ky", "kk", "mk", "mn", "ru", "sr", "uk", "el", "hy", "iw", "ur", "ar", "fa", "ne", "mr", "hi", "as", "bn", "pa", "gu", "or", "ta", "te", "kn", "ml", "si", "th", "lo", "my", "ka", "am", "km", "zh-cn", "zh-tw", "zh-hk", "ja", "ko"]
            default: "en"
        - name: api_key
          in: query
          required: false
          description: Pass API key as query parameter
          schema:
            type: string
      responses:
        '200':
          description: Successful response. A query YouTube has no suggestions for returns an error.
          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, or YouTube rejected the query.
          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.
          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. 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 in the order YouTube shows them.
          items:
            $ref: '#/components/schemas/Suggestion'
        error:
          type: string
          description: Error message if no results were found.
    Suggestion:
      type: object
      required: [value, type]
      properties:
        value:
          type: string
          description: The suggested search term.
        type:
          type: string
          description: The kind of suggestion.
          enum: ["query", "channel", "entity"]
        channel:
          $ref: '#/components/schemas/Channel'
        title:
          type: string
          description: The name of the topic.
        subtitle:
          type: string
          description: A short description of the topic.
        thumbnail:
          type: string
          description: The topic's image URL.
        thumbnail_source:
          type: string
          description: The page the thumbnail is taken from.
        kgmid:
          type: string
          description: The Google Knowledge Graph id of the suggestion.
    Channel:
      type: object
      description: The suggested channel.
      required: [id, link]
      properties:
        id:
          type: string
          description: The YouTube channel id.
        title:
          type: string
          description: The channel name.
        handle:
          type: string
          description: The channel handle, starting with @.
        link:
          type: string
          description: The channel URL.
        thumbnail:
          type: string
          description: The channel avatar URL.
    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
          nullable: true
          description: "Always null for this engine"
        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
        q:
          type: string
        gl:
          type: string
        hl:
          type: string
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
