> ## 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.

# Update semantic model

> Update a semantic model.

If `approved_sql` is changed on an approved or deployed model, the model
is automatically reset to a `pending_review` status, and an audit entry is
created. The model must be re-approved before it can be deployed again.

**Required roles**: `nx1_semantic_modeller` or `nx1_semantic_admin`



## OpenAPI

````yaml patch /api/semantic-models/{model_id}
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/semantic-models/{model_id}:
    patch:
      tags:
        - Semantic models
      summary: Update semantic model
      description: >-
        Update a semantic model.


        If `approved_sql` is changed on an approved or deployed model, the model

        is automatically reset to a `pending_review` status, and an audit entry
        is

        created. The model must be re-approved before it can be deployed again.


        **Required roles**: `nx1_semantic_modeller` or `nx1_semantic_admin`
      operationId: update_semantic_model_api_semantic_models__model_id__patch
      parameters:
        - name: model_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Model Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SemanticModelUpdate'
      responses:
        '200':
          description: Model updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SemanticModelResponse'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not Found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    SemanticModelUpdate:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        approved_sql:
          anyOf:
            - type: string
            - type: 'null'
          title: Approved Sql
          description: Human-modified SQL.
        schedule_cron:
          anyOf:
            - type: string
            - type: 'null'
          title: Schedule Cron
          description: Cron schedule for refresh.
      type: object
      title: SemanticModelUpdate
      description: Request to update a semantic model.
    SemanticModelResponse:
      properties:
        name:
          type: string
          title: Name
          description: Business-friendly model name.
        description:
          type: string
          title: Description
          description: Model description.
          default: ''
        domain_urn:
          type: string
          title: Domain Urn
          description: DataHub domain URN.
        domain_name:
          type: string
          title: Domain Name
          description: Human-readable domain name.
        id:
          type: string
          format: uuid
          title: Id
        source_tables:
          type: string
          title: Source Tables
        generated_sql:
          type: string
          title: Generated Sql
        approved_sql:
          anyOf:
            - type: string
            - type: 'null'
          title: Approved Sql
        target_catalog:
          type: string
          title: Target Catalog
        target_schema:
          type: string
          title: Target Schema
        view_name:
          anyOf:
            - type: string
            - type: 'null'
          title: View Name
        status:
          $ref: '#/components/schemas/SemanticModelStatus'
        ai_confidence_score:
          anyOf:
            - type: number
            - type: 'null'
          title: Ai Confidence Score
        ai_reasoning:
          anyOf:
            - type: string
            - type: 'null'
          title: Ai Reasoning
        generation_task_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Generation Task Id
        reviewed_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Reviewed By
        reviewed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Reviewed At
        review_notes:
          anyOf:
            - type: string
            - type: 'null'
          title: Review Notes
        schedule_cron:
          anyOf:
            - type: string
            - type: 'null'
          title: Schedule Cron
        job_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Job Id
        created_by:
          type: string
          title: Created By
        owner_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner Id
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        deployed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Deployed At
        external_id:
          anyOf:
            - type: string
            - type: 'null'
          title: External Id
        version:
          type: integer
          title: Version
        parent_model_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Parent Model Id
      type: object
      required:
        - name
        - domain_urn
        - domain_name
        - id
        - source_tables
        - generated_sql
        - approved_sql
        - target_catalog
        - target_schema
        - view_name
        - status
        - ai_confidence_score
        - ai_reasoning
        - generation_task_id
        - reviewed_by
        - reviewed_at
        - review_notes
        - schedule_cron
        - job_id
        - created_by
        - owner_id
        - created_at
        - updated_at
        - deployed_at
        - external_id
        - version
        - parent_model_id
      title: SemanticModelResponse
      description: Response model for a semantic model.
    ErrorResponse:
      properties:
        error:
          type: string
          title: Error
          description: A brief description of the error that occurred.
        code:
          type: integer
          title: Code
          description: The HTTP status code associated with the error.
          default: 500
      type: object
      required:
        - error
      title: ErrorResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SemanticModelStatus:
      type: string
      enum:
        - draft
        - pending_review
        - approved
        - rejected
        - deployed
        - failed
        - archived
      title: SemanticModelStatus
      description: Status of a semantic model.
    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
  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

````