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

# Create a cost rule

> Create a cost rule. Accepts the same snake_case body as the admin Cost Rules
API. Requires the tenant **Cost Rules** feature flag.

On create, `name` and `document_types` (or singular `document_type`) are
required; `vendor_id` is required unless `output_kind` is `EXTRA_COST`.
When `output_kind` is `EXTRA_COST`, `cost_basis` and `cost_basis_amount`
become required.




## OpenAPI

````yaml /api-reference/build.yaml post /cost-rules
openapi: 3.0.0
info:
  title: Luminous API
  version: 1.0.0
  description: API documentation for Luminous
servers:
  - url: https://{companyName}.api.joinluminous.com/external/api/v1
    variables:
      companyName:
        default: companyName
        description: Your company-specific subdomain
security: []
tags:
  - name: Products
    description: Get and manage products
  - name: Pricing
    description: Manage price schedules, levels, and customizations
  - name: BOMs
    description: Manage Bills of Materials (BOMs)
  - name: Labels
    description: Label rendering via Labelary ZPL service
  - name: Companies
    description: Manage business accounts and their associated data
  - name: Contacts
    description: Manage contact information for individuals
  - name: Suppliers
    description: Manage suppliers (factories) — vendors used on purchase orders
  - name: Supplier SKUs
    description: Manage per-supplier SKU and unit-cost overrides for products
  - name: Locations
    description: Manage warehouses and locations
  - name: Inventory
    description: Get and adjust product stock levels
  - name: Lots
    description: Create, update, and delete product lots (batches)
  - name: Transfer Orders
    description: Manage transfer orders
  - name: Fulfillment Orders
    description: Manage fulfillment orders and picklists
  - name: Purchase Orders
    description: Get and modify purchase orders
  - name: Receiving Reports
    description: Manage receiving reports
  - name: Payment Obligations
    description: Manage payment obligations for purchase orders
  - name: Sales Orders
    description: Manage sales orders and sales order shipments
  - name: Purgatory
    description: >-
      Inspect and resolve non-posted sales orders in the purgatory staging
      workflow
  - name: PickFlow Shipping
    description: >-
      Provider-agnostic shipping rates, services, packages, and label purchase
      for PickFlow
  - name: Cycle Counts
    description: >-
      Create, drive, and post PickFlow cycle counts — batches, per-warehouse
      sessions, and CSV import/export
  - name: Print Stations
    description: List paired print stations and enqueue print jobs to them
  - name: Invoices
    description: Get and manage invoices
  - name: Work Orders
    description: >-
      Manage work orders — production lifecycle, steps, materials, links,
      shipments, and comments
  - name: Production Batches
    description: Group and manage work orders as production batches
  - name: Bills
    description: >-
      Accounts payable bill management, payments, attachments, allocations, and
      variance
  - name: Prepayments
    description: Manage vendor prepayments and applications
  - name: Vendor Credits
    description: Manage vendor credits and applications
  - name: Vendor Returns
    description: Manage vendor returns and credit generation
  - name: Customer Returns
    description: Manage customer returns (sales returns), receiving, and restock behavior
  - name: Stock Snapshot
    description: Point-in-time stock snapshots with export support
  - name: Consumption
    description: Consumption reports and exports
  - name: Inventory Aging
    description: Cost-layer-based inventory aging reports
  - name: Bills Reports
    description: Accounts payable bills aging reports
  - name: Forecast
    description: Materialized forecast data
  - name: Reports
    description: Close the books, inventory discrepancy, transaction COGS, and EDI reports
  - name: Tags
    description: Add/remove tags across various resources
  - name: Custom Fields
    description: Get and set custom fields across various resources
  - name: Currency
    description: Currency configuration, exchange rates, and conversion
  - name: Integration Mappings
    description: Manage integration mappings for external systems
  - name: Integration Field Mappings
    description: Manage field-level mappings between Luminous and external systems
