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

# Save a function spec as a new draft

> Save a spec as a new draft version, creating the function if it is new.

The code is checked against the allowlist before anything is stored;
a refused spec answers 422 naming the line and the reason.

**Required roles**: `author` or `workspace_admin`



## OpenAPI

````yaml post /api/decisions/{workspace}/functions
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/decisions/{workspace}/functions:
    post:
      tags:
        - Decision functions
      summary: Save a function spec as a new draft
      description: |-
        Save a spec as a new draft version, creating the function if it is new.

        The code is checked against the allowlist before anything is stored;
        a refused spec answers 422 naming the line and the reason.

        **Required roles**: `author` or `workspace_admin`
      operationId: save_function_api_decisions__workspace__functions_post
      parameters:
        - name: workspace
          in: path
          required: true
          schema:
            type: string
            maxLength: 64
            pattern: ^[a-z0-9][a-z0-9-]{0,63}$
            description: Workspace slug.
            title: Workspace
          description: Workspace slug.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FunctionSaveRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FunctionVersionDetail'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Conflict
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unprocessable Content
        '503':
          description: Service Unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    FunctionSaveRequest:
      properties:
        spec:
          additionalProperties: true
          type: object
          title: Spec
          description: The function spec.
        notes:
          anyOf:
            - type: string
            - type: 'null'
          title: Notes
          description: What changed and why.
        folder:
          anyOf:
            - type: string
              maxLength: 200
            - type: 'null'
          title: Folder
          description: >-
            Free-text grouping for the workspace page. Only used when the
            function is created.
      type: object
      required:
        - spec
      title: FunctionSaveRequest
      description: |-
        A spec to save as a draft version.

        ``spec`` is a function spec: name, kind, summary, params, returns
        (or input for a table function), code — one PySpark ``def`` — and
        tests. See the ``spark-functions`` skill for its shape.
    FunctionVersionDetail:
      properties:
        workspace:
          type: string
          title: Workspace
        name:
          type: string
          title: Name
        version:
          type: integer
          title: Version
        content_sha:
          type: string
          title: Content Sha
        status:
          $ref: '#/components/schemas/DecisionVersionStatusEnum'
        notes:
          anyOf:
            - type: string
            - type: 'null'
          title: Notes
        drafted_by_run:
          anyOf:
            - type: string
            - type: 'null'
          title: Drafted By Run
        created_by:
          type: string
          title: Created By
        created_at:
          type: string
          format: date-time
          title: Created At
        submitted_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Submitted By
        submitted_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Submitted At
        approved_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Approved By
        approved_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Approved At
        simulation:
          anyOf:
            - $ref: '#/components/schemas/SimulationSummary'
            - type: 'null'
        spec:
          additionalProperties: true
          type: object
          title: Spec
        generated_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Generated Code
          description: The module a release would ship for this version.
        simulation_report:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Simulation Report
        edited_in_place:
          type: boolean
          title: Edited In Place
          default: false
      type: object
      required:
        - workspace
        - name
        - version
        - content_sha
        - status
        - created_by
        - created_at
        - spec
      title: FunctionVersionDetail
    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
    DecisionVersionStatusEnum:
      type: string
      enum:
        - draft
        - submitted
        - approved
        - retired
      title: DecisionVersionStatusEnum
      description: |-
        Lifecycle state of a single version.

        ``draft`` → ``submitted`` → ``approved``, with ``reject`` returning a
        submitted version to ``draft`` and ``retire`` taking an approved
        version out of circulation.
    SimulationSummary:
      properties:
        passed:
          type: boolean
          title: Passed
        simulated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Simulated At
        simulated_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Simulated By
        current:
          type: boolean
          title: Current
          description: Whether it ran on this version's current content.
          default: true
      type: object
      required:
        - passed
      title: SimulationSummary
  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

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.