openapi: "3.0.1"
info:
  title: "Rasa Platform - Model CI/CD"
  version: "1.0.0"
  description: >-
    Rasa Platform model CI/CD endpoints
servers:
- url: http://demo-bot.rasa.com/api
  description: Demo
paths:
  /projects/{project_id}/models:
    get:
      tags:
      - Models
      summary: Get a list of Core and NLU models
      operationId: getModels
      description: >-
        Returns a list of metadata on Rasa models.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/offset'
      - $ref: '#/components/parameters/limit'
      responses:
        200:
          description: Model list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Model'
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/models/nlu:
    get:
      tags:
      - Models
      summary: Get NLU models
      operationId: getModels
      description: >-
        Returns a list of metadata on Rasa NLU models.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/offset'
      - $ref: '#/components/parameters/limit'
      responses:
        200:
          description: Model list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Model'
        401:
          $ref: '#/components/responses/UnauthorizedError'
    post:
      tags:
      - Models
      summary: Upload a zipped Rasa NLU model
      parameters:
      - $ref: '#/components/parameters/projectId'
      - in: formData
        name: upfile
        schema:
          type: file
        description: The file to upload.
      responses:
        204:
          description: Upload OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No model found
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/jobs:
    post:
      tags:
      - Jobs, Model
      summary: Train a model
      operationId: trainModel
      parameters:
      - $ref: '#/components/parameters/projectId'
      responses:
        200:
          description: Confirmation of model training
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/tags/{tag}:
    get:
      tags:
      - model
      summary: Get a Rasa NLU model with tag
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/tag'
      responses:
        200:
          description: Zipped Rasa NLU model
          content:
            application/octet-stream:
              schema:
                type: string
        404:
          description: No model found for tag
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/{model}:
    get:
      tags:
      - model
      summary: Get a Rasa NLU model by name
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        200:
          description: Zipped Rasa NLU model
          content:
            application/octet-stream:
              schema:
                type: string
        404:
          description: No model found for tag
        401:
          $ref: '#/components/responses/UnauthorizedError'
    delete:
      tags:
      - model
      summary: Delete a Rasa NLU model
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        204:
          description: Delete OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: Model could not be deleted
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/{model}/tags/{tag}:
    put:
      tags:
      - model
      summary: Tag a Rasa NLU model
      description: >-
        This endpoint can be used to assign a tag to a Rasa NLU model. The tag
        will be removed from any other NLU model that might have it. The
        endpoint returns the assigned tag with status code 200.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      - $ref: '#/components/parameters/tag'
      responses:
        200:
          description: Tag created on model
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No tag found
        401:
          $ref: '#/components/responses/UnauthorizedError'
    delete:
      tags:
      - model
      summary: Delete a tag of a Rasa NLU model
      description: >-
        Rasa NLU model tags can be deleted at this endpoint.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      - $ref: '#/components/parameters/tag'
      responses:
        204:
          description: Deleted OK
          content:
            text/plain:
              schema:
                type: string
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/core:
    get:
      tags:
      - model
      summary: Fetch list of Rasa Core models
      description: >-
        Returns a list of metadata on Rasa Core models.
      parameters:
      - $ref: '#/components/parameters/projectId'
      responses:
        200:
          description: Model list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Model'
    post:
      tags:
      - model
      summary: Upload a zipped Rasa Core model
      parameters:
      - $ref: '#/components/parameters/projectId'
      - in: formData
        name: upfile
        schema:
          type: file
        description: The file to upload.
      responses:
        204:
          description: Upload OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No model found

  /projects/{project_id}/models/core/tags/{tag}:
    get:
      tags:
      - model
      summary: Get a Rasa Core model with tag
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/tag'
      responses:
        200:
          description: Zipped Rasa Core model
          content:
            application/octet-stream:
              schema:
                type: string
        404:
          description: No model found for tag

  /projects/{project_id}/models/core/{model}:
    get:
      tags:
      - model
      summary: Get a Rasa Core model by name
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        200:
          description: Zipped Rasa Core model
          content:
            application/octet-stream:
              schema:
                type: string
        404:
          description: No model found for tag
        401:
          $ref: '#/components/responses/UnauthorizedError'
    delete:
      tags:
      - model
      summary: Delete a Rasa Core model
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        204:
          description: Delete OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: Model could not be deleted

  /projects/{project_id}/models/core/{model}/tags/{tag}:
    put:
      tags:
      - model
      summary: Tag a Rasa Core model
      description: >-
        This endpoint can be used to assign a tag to a Rasa Core model. The tag
        will be removed from any other Core model that might have it. The
        endpoint returns the assigned tag with status code 200.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      - $ref: '#/components/parameters/tag'
      responses:
        200:
          description: Tag created on model
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No tag found
    delete:
      tags:
      - model
      summary: Delete a tag of a Rasa Core model
      description: >-
        Rasa Core model tags can be deleted at this endpoint.
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      - $ref: '#/components/parameters/tag'
      responses:
        204:
          description: Delete OK
          content:
            text/plain:
              schema:
                type: string

  /projects/{project_id}/evaluations:
    get:
      tags:
      - Evaluations
      summary: Get model evaluations
      operationId: getEvaluations
      parameters:
      - $ref: '#/components/parameters/projectId'
      responses:
        200:
          description: Model evaluations
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    project_id:
                      type: string
                    model:
                      type: string
                    intent_evaluation:
                      type: object
                      $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/evaluations/{model}:
    put:
      tags:
      - Evaluations
      summary: Start a model evaluation
      operationId: startEvaluation
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        200:
          description: Model evaluation
          content:
            application/json:
              schema:
                type: object
                properties:
                  intent_evaluation:
                    type: object
                    $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'
    get:
      tags:
      - Evaluations
      summary: Retrieve a model evaluation
      operationId: getEvaluation
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        200:
          description: Model evaluation
          content:
            application/json:
              schema:
                type: object
                properties:
                  intent_evaluation:
                    type: object
                    $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'
        404:
          description: Evaluation result could not be found
    delete:
      tags:
      - Evaluations
      summary: Delete a model evaluation
      operationId: deleteEvaluation
      parameters:
      - $ref: '#/components/parameters/projectId'
      - $ref: '#/components/parameters/model'
      responses:
        204:
          description: Deleted model evaluation
          content:
            text/plain:
              schema:
                type: string
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/settings:
    get:
      tags:
      - Settings
      summary: Fetch NLU config
      operationId: getConfig
      parameters:
      - $ref: '#/components/parameters/projectId'
      responses:
        200:
          description: Configuration of NLU
          content:
            application/json:
              schema:
                type: object
                properties:
                  nlu_config:
                    description: YAML string
                    type: string
        400:
          description: could not find settings
        401:
          $ref: '#/components/responses/UnauthorizedError'
    put:
      tags:
      - Settings
      summary: Save NLU config
      operationId: saveConfig
      parameters:
      - $ref: '#/components/parameters/projectId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                nlu_config:
                  description: YAML string
                  type: string
      responses:
        200:
          description: Saved configuration of NLU
          content:
            application/json:
              schema:
                type: object
                properties:
                  nlu_config:
                    description: YAML string
                    type: string
        400:
          description: could not find settings
        401:
          $ref: '#/components/responses/UnauthorizedError'

security:
- bearerAuth: []
components:
  parameters:
    projectId:
      in: path
      name: project_id
      example: default
      description: project ID
      schema:
        type: string
      required: true
    model:
      in: path
      name: model
      description: model name
      schema:
        type: string
      required: true
    tag:
      in: path
      name: tag
      description: model tag
      schema:
        type: string
      required: true
    offset:
      in: query
      name: offset
      schema:
        default: 0
        type: number
    limit:
      in: query
      name: limit
      schema:
        default: null
        type: number
  responses:
    UnauthorizedError:
      description: Access token is missing or invalid
      content:
        application/json:
          schema:
            type: object
            properties:
              exception:
                type: string
              reasons:
                oneOf:
                - type: string
                - type: array
                  items:
                    type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Suggestion:
      type: object
      properties:
        user_input:
          type: object
          properties:
            text:
              type: string
            intent:
              type: object
              properties:
                name:
                  type: string
                confidence:
                  type: number
            entities:
              type: array
              items:
                type: object
        project_id:
          type: string
        model:
          type: string
        time:
          type: number
        team:
          type: string
    EvaluationResult:
      type: object
      properties:
        report:
          type: string
        f1_score:
          type: integer
        accuracy:
          type: integer
        predictions:
          type: array
          items:
            type: object
            properties:
              text:
                type: string
              confidence:
                type: integer
              intent:
                type: string
              predicted:
                type: string
        precision:
          type: integer
    Model:
      type: object
      properties:
        project:
          type: string
        model:
          type: string
        path:
          type: string
        hash:
          type: string
        tags:
          type: array
          items:
            type: string
        trained_at:
          type: number
        version:
          type: string
        type:
          type: string