paths:
  /cost-rules:
    post:
      tags:
        - Cost Rules
      summary: Create a cost rule
      description: >
        Create a cost rule. Accepts the same snake_case body as the admin Cost
        Rules

        API. Requires the tenant **Cost Rules** feature flag.


        On create, `name` and `document_types` (or singular `document_type`) are

        required; `vendor_id` is required unless `output_kind` is `EXTRA_COST`.

        When `output_kind` is `EXTRA_COST`, `cost_basis` and `cost_basis_amount`

        become required.
      operationId: createCostRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - type: object
                  properties:
                    vendor_id:
                      type: integer
                      description: >
                        Supplier / factory ID. Required on create unless
                        `output_kind` is `EXTRA_COST`

                        (where the supplier is an optional document condition).
                        Optional on update.
                    name:
                      type: string
                      maxLength: 255
                      description: >-
                        Rule name. Required on create. Must be unique per vendor
                        among non-deleted rules.
                    description:
                      type: string
                      maxLength: 1000
                      nullable: true
                    document_types:
                      type: array
                      description: >-
                        Document types the rule applies to. Required on create
                        (or provide singular `document_type`).
                      minItems: 1
                      items:
                        type: string
                        enum:
                          - PURCHASE_ORDER
                          - WORK_ORDER
                          - SHIPMENT
                    document_type:
                      type: string
                      description: Singular alternative to `document_types` (back-compat).
                      enum:
                        - PURCHASE_ORDER
                        - WORK_ORDER
                        - SHIPMENT
                    tier_mode:
                      type: string
                      enum:
                        - NON_GRADUATED
                        - GRADUATED
                      description: Defaults to `NON_GRADUATED`.
                    tier_quantity_basis:
                      type: string
                      enum:
                        - LINE
                        - SCOPE_GROUP
                      description: Defaults to `LINE`.
                    priority:
                      type: integer
                      minimum: 1
                      maximum: 1000
                      description: Defaults to `100`.
                    status:
                      type: string
                      enum:
                        - ACTIVE
                        - INACTIVE
                        - DRAFT
                      description: Defaults to `ACTIVE` on create.
                    effective_from:
                      type: string
                      format: date
                      nullable: true
                    effective_to:
                      type: string
                      format: date
                      nullable: true
                      description: Must be on or after `effective_from`.
                    moq:
                      type: number
                      minimum: 0
                      nullable: true
                    order_multiple:
                      type: number
                      minimum: 0
                      nullable: true
                    is_active:
                      type: boolean
                      nullable: true
                    output_kind:
                      type: string
                      enum:
                        - UNIT_COST
                        - EXTRA_COST
                      description: Defaults to `UNIT_COST`.
                    extra_cost_item_name:
                      type: string
                      maxLength: 255
                      nullable: true
                    cost_allocation_type:
                      type: string
                      nullable: true
                      enum:
                        - UNIT_BASED_ALLOCATION
                        - VOLUME_BASED_ALLOCATION
                        - WEIGHT_BASED_ALLOCATION
                        - VALUE_BASED_ALLOCATION
                    cost_basis:
                      type: string
                      enum:
                        - PERCENTAGE
                        - FIXED
                      nullable: true
                      description: Required when `output_kind` is `EXTRA_COST`.
                    cost_basis_amount:
                      type: number
                      minimum: 0
                      nullable: true
                      description: Required when `output_kind` is `EXTRA_COST`.
                    shipment_type:
                      type: string
                      maxLength: 30
                      nullable: true
                    options:
                      type: object
                      properties:
                        auto_apply:
                          type: boolean
                          description: >-
                            Server fires this rule automatically on PO /
                            shipment save.
                        add_as_additional_fee:
                          type: boolean
                          description: >-
                            Mirror the produced line to a PO additional fee
                            (PURCHASE_ORDER + EXTRA_COST only).
                    scopes:
                      type: array
                      description: >-
                        Product / category / tag / supplier-SKU scopes. Replaces
                        existing scopes when provided.
                      items:
                        type: object
                        required:
                          - scope_type
                          - scope_value
                        properties:
                          scope_type:
                            type: string
                            enum:
                              - PRODUCT
                              - SUPPLIER_SKU
                              - CATEGORY
                              - SUBCATEGORY
                              - TAG
                              - ATTRIBUTE
                          scope_value:
                            type: string
                          scope_operator:
                            type: string
                            enum:
                              - EQUALS
                              - NOT_EQUALS
                              - IN
                              - NOT_IN
                              - CONTAINS
                              - STARTS_WITH
                              - ENDS_WITH
                              - GREATER_THAN
                              - LESS_THAN
                              - GREATER_THAN_OR_EQUALS
                              - LESS_THAN_OR_EQUALS
                              - ALL
                          scope_extra:
                            type: object
                            nullable: true
                    conditions:
                      type: array
                      description: >-
                        Document-level applicability gates. Replaces existing
                        conditions when provided.
                      items:
                        type: object
                        required:
                          - condition_type
                          - values
                        properties:
                          condition_type:
                            type: string
                            enum:
                              - SUPPLIER
                              - SOURCE_WAREHOUSE
                              - DESTINATION_WAREHOUSE
                              - SHIPMENT_TYPE
                          operator:
                            type: string
                            enum:
                              - IN
                              - NOT_IN
                          values:
                            type: array
                            minItems: 1
                            items:
                              type: string
                    tiers:
                      type: array
                      description: >-
                        Quantity tiers with their effects. Replaces existing
                        tiers when provided.
                      items:
                        type: object
                        required:
                          - min_quantity
                          - effects
                        properties:
                          min_quantity:
                            type: number
                            minimum: 0
                          max_quantity:
                            type: number
                            minimum: 0
                            nullable: true
                            description: Must be greater than or equal to `min_quantity`.
                          effects:
                            type: array
                            minItems: 1
                            items:
                              type: object
                              required:
                                - effect_type
                                - amount
                              properties:
                                effect_type:
                                  type: string
                                  enum:
                                    - BASE_PRICE
                                    - PERCENT_DISCOUNT
                                    - PERCENT_MARKUP
                                    - FIXED_PER_UNIT
                                    - FIXED_PER_LINE
                                    - FIXED_PER_DOCUMENT
                                    - MINIMUM_FLOOR
                                amount:
                                  type: number
                                sequence:
                                  type: integer
                                  minimum: 0
                                  nullable: true
                                description:
                                  type: string
                                  maxLength: 255
                                  nullable: true
                - required:
                    - name
            examples:
              unitCost:
                summary: Minimal unit-cost rule
                value:
                  vendor_id: 42
                  name: Material cost — SKU-ABC
                  document_types:
                    - PURCHASE_ORDER
                  status: ACTIVE
                  tiers:
                    - min_quantity: '0'
                      effects:
                        - effect_type: FIXED_PER_UNIT
                          amount: '12.50'
                          sequence: 1
                          description: Material cost
                  scopes:
                    - scope_type: PRODUCT
                      scope_value: '12345'
                      scope_operator: EQUALS
      responses:
        '201':
          description: Cost rule created.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    description: >
                      A cost rule — vendor-scoped tiered pricing or extra-cost
                      rule applied to

                      purchase orders, work orders, and shipments. Nested
                      `scopes`, `conditions`,

                      and `tiers` (with `effects`) are only present when the
                      relation is loaded

                      (always on `GET /cost-rules/{id}`).
                    properties:
                      id:
                        type: integer
                        description: Cost rule ID.
                      vendor_id:
                        type: integer
                        nullable: true
                        description: >-
                          Supplier / factory ID the rule is scoped to. Null for
                          an EXTRA_COST rule with no supplier condition.
                      vendor_name:
                        type: string
                        nullable: true
                        description: >-
                          Supplier factory name. Only present when the vendor
                          relation is loaded.
                      name:
                        type: string
                        description: Rule name, unique per vendor among non-deleted rules.
                      description:
                        type: string
                        nullable: true
                      document_type:
                        type: string
                        nullable: true
                        description: First entry of `document_types` (convenience field).
                        enum:
                          - PURCHASE_ORDER
                          - WORK_ORDER
                          - SHIPMENT
                      document_types:
                        type: array
                        description: Document types the rule applies to.
                        items:
                          type: string
                          enum:
                            - PURCHASE_ORDER
                            - WORK_ORDER
                            - SHIPMENT
                      tier_mode:
                        type: string
                        nullable: true
                        enum:
                          - NON_GRADUATED
                          - GRADUATED
                      tier_quantity_basis:
                        type: string
                        nullable: true
                        enum:
                          - LINE
                          - SCOPE_GROUP
                      priority:
                        type: integer
                        nullable: true
                        description: Evaluation priority (1–1000, lower wins).
                      status:
                        type: string
                        enum:
                          - ACTIVE
                          - INACTIVE
                          - DRAFT
                      is_active:
                        type: boolean
                        description: Convenience flag — true when `status` is `ACTIVE`.
                      effective_from:
                        type: string
                        format: date
                        nullable: true
                      effective_to:
                        type: string
                        format: date
                        nullable: true
                      moq:
                        type: number
                        nullable: true
                        description: Minimum order quantity.
                      order_multiple:
                        type: number
                        nullable: true
                      output_kind:
                        type: string
                        nullable: true
                        enum:
                          - UNIT_COST
                          - EXTRA_COST
                      extra_cost_item_name:
                        type: string
                        nullable: true
                      cost_allocation_type:
                        type: string
                        nullable: true
                        enum:
                          - UNIT_BASED_ALLOCATION
                          - VOLUME_BASED_ALLOCATION
                          - WEIGHT_BASED_ALLOCATION
                          - VALUE_BASED_ALLOCATION
                      cost_basis:
                        type: string
                        nullable: true
                        enum:
                          - PERCENTAGE
                          - FIXED
                      cost_basis_amount:
                        type: number
                        nullable: true
                      shipment_type:
                        type: string
                        nullable: true
                        description: >-
                          Optional Air/Sea/Road/Rail/Express scope for shipment
                          rules.
                      options:
                        type: object
                        description: Rule-level options bag.
                        properties:
                          auto_apply:
                            type: boolean
                            description: >-
                              Server fires this rule automatically on PO /
                              shipment save.
                          add_as_additional_fee:
                            type: boolean
                            description: >-
                              Mirror the produced line to a PO additional fee
                              (PURCHASE_ORDER + EXTRA_COST only).
                      scopes:
                        type: array
                        description: >-
                          Product / category / tag / supplier-SKU scopes.
                          Present when loaded.
                        items:
                          type: object
                          properties:
                            id:
                              type: integer
                            cost_rule_id:
                              type: integer
                            scope_type:
                              type: string
                              enum:
                                - PRODUCT
                                - SUPPLIER_SKU
                                - CATEGORY
                                - SUBCATEGORY
                                - TAG
                                - ATTRIBUTE
                            scope_value:
                              type: string
                            scope_operator:
                              type: string
                              nullable: true
                              enum:
                                - EQUALS
                                - NOT_EQUALS
                                - IN
                                - NOT_IN
                                - CONTAINS
                                - STARTS_WITH
                                - ENDS_WITH
                                - GREATER_THAN
                                - LESS_THAN
                                - GREATER_THAN_OR_EQUALS
                                - LESS_THAN_OR_EQUALS
                                - ALL
                            scope_extra:
                              type: object
                              nullable: true
                      conditions:
                        type: array
                        description: >-
                          Document-level applicability gates (extra-cost rules).
                          Present when loaded.
                        items:
                          type: object
                          properties:
                            id:
                              type: integer
                            cost_rule_id:
                              type: integer
                            condition_type:
                              type: string
                              enum:
                                - SUPPLIER
                                - SOURCE_WAREHOUSE
                                - DESTINATION_WAREHOUSE
                                - SHIPMENT_TYPE
                            operator:
                              type: string
                              nullable: true
                              enum:
                                - IN
                                - NOT_IN
                            values:
                              type: array
                              items:
                                type: string
                      tiers:
                        type: array
                        description: >-
                          Quantity tiers with their effects. Present when
                          loaded.
                        items:
                          type: object
                          properties:
                            id:
                              type: integer
                            cost_rule_id:
                              type: integer
                            min_quantity:
                              type: number
                            max_quantity:
                              type: number
                              nullable: true
                            effects:
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: integer
                                  cost_rule_id:
                                    type: integer
                                  cost_rule_tier_id:
                                    type: integer
                                  effect_type:
                                    type: string
                                    enum:
                                      - BASE_PRICE
                                      - PERCENT_DISCOUNT
                                      - PERCENT_MARKUP
                                      - FIXED_PER_UNIT
                                      - FIXED_PER_LINE
                                      - FIXED_PER_DOCUMENT
                                      - MINIMUM_FLOOR
                                  amount:
                                    type: number
                                  order:
                                    type: integer
                                    nullable: true
                                    description: Effect sequence within the tier.
                                  description:
                                    type: string
                                    nullable: true
                      created_at:
                        type: string
                        format: date-time
                      updated_at:
                        type: string
                        format: date-time
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '404':
          description: Cost Rules feature is not enabled for this tenant.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '422':
          description: >
            Validation error — e.g. missing `name`, missing vendor on a non

            extra-cost rule, duplicate name for the vendor, invalid enum value,
            or

            `cost_basis` / `cost_basis_amount` missing on an `EXTRA_COST` rule.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  errors:
                    type: object
                    additionalProperties:
                      type: array
                      items:
                        type: string
      security:
        - BearerAuth: []
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Authenticate using a bearer token. To create a token, navigate to
        /settings/api-tokens and click Create API Token.

````