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

# Create a model

> Create a new model in a project. The model is defined via a YAML string that describes the node tree structure, under a top-level `nexus_nodes_attributes` list. The new model is version 0 and, as the model's first version, is active. Use [Validate model YAML](/api-reference/models/validate-yaml) to check the YAML first. Requires the `write:model` token scope.



## OpenAPI

````yaml POST /projects/{project_id}/models
openapi: 3.1.0
info:
  title: Mangrove - API
  version: 1.1.0
  description: >
    ## Filtering and sorting


    List endpoints that accept `filter` take one query parameter per condition,
    written `filter[field][comparator]=value`, for example
    `filter[name][contains]=North`. The comparators are `eq`, `neq`, `gt`,
    `geq`, `lt`, `leq` and `contains`, and `filter[field]=value` is short for
    `eq`. Conditions combine with AND. `contains` matches part of the value, is
    case-sensitive, and applies only to text fields. An unknown field or
    comparator, a value that doesn't fit the field's type, or a list or object
    as the value returns 400 with a message naming the problem. Each list
    operation names its filterable fields; some take only `eq`, and say so.


    `sort` takes a comma-separated list of fields, for example
    `sort=-created_at,name`. Each field sorts ascending, or descending with a
    `-` prefix. Unknown sort fields are ignored. Sorting by `id` orders by the
    record's internal ID, not its friendly ID. Each list operation names its
    sortable fields.
servers:
  - url: https://app.gomangrove.com/api/v1
security:
  - sec0: []
