openapi: 3.0.0
info:
  title: Kaggle Notebook API
  description: |
    Get one public Kaggle notebook by its ref or kaggle.com link: its title, author, language, type, votes, views, forks, comments, medal, tags, best public score, fork origin, collaborators and version count, its latest run (status, runtime, accelerator, internet setting), the files that run wrote, and the competitions, datasets, notebooks and models it reads.

    A notebook that does not exist, is private or was deleted returns an error saying Kaggle has no public notebook for that ref. Kaggle lists at most 500 output files for a run.

    **Cross-linking**: `notebook_id` is the `author/slug` ref Kaggle uses for a notebook, as in its kaggle.com/code link. A dataset source's `dataset_id` is the `owner/slug` ref of a Kaggle dataset, a notebook source's `notebook_id` can be passed back to this API, and a competition source's `competition_id` is Kaggle's numeric competition id.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Kaggle Notebook
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `kaggle_notebook`'
          schema:
            type: string
            enum: ["kaggle_notebook"]
        - name: notebook_id
          in: query
          required: true
          description: The notebook's ref, its author's username and the notebook's slug, such as `alexisbcook/titanic-tutorial`, or its kaggle.com/code link. The notebook's latest version is returned, and a renamed notebook under its new ref.
          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'
        notebook:
          $ref: '#/components/schemas/Notebook'
        run:
          $ref: '#/components/schemas/Run'
        outputs:
          type: array
          description: Files the latest run wrote, in Kaggle's order.
          items:
            $ref: '#/components/schemas/Output'
        data_sources:
          type: array
          description: Competitions, datasets, notebook outputs and models the notebook reads.
          items:
            $ref: '#/components/schemas/DataSource'
        error:
          type: string
          description: Message saying why no notebook was returned.
    Notebook:
      type: object
      required: [notebook_id, id, title, link, author, language, type, votes, views, forks, updated_at, version, versions_count]
      properties:
        notebook_id:
          type: string
          description: Kaggle's ref for the notebook, its author's username and the notebook's slug.
        id:
          type: integer
          description: Kaggle's numeric id for the notebook.
        title:
          type: string
          description: Title of the notebook.
        link:
          type: string
          description: Link to the notebook's page on Kaggle.
        author:
          $ref: '#/components/schemas/Author'
        collaborators:
          type: array
          description: Kaggle users the author shares the notebook with.
          items:
            $ref: '#/components/schemas/Author'
        language:
          type: string
          description: Language the notebook is written in, such as `python`, `r` or `rmarkdown`.
        type:
          type: string
          description: Whether the notebook is a `notebook` or a `script`.
        votes:
          type: integer
          description: Number of upvotes.
        views:
          type: integer
          description: Number of views.
        forks:
          type: integer
          description: Number of copies other users made of the notebook.
        comments:
          type: integer
          description: Number of comments on the notebook.
        medal:
          type: string
          description: Medal Kaggle awarded the notebook, `gold`, `silver` or `bronze`.
        tags:
          type: array
          description: Names of the tags the notebook carries.
          items:
            type: string
        best_public_score:
          type: number
          description: Best public leaderboard score of the notebook's competition submissions.
        is_fork:
          type: boolean
          description: Whether the notebook is a copy of another notebook.
        forked_from:
          $ref: '#/components/schemas/ForkedFrom'
        updated_at:
          type: string
          format: date-time
          description: Time of the notebook's last update, in UTC.
        version:
          type: integer
          description: Number of the notebook's current version.
        versions_count:
          type: integer
          description: Number of versions the notebook has.
    Author:
      type: object
      required: [username, name, link]
      properties:
        username:
          type: string
          description: Kaggle username.
        name:
          type: string
          description: Display name.
        link:
          type: string
          description: Link to the user's profile on Kaggle.
        tier:
          type: string
          description: The user's Kaggle progression tier, such as `expert`, `master` or `grandmaster`.
    ForkedFrom:
      type: object
      required: [notebook_id, id, title, link, author]
      properties:
        notebook_id:
          type: string
          description: Kaggle's ref for the public notebook this one was copied from.
        id:
          type: integer
          description: Kaggle's numeric id for that notebook.
        title:
          type: string
          description: Title of that notebook.
        link:
          type: string
          description: Link to that notebook's page on Kaggle.
        author:
          $ref: '#/components/schemas/Author'
    Run:
      type: object
      required: [status, created_at, accelerator, has_internet]
      properties:
        status:
          type: string
          description: State of the notebook's latest run.
          enum: ["queued", "running", "complete", "error", "cancel_requested", "cancelled", "new_script"]
        created_at:
          type: string
          format: date-time
          description: Time the run's version was saved and queued, in UTC.
        evaluated_at:
          type: string
          format: date-time
          description: Time the run started, in UTC.
        cancelled_at:
          type: string
          format: date-time
          description: Time the run was cancelled, in UTC.
        runtime_seconds:
          type: number
          description: How long the run took, in seconds.
        is_successful:
          type: boolean
          description: Whether the run finished without an error.
        exit_code:
          type: integer
          description: Exit code the run ended with.
        output_size_bytes:
          type: integer
          description: Total size of the files the run wrote, in bytes.
        accelerator:
          type: string
          description: Accelerator the run used as Kaggle names it, such as `nvidia_tesla_t4`, or `none`.
        has_internet:
          type: boolean
          description: Whether the run had internet access.
        is_quick_save:
          type: boolean
          description: Whether the version was a Quick Save, which keeps the outputs of the editor session instead of running the notebook again.
    Output:
      type: object
      required: [name, path, size_bytes]
      properties:
        name:
          type: string
          description: Name of the file.
        path:
          type: string
          description: Path of the file in the run's output folder.
        size_bytes:
          type: integer
          description: Size of the file in bytes.
        file_type:
          type: string
          description: Extension of the file, such as `.csv`.
    DataSource:
      type: object
      required: [type]
      properties:
        type:
          type: string
          description: Kind of source.
          enum: ["competition", "dataset", "notebook", "model"]
        name:
          type: string
          description: Name of the source.
        link:
          type: string
          description: Link to the source's page on Kaggle.
        competition_id:
          type: integer
          description: Kaggle's numeric id for a competition source.
        dataset_id:
          type: string
          description: Kaggle's ref for a dataset source, its owner's slug and the dataset's slug.
        notebook_id:
          type: string
          description: Kaggle's ref for a notebook whose output the notebook reads.
        model_id:
          type: string
          description: Kaggle's ref for a model source, its owner's slug and the model's slug.
        is_private:
          type: boolean
          description: Whether the source is private, so Kaggle shows only its kind.
    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: "Kaggle notebook page 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
        notebook_id:
          type: string
          description: Ref of the notebook looked up
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
