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

# Create commitment

> Creates a commitment on a subscription: a minimum spend or quantity over a term, with optional committed and overage rates.



## OpenAPI

````yaml https://swagger.flexprice.io post /commitments
openapi: 3.0.1
info:
  title: Flexprice API
  description: Flexprice API Service
  contact:
    name: API Support
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
  version: '1.0'
servers:
  - url: https://us.api.flexprice.io/v1
    description: US Region
  - url: https://api.cloud.flexprice.io/v1
    description: India Region
security: []
paths:
  /commitments:
    post:
      tags:
        - Commitments
      summary: Create commitment
      description: >-
        Creates a commitment on a subscription: a minimum spend or quantity over
        a term, with optional committed and overage rates.
      operationId: createCommitment
      requestBody:
        description: Commitment
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCommitmentRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommitmentResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: python
          label: Python
          source: |-
            from flexprice import Flexprice
            from flexprice.utils import parse_datetime


            with Flexprice(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as f_client:

                res = f_client.commitments.create_commitment(end_date=parse_datetime("2024-12-01T13:56:43.281Z"), measurement="billing_period", name="<value>", scope={
                    "entity_type": "group",
                }, start_date=parse_datetime("2026-08-30T15:34:29.816Z"), type_="amount")

                # Handle response
                print(res)
        - lang: typescript
          label: TypeScript
          source: |-
            import { Flexprice } from "@flexprice/sdk";

            const flexprice = new Flexprice({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await flexprice.commitments.createCommitment({
                endDate: new Date("2024-12-01T13:56:43.281Z"),
                measurement: "billing_period",
                name: "<value>",
                scope: {
                  entityType: "group",
                },
                startDate: new Date("2026-08-30T15:34:29.816Z"),
                type: "amount",
              });

              console.log(result);
            }

            run();
        - lang: go
          label: Go
          source: "package main\n\nimport(\n\t\"context\"\n\tflexprice \"github.com/flexprice/go-sdk/v2\"\n\t\"github.com/flexprice/go-sdk/v2/types\"\n\t\"github.com/flexprice/go-sdk/v2/models/types\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := flexprice.New(\n        flexprice.WithSecurity(\"<YOUR_API_KEY_HERE>\"),\n    )\n\n    res, err := s.Commitments.CreateCommitment(ctx, types.CreateCommitmentRequest{\n        EndDate: types.MustTimeFromString(\"2024-12-01T13:56:43.281Z\"),\n        Measurement: types.CommitmentMeasurementBillingPeriod,\n        Name: \"<value>\",\n        Scope: types.CommitmentScopeInput{\n            EntityType: types.CommitmentScopeTypeGroup,\n        },\n        StartDate: types.MustTimeFromString(\"2026-08-30T15:34:29.816Z\"),\n        Type: types.CommitmentTypeAmount,\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.CommitmentResponse != nil {\n        // handle response\n    }\n}"
components:
  schemas:
    CreateCommitmentRequest:
      required:
        - end_date
        - measurement
        - name
        - scope
        - start_date
        - type
      type: object
      properties:
        active_windows:
          type: array
          items:
            $ref: '#/components/schemas/types.ActiveWindow'
        binding:
          type: boolean
          description: default false
        collection_method:
          $ref: '#/components/schemas/types.CommitmentCollectionMethod'
        committed_price:
          $ref: '#/components/schemas/CommitmentPriceInput'
        end_date:
          type: string
          format: date-time
        idempotency_key:
          maxLength: 128
          type: string
        invoice_description:
          maxLength: 500
          type: string
        invoice_label:
          maxLength: 255
          type: string
        measurement:
          $ref: '#/components/schemas/types.CommitmentMeasurement'
        metadata:
          $ref: '#/components/schemas/types.Metadata'
        name:
          maxLength: 255
          type: string
        overage_price:
          $ref: '#/components/schemas/CommitmentPriceInput'
        priority:
          type: integer
        scope:
          $ref: '#/components/schemas/CommitmentScopeInput'
        start_date:
          type: string
          format: date-time
        subscription_id:
          type: string
          description: >-
            SubscriptionID is required on POST /commitments and set server-side
            on inline commitments.
        timezone:
          type: string
        type:
          $ref: '#/components/schemas/types.CommitmentType'
        value:
          type: string
    CommitmentResponse:
      type: object
      properties:
        active_windows:
          type: array
          items:
            $ref: '#/components/schemas/types.ActiveWindow'
        binding:
          type: boolean
        collection_method:
          $ref: '#/components/schemas/types.CommitmentCollectionMethod'
        commitment_status:
          $ref: '#/components/schemas/types.CommitmentStatus'
        commitment_value:
          type: string
        committed_price_id:
          type: string
        created_at:
          type: string
          format: date-time
        created_by:
          type: string
        currency:
          type: string
        customer_id:
          type: string
        end_date:
          type: string
          format: date-time
        environment_id:
          type: string
        id:
          type: string
        idempotency_key:
          type: string
        instalment_invoicing:
          type: string
        invoice_description:
          type: string
        invoice_label:
          type: string
        measurement:
          $ref: '#/components/schemas/types.CommitmentMeasurement'
        metadata:
          $ref: '#/components/schemas/types.Metadata'
        name:
          type: string
        on_early_termination:
          $ref: '#/components/schemas/types.CommitmentEarlyTermination'
        overage_price_id:
          type: string
        priority:
          type: integer
        scope_entity_id:
          type: string
        scope_entity_type:
          $ref: '#/components/schemas/types.CommitmentScopeType'
        start_date:
          type: string
          format: date-time
        status:
          $ref: '#/components/schemas/types.Status'
        subscription_id:
          type: string
        tenant_id:
          type: string
        terminated_at:
          type: string
          format: date-time
        termination_invoice_id:
          type: string
        timezone:
          type: string
        total_amount:
          type: string
        type:
          $ref: '#/components/schemas/types.CommitmentType'
        updated_at:
          type: string
          format: date-time
        updated_by:
          type: string
        value:
          type: string
    errors.ErrorResponse:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/errors.ErrorCode'
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    types.ActiveWindow:
      type: object
      properties:
        end:
          $ref: '#/components/schemas/types.Bucket'
        start:
          $ref: '#/components/schemas/types.Bucket'
      x-speakeasy-name-override: ActiveWindow
    types.CommitmentCollectionMethod:
      type: string
      enum:
        - per_period
        - billing_terms
      x-enum-varnames:
        - CommitmentCollectionPerPeriod
        - CommitmentCollectionBillingTerms
      x-speakeasy-name-override: CommitmentCollectionMethod
    CommitmentPriceInput:
      type: object
      properties:
        amount:
          type: string
        billing_model:
          $ref: '#/components/schemas/types.BillingModel'
        tier_mode:
          $ref: '#/components/schemas/types.BillingTier'
        tiers:
          type: array
          items:
            $ref: '#/components/schemas/CreatePriceTier'
        transform_quantity:
          $ref: '#/components/schemas/price.TransformQuantity'
    types.CommitmentMeasurement:
      type: string
      enum:
        - billing_period
        - window
      x-enum-varnames:
        - CommitmentMeasurementBillingPeriod
        - CommitmentMeasurementWindow
      x-speakeasy-name-override: CommitmentMeasurement
    types.Metadata:
      type: object
      additionalProperties:
        type: string
      x-speakeasy-name-override: Metadata
    CommitmentScopeInput:
      required:
        - entity_type
      type: object
      properties:
        entity_id:
          type: string
          description: >-
            EntityID may be omitted on an inline subscription-scoped commitment;
            the new subscription's ID is used.
        entity_type:
          $ref: '#/components/schemas/types.CommitmentScopeType'
    types.CommitmentType:
      type: string
      enum:
        - amount
        - quantity
      x-enum-varnames:
        - COMMITMENT_TYPE_AMOUNT
        - COMMITMENT_TYPE_QUANTITY
      x-speakeasy-name-override: CommitmentType
    types.CommitmentStatus:
      type: string
      enum:
        - active
        - ended
        - terminated
      x-enum-varnames:
        - CommitmentStatusActive
        - CommitmentStatusEnded
        - CommitmentStatusTerminated
      x-speakeasy-name-override: CommitmentStatus
    types.CommitmentEarlyTermination:
      type: string
      enum:
        - forfeit
        - credit_note
        - bill_remaining
      x-enum-varnames:
        - CommitmentTerminationForfeit
        - CommitmentTerminationCreditNote
        - CommitmentTerminationBillRemaining
      x-speakeasy-name-override: CommitmentEarlyTermination
    types.CommitmentScopeType:
      type: string
      enum:
        - subscription
        - group
        - meter
        - price
      x-enum-varnames:
        - CommitmentScopeSubscription
        - CommitmentScopeGroup
        - CommitmentScopeMeter
        - CommitmentScopePrice
      x-speakeasy-name-override: CommitmentScopeType
    types.Status:
      type: string
      enum:
        - published
        - deleted
        - archived
      x-enum-varnames:
        - StatusPublished
        - StatusDeleted
        - StatusArchived
      x-speakeasy-name-override: Status
    errors.ErrorCode:
      type: string
      enum:
        - http_client_error
        - system_error
        - internal_error
        - not_found
        - already_exists
        - version_conflict
        - validation_error
        - invalid_operation
        - permission_denied
        - database_error
        - service_unavailable
        - too_many_requests
        - not_implemented
      x-enum-varnames:
        - ErrCodeHTTPClient
        - ErrCodeSystemError
        - ErrCodeInternalError
        - ErrCodeNotFound
        - ErrCodeAlreadyExists
        - ErrCodeVersionConflict
        - ErrCodeValidation
        - ErrCodeInvalidOperation
        - ErrCodePermissionDenied
        - ErrCodeDatabase
        - ErrCodeServiceUnavailable
        - ErrCodeTooManyRequests
        - ErrCodeNotImplemented
      x-speakeasy-name-override: ErrorCode
    types.Bucket:
      type: object
      properties:
        hour:
          maximum: 24
          minimum: 0
          type: integer
        minute:
          maximum: 59
          minimum: 0
          type: integer
      x-speakeasy-name-override: Bucket
    types.BillingModel:
      type: string
      enum:
        - FLAT_FEE
        - PACKAGE
        - TIERED
      x-enum-varnames:
        - BILLING_MODEL_FLAT_FEE
        - BILLING_MODEL_PACKAGE
        - BILLING_MODEL_TIERED
      x-speakeasy-name-override: BillingModel
    types.BillingTier:
      type: string
      enum:
        - VOLUME
        - SLAB
      x-enum-varnames:
        - BILLING_TIER_VOLUME
        - BILLING_TIER_SLAB
      x-speakeasy-name-override: BillingTier
    CreatePriceTier:
      required:
        - unit_amount
      type: object
      properties:
        flat_amount:
          type: string
          description: >-
            flat_amount is the flat amount for the given tier (optional)

            Applied on top of unit_amount*quantity. Useful for cases like "2.7$
            + 5c"
        transform_quantity:
          $ref: '#/components/schemas/price.TransformQuantity'
        unit_amount:
          type: string
          description: unit_amount is the amount per unit for the given tier
        up_to:
          type: integer
          description: >-
            up_to is the quantity up to which this tier applies. It is null for
            the last tier.

            IMPORTANT: Tier boundaries are INCLUSIVE.

            - If up_to is 1000, then quantity less than or equal to 1000 belongs
            to this tier

            - This behavior is consistent across both VOLUME and SLAB tier modes
    price.TransformQuantity:
      type: object
      properties:
        divide_by:
          type: integer
          description: Divide quantity by this number
        round:
          $ref: '#/components/schemas/types.RoundType'
    types.RoundType:
      type: string
      enum:
        - up
        - down
      x-enum-varnames:
        - ROUND_UP
        - ROUND_DOWN
      x-speakeasy-name-override: RoundType
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````

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