openapi: 3.0.0
info:
  title: Niconico Video API
  description: |
    Get a Niconico video's public details from its id, its numeric thread id or a watch link. The answer carries the title, description, length, upload time, view, comment, mylist and like counts, tags, genre, thumbnail, payment flags, the Japan-only restriction, and the uploading user or channel. A video that is missing, deleted, private or unavailable outside Japan is answered with an error message.

    **Cross-linking**: `video.id` and `video.link` are what `video_id` takes, so a stored link or id can be checked again later.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Niconico Video Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine identifier
          schema:
            type: string
            enum: ["niconico_video"]
            default: "niconico_video"
        - name: video_id
          in: query
          required: true
          description: Niconico video id with its sm, so, nm, nl or ss prefix, a 10-digit thread id, or a nicovideo.jp watch or shorts link or nico.ms short link.
          schema:
            type: string
            maxLength: 2048
        - name: zero_retention
          in: query
          required: false
          description: Set to true to disable logging and persistent storage for this request. Enterprise plans only.
          schema:
            type: boolean
            default: false
      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'
        '403':
          description: Forbidden. Zero data retention is not available to the account, or the account requires `zero_retention=true`.
          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
      required: [search_metadata, search_parameters]
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        video:
          $ref: '#/components/schemas/Video'
        channel:
          $ref: '#/components/schemas/Channel'
        error:
          type: string
          description: Error message for a video Niconico does not show, such as a missing, deleted, private or Japan-only one.

    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: Niconico watch page 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
        video_id:
          type: string
          description: Niconico video id or thread id taken from the video_id parameter
        zero_retention:
          type: boolean
          description: Whether zero data retention was requested

    Video:
      type: object
      required: [id, link, title, length_seconds, iso_date, views, comments, mylists, likes, thumbnail, billing_type, watchable_by]
      properties:
        id:
          type: string
          description: Niconico video id, such as sm9.
        link:
          type: string
          description: URL of the video's watch page.
        title:
          type: string
          description: Title of the video.
        description:
          type: string
          description: Description of the video as plain text with line breaks.
        length_seconds:
          type: integer
          description: Length of the video in seconds.
        iso_date:
          type: string
          format: date-time
          description: Upload time in UTC.
        views:
          type: integer
          description: Number of views.
        comments:
          type: integer
          description: Number of comments.
        mylists:
          type: integer
          description: Number of times the video was added to a mylist.
        likes:
          type: integer
          description: Number of likes.
        thumbnail:
          type: string
          description: URL of the largest thumbnail.
        is_short:
          type: boolean
          description: Whether the video is a Niconico short.
        base_video_id:
          type: string
          description: Id of the full video a short was cut from.
        category:
          type: string
          description: Genre name in Japanese.
        category_id:
          type: string
          description: Niconico genre key, such as anime.
        tags:
          type: array
          description: Tags on the video.
          items:
            $ref: '#/components/schemas/Tag'
        billing_type:
          type: string
          description: How Niconico charges for the video, such as free, member_only or custom.
        watchable_by:
          type: string
          description: Who can watch the whole video, such as all, member or purchaser.
        is_pay_per_view:
          type: boolean
          description: Whether the video is sold on its own.
        is_members_only:
          type: boolean
          description: Whether the video is for channel members only.
        is_premium_only:
          type: boolean
          description: Whether the video is for Niconico Premium members only.
        is_login_required:
          type: boolean
          description: Whether watching the video needs a Niconico login.
        is_embeddable:
          type: boolean
          description: Whether Niconico allows playback in its embedded player.
        geo_restriction:
          $ref: '#/components/schemas/GeoRestriction'

    Tag:
      type: object
      required: [name]
      properties:
        name:
          type: string
          description: Tag text.
        is_locked:
          type: boolean
          description: Whether only the uploader can remove the tag.

    GeoRestriction:
      type: object
      required: [mode, countries]
      properties:
        mode:
          type: string
          enum: ["allow"]
          description: Whether the countries listed are the only ones allowed.
        countries:
          type: array
          description: Country codes the video is limited to.
          items:
            type: string

    Channel:
      type: object
      required: [type, id, name, link]
      properties:
        type:
          type: string
          enum: ["user", "channel"]
          description: Whether the uploader is a user or a Niconico channel.
        id:
          type: string
          description: Niconico user id, or channel id such as ch2632720.
        name:
          type: string
          description: Name of the user or channel.
        link:
          type: string
          description: URL of the user or channel page.
        thumbnail:
          type: string
          description: URL of the user's or channel's icon when available. Niconico's default user icon is omitted.
        is_official_anime:
          type: boolean
          description: Whether the channel is an official anime channel.

    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