paths:
  /projects/{project_id}/models:
    post:
      summary: Create a model
      description: >-
        Create a new model in a project. The model is defined via a YAML string
        that describes the node tree structure, under a top-level
        `nexus_nodes_attributes` list. The new model is version 0 and, as the
        model's first version, is active. Use [Validate model
        YAML](/api-reference/models/validate-yaml) to check the YAML first.
        Requires the `write:model` token scope.
      operationId: create-model
      parameters:
        - $ref: '#/components/parameters/ProjectId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
              properties:
                model:
                  type: object
                  required:
                    - name
                    - yaml
                  properties:
                    name:
                      type: string
                      description: >-
                        Display name for the model. Must be unique within the
                        project.
                    yaml:
                      type: string
                      description: YAML defining the model's node tree.
            example:
              model:
                name: Carbon Calculation Model
                yaml: |
                  nexus_nodes_attributes:
                  - name: Net Carbon Removal
                    operator: difference
                    output_unit: t
                    order: 1
                    is_primary: true
                    nexus_nodes_attributes:
                    - name: Gross Removal
                      data_point_type: gross-removal
                      order: 1
                    - name: Process Emissions
                      data_point_type: process-emissions
                      order: 2
      responses:
        '201':
          description: '201'
          content:
            application/json:
              example:
                id: mod_aBcD1234eFgH5678
                name: Carbon Calculation Model
                version: 0
                version_label: null
                description: null
                is_active: true
                cadence: null
                partition_type: time
                order: 0
                is_latest: true
                is_score_producing: false
                created_at: '2025-01-15T10:00:00.000Z'
                updated_at: '2025-01-15T10:00:00.000Z'
                ledger: null
                quantification_methodology: null
                ui_url: >-
                  https://app.gomangrove.com/nexus/prj_AbCd1234567890Ef/system/mod_aBcD1234eFgH5678
              schema:
                $ref: '#/components/schemas/Model'
        '400':
          description: The `model` object is missing, or `model.yaml` is missing or blank.
          content:
            application/json:
              example:
                errors:
                  - message: YAML content is required
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          description: >-
            The project has no nexus config, the YAML does not parse, or the
            model is invalid (for example, a model with this name already exists
            in the project).
          content:
            application/json:
              examples:
                Duplicate:
                  value:
                    errors:
                      - message: Name has already been taken
                        field: name
                        code: taken
                Syntax:
                  value:
                    errors:
                      - message: >-
                          Syntax error at line 3, column 3: could not find
                          expected ':' while scanning a simple key
                NoConfiguration:
                  value:
                    errors:
                      - message: Project does not have Nexus configuration
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  parameters:
    ProjectId:
      name: project_id
      in: path
      required: true
      description: The project's friendly ID (e.g. `prj_aBcD1234eFgH5678`).
      schema:
        type: string
  schemas:
    Model:
      type: object
      description: >-
        One version of a model. Every endpoint that returns a model returns this
        shape.
      properties:
        id:
          type: string
          description: >-
            The model's friendly ID (e.g. `mod_aBcD1234eFgH5678`). Each version
            has its own.
          example: mod_aBcD1234eFgH5678
        name:
          type: string
          description: Shared by every version of the model.
        version:
          type: integer
          description: >-
            Version number. A model created through the API starts at 0, and
            each new version adds one.
        version_label:
          type:
            - string
            - 'null'
          description: >-
            A short name for the version, up to 255 characters (letters,
            numbers, spaces and `_ - . ( ) /`).
        description:
          type:
            - string
            - 'null'
          description: What changed in the version, up to 500 characters.
        is_active:
          type: boolean
          description: >-
            Whether this is the version new batch generations and model runs use
            by default. At most one version of a model is active; the first
            version is active when it is created.
        cadence:
          type:
            - string
            - 'null'
          enum:
            - hourly
            - daily
            - weekly
            - monthly
            - annually
            - null
        partition_type:
          type:
            - string
            - 'null'
          enum:
            - time
            - feedstock
            - tracking_id
            - asset
            - tracking_id_and_feedstock
            - tracking_id_and_asset
            - null
          description: >-
            How batches are partitioned. The composite values partition by both
            dimensions at once.
        order:
          type: integer
        is_latest:
          type: boolean
          description: Whether this is the highest version number of the model.
        is_score_producing:
          type: boolean
          description: >-
            Whether the model produces carbon intensity score sets rather than
            batches.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        ledger:
          type:
            - object
            - 'null'
          description: >-
            The production accounting ledger the model produces batches into, or
            null when it is not linked to one.
          properties:
            id:
              type: string
              example: led_aBcD1234eFgH5678
            name:
              type: string
        quantification_methodology:
          type:
            - object
            - 'null'
          description: >-
            The designated quantification methodology, or null for a production
            model.
          properties:
            id:
              type: integer
            name:
              type: string
        ui_url:
          type:
            - string
            - 'null'
          format: uri
          description: >-
            Link that opens this model in the Mangrove app. Null when the model
            has no project.
          example: >-
            https://app.gomangrove.com/nexus/prj_AbCd1234567890Ef/system/mod_aBcD1234eFgH5678
    ErrorResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: array
          items:
            type: object
            required:
              - message
            properties:
              message:
                type: string
                description: Human-readable error message
              field:
                type: string
                description: Attribute the error applies to (validation errors only)
              code:
                type: string
                description: Machine-readable error code (validation errors only)
              blocking:
                type: array
                description: >-
                  Bounded preview of the records blocking a destroy
                  (blocked-destroy errors only)
                items:
                  $ref: '#/components/schemas/DeletionBlockingRecord'
              blocking_count:
                type: integer
                description: >-
                  Total count of records blocking a destroy (blocked-destroy
                  errors only)
              config_key:
                type: string
                description: >-
                  The data feed source config setting to fix, when the error is
                  on `config` (data feed source validation errors only)
              count:
                type: number
                description: >-
                  The limit or comparison value the failed validation checked
                  against, e.g. a maximum length or a numeric bound (validation
                  errors only, when the validation has one)
              value:
                description: >-
                  The rejected value, e.g. on an inclusion or uniqueness failure
                  (validation errors only, when the validation reports one)
    DeletionBlockingRecord:
      type: object
      required:
        - type
      properties:
        type:
          type: string
        friendly_id:
          type: string
        name:
          type:
            - string
            - 'null'
          description: >-
            Display label, and the only identifier for records that have no
            friendly_id
  responses:
    Unauthorized:
      description: >-
        The API token is missing, invalid or expired. The body is empty, except
        for an expired token, which returns the error below.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            errors:
              - message: API token has expired
    Forbidden:
      description: >-
        The token lacks the scope the operation's description names, or a
        condition the description states applies, such as a feature that isn't
        enabled for your account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            errors:
              - message: You are not authorized to perform this action
    NotFound:
      description: >-
        A resource named in the path doesn't exist in your account, or the token
        can't see it.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            errors:
              - message: Record not found
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: Authorization
      x-bearer-format: ''

````

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