> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nx1cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a deployment for a model

> Creates a new deployment for the specified registered model.

If the request body includes a ``model_name``, the API ignores it and uses the ``model`` path parameter instead.



## OpenAPI

````yaml post /api/models/{model}/deployments
openapi: 3.1.0
info:
  title: Nx1 AI API
  description: |

    AI API for Nx1 Data Platform Management and Automated Data Tasks.

    Authentication is required via PSK in Authorization header.

    Default PSK is | [ask a friend] |
  version: 0.10.2
servers: []
security: []
paths:
  /api/models/{model}/deployments:
    post:
      tags:
        - Deployments
      summary: Create a deployment for a model
      description: >-
        Creates a new deployment for the specified registered model.


        If the request body includes a ``model_name``, the API ignores it and
        uses the ``model`` path parameter instead.
      operationId: create_deployment_api_models__model__deployments_post
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            description: MLflow registered model name.
            title: Model
          description: MLflow registered model name.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/BatchDeploymentRequest'
                - $ref: '#/components/schemas/OnlineDeploymentRequest'
              discriminator:
                propertyName: type
                mapping:
                  batch:
                    $ref: '#/components/schemas/BatchDeploymentRequest'
                  online:
                    $ref: '#/components/schemas/OnlineDeploymentRequest'
              title: Request
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeploymentResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    BatchDeploymentRequest:
      properties:
        type:
          type: string
          const: batch
          title: Type
          default: batch
        name:
          type: string
          title: Name
          description: >-
            Deployment name. Use lowercase letters, digits, and hyphens only.
            Must start and end with an alphanumeric character, with a maximum of
            63 characters. Unique per registered model.
        model:
          $ref: '#/components/schemas/ModelReference'
        source:
          $ref: '#/components/schemas/SourceTable'
        target:
          $ref: '#/components/schemas/TargetTable'
        entity_columns:
          items:
            type: string
          type: array
          minItems: 1
          title: Entity Columns
          description: Columns from the source carried forward into the predictions table.
        schedule:
          anyOf:
            - type: string
            - type: 'null'
          title: Schedule
          description: Cron expression. None = manual-trigger only.
        rerun_behavior:
          $ref: '#/components/schemas/RerunBehavior'
          default: overwrite_partition
        partition_column:
          type: string
          title: Partition Column
          description: Partition column for overwrite_partition mode.
          default: scored_at
        domain:
          type: string
          title: Domain
        owner:
          type: string
          title: Owner
        trigger_now:
          type: boolean
          title: Trigger Now
          default: false
        allowed_roles:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Roles
          description: >-
            Keycloak roles that can invoke or manage this deployment via a user
            PSK. An empty or unset list restricts access to the platform PSK
            only.
      type: object
      required:
        - name
        - model
        - source
        - target
        - entity_columns
        - domain
        - owner
      title: BatchDeploymentRequest
    OnlineDeploymentRequest:
      properties:
        type:
          type: string
          const: online
          title: Type
          default: online
        name:
          type: string
          title: Name
          description: >-
            Deployment name. Use lowercase letters, digits, and hyphens only.
            Must start and end with an alphanumeric character, with a maximum of
            63 characters. Also used as the Kubernetes Service name with a
            ``serve-`` prefix. Unique per registered model.
        model:
          $ref: '#/components/schemas/ModelReference'
        min_replicas:
          type: integer
          minimum: 1
          title: Min Replicas
          default: 2
        max_replicas:
          type: integer
          minimum: 1
          title: Max Replicas
          default: 10
        target_cpu_utilization:
          type: integer
          maximum: 100
          minimum: 1
          title: Target Cpu Utilization
          default: 70
        cpu_request:
          anyOf:
            - type: string
            - type: 'null'
          title: Cpu Request
        memory_request:
          anyOf:
            - type: string
            - type: 'null'
          title: Memory Request
        cpu_limit:
          anyOf:
            - type: string
            - type: 'null'
          title: Cpu Limit
        memory_limit:
          anyOf:
            - type: string
            - type: 'null'
          title: Memory Limit
        driver_memory:
          anyOf:
            - type: string
            - type: 'null'
          title: Driver Memory
          description: >-
            Spark driver heap size. Maps to the Spark ``--driver-memory`` flag.
            Auto-sized when unset.
        domain:
          type: string
          title: Domain
        owner:
          type: string
          title: Owner
        allowed_roles:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Roles
          description: >-
            Keycloak roles that can invoke this deployment via the proxy using a
            user PSK. An empty or unset list restricts access to the platform
            PSK only.
      type: object
      required:
        - name
        - model
        - domain
        - owner
      title: OnlineDeploymentRequest
    DeploymentResponse:
      properties:
        deployment_id:
          type: string
          format: uuid
          title: Deployment Id
        name:
          type: string
          title: Name
        type:
          $ref: '#/components/schemas/DeploymentType'
        status:
          $ref: '#/components/schemas/DeploymentStatus'
        domain:
          type: string
          title: Domain
        owner:
          type: string
          title: Owner
        model:
          $ref: '#/components/schemas/ModelReference'
        resolved_model_version:
          anyOf:
            - type: string
            - type: 'null'
          title: Resolved Model Version
          description: >-
            The model version this deployment currently uses. When the
            deployment references an alias, this shows the resolved version
            number.
        dag_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Dag Id
        dag_s3_uri:
          anyOf:
            - type: string
            - type: 'null'
          title: Dag S3 Uri
        schedule:
          anyOf:
            - type: string
            - type: 'null'
          title: Schedule
        last_run:
          anyOf:
            - $ref: '#/components/schemas/DeploymentRunSummary'
            - type: 'null'
        service_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Service Url
        replica_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Replica Count
        ready_replicas:
          anyOf:
            - type: integer
            - type: 'null'
          title: Ready Replicas
        allowed_roles:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Roles
        error_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Message
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        stopped_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Stopped At
      type: object
      required:
        - deployment_id
        - name
        - type
        - status
        - domain
        - owner
        - model
        - created_at
        - updated_at
      title: DeploymentResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ModelReference:
      properties:
        model_name:
          type: string
          title: Model Name
          description: MLflow registered model name.
        model_version:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Version
          description: >-
            The exact model version to deploy. For example, `3`. Mutually
            exclusive with `model_alias`.
        model_alias:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Alias
          description: >-
            The alias to resolve to a version at deployment time. For example,
            `production`. Mutually exclusive with `model_version`.
      type: object
      required:
        - model_name
      title: ModelReference
      description: |-
        A registered MLflow model with either a version number or an alias.

        Provide exactly one of ``model_version`` or ``model_alias``. A version
        number deploys a specific model release. An alias resolves to a
        concrete version at deployment creation time.
    SourceTable:
      properties:
        catalog:
          type: string
          title: Catalog
          default: iceberg
        schema:
          type: string
          title: Schema
        table:
          type: string
          title: Table
        filter_sql:
          anyOf:
            - type: string
              maxLength: 2000
            - type: 'null'
          title: Filter Sql
          description: >-
            SQL filter condition to apply to the source table. For example,
            ``date > '2024-01-01'``.
        snapshot_id:
          anyOf:
            - type: integer
            - type: 'null'
          title: Snapshot Id
          description: Optional Iceberg snapshot id for time-travel reads.
      type: object
      required:
        - schema
        - table
      title: SourceTable
      description: Iceberg table the batch scorer reads from.
    TargetTable:
      properties:
        catalog:
          type: string
          title: Catalog
          default: iceberg
        schema:
          type: string
          title: Schema
        table:
          type: string
          title: Table
      type: object
      required:
        - schema
        - table
      title: TargetTable
      description: Iceberg table the batch scorer writes predictions to.
    RerunBehavior:
      type: string
      enum:
        - overwrite_partition
        - append_dedup
      title: RerunBehavior
    DeploymentType:
      type: string
      enum:
        - batch
        - online
      title: DeploymentType
    DeploymentStatus:
      type: string
      enum:
        - pending
        - deploying
        - active
        - failed
        - stopped
        - archived
      title: DeploymentStatus
    DeploymentRunSummary:
      properties:
        run_id:
          type: string
          format: uuid
          title: Run Id
        airflow_run_id:
          type: string
          title: Airflow Run Id
        status:
          $ref: '#/components/schemas/DeploymentRunStatus'
        rows_scored:
          anyOf:
            - type: integer
            - type: 'null'
          title: Rows Scored
        started_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Started At
        finished_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Finished At
      type: object
      required:
        - run_id
        - airflow_run_id
        - status
      title: DeploymentRunSummary
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    DeploymentRunStatus:
      type: string
      enum:
        - queued
        - running
        - succeeded
        - failed
      title: DeploymentRunStatus
  securitySchemes:
    OAuth2AuthorizationCodeBearer:
      type: oauth2
      flows:
        authorizationCode:
          scopes: {}
          authorizationUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/auth
          tokenUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/token
    APIKeyHeader:
      type: apiKey
      in: header
      name: Authorization-PSK

````