openapi: 3.0.0
info:
  title: YouTube Trending Shorts API
  description: |
    Get the shorts trending on YouTube's Shorts feed for a country, with views, likes, comments, publish date, duration and channel details when YouTube returns them. Use `next_page_token` to get the next batch.

    **Cross-linking**: Short IDs are YouTube video IDs and can be used with the YouTube Video API and the YouTube Comments API. Channel IDs can be used with the YouTube Channel API and the YouTube Channel Shorts API.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: YouTube Trending Shorts
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Parameter defines the engine that will be used to retrieve real-time data. It must be set to `youtube_trending_shorts`.
          schema:
            type: string
            enum: ["youtube_trending_shorts"]
        - name: gl
          in: query
          required: false
          description: Defines the country of the search.
          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: Defines the language of the feed. YouTube picks shorts in that language, e.g. `ja` with `gl=JP`.
          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: next_page_token
          in: query
          required: false
          description: Token from `pagination.next_page_token` of a previous response, used to fetch the next batch of shorts. Send it with the same `gl` and `hl` as that request.
          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 invalid values or a malformed `next_page_token`.
          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'
        shorts:
          type: array
          items:
            $ref: '#/components/schemas/Short'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Error message returned instead of shorts, such as when YouTube rejects the `next_page_token`
    Pagination:
      type: object
      properties:
        next_page_token:
          type: string
          description: Token to pass as `next_page_token` to fetch the next batch of shorts.
    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: YouTube 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: The search engine used
        gl:
          type: string
          description: Country code used for the search
        hl:
          type: string
          description: Language code used for the search
        next_page_token:
          type: string
          description: Pagination token used for this request
    Short:
      type: object
      required: [position, id, title, link, channel]
      properties:
        position:
          type: integer
          description: Position of the short in this batch
        id:
          type: string
          description: YouTube video ID of the short
        title:
          type: string
          description: Short title
        link:
          type: string
          description: Direct link to the short
        description:
          type: string
          description: Short description written by the creator
        views:
          type: integer
          description: Number of views
        likes:
          type: integer
          description: Number of likes
        comments:
          type: integer
          description: Number of comments
        publish_date:
          type: string
          format: date-time
          description: Publish date and time in ISO 8601 format
        length:
          type: string
          description: Duration formatted as minutes and seconds (e.g., "0:36")
        length_seconds:
          type: integer
          description: Duration in seconds
        category:
          type: string
          description: YouTube category of the short
        keywords:
          type: array
          items:
            type: string
          description: Tags set by the creator
        is_family_safe:
          type: boolean
          description: Whether YouTube marks the short as family safe
        channel:
          $ref: '#/components/schemas/Channel'
        music:
          $ref: '#/components/schemas/Music'
        thumbnail:
          type: string
          description: URL to the short cover image
    Music:
      type: object
      properties:
        title:
          type: string
          description: Title of the music used in the short
        thumbnail:
          type: string
          description: URL to the music cover image
    Channel:
      type: object
      required: [id, title, link]
      properties:
        id:
          type: string
          description: Unique channel identifier
        title:
          type: string
          description: Channel name
        handle:
          type: string
          description: Channel handle (e.g., "@MrBeast")
        link:
          type: string
          description: Link to the channel
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
