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

# Cancel a subscription

> Cancels a subscription. You can modify the behavior of the cancellation based on the arguments passed to the call.

<CodeGroup>
  ```py Python theme={null}
  lotus.cancel_subscription(
      subscription_id='sub_a623349004cd4947aca1851c64aa6fbd',
      flat_fee_behavior='charge_prorated',
      usage_behavior='bill_full',
      invoicing_behavior='invoice_now'
  )
  ```

  ```ts Typescript theme={null}
  await lotus.cancelSubscription({
    subscription_id: "sub_a623349004cd4947aca1851c64aa6fbd",
    flat_fee_behavior: "charge_prorated",
    usage_behavior: "bill_full",
    invoicing_behavior: "invoice_now",
  });
  ```
</CodeGroup>

***


## OpenAPI

````yaml POST /api/subscriptions/{subscription_id}/cancel/
openapi: 3.0.3
info:
  title: Lotus API
  version: 0.9.3
  description: >-
    Lotus is an open-core pricing and billing engine. We enable API companies to
    automate and optimize their custom usage-based pricing for any metric.
servers: []
security: []
paths:
  /api/subscriptions/{subscription_id}/cancel/:
    post:
      tags:
        - api
      operationId: api_subscriptions_cancel_create_2
      parameters:
        - in: path
          name: subscription_id
          schema:
            type: string
          description: The ID of the subscription to cancel.
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionRecordCancelRequest'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/SubscriptionRecordCancelRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/SubscriptionRecordCancelRequest'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionRecord'
          description: ''
      security:
        - knoxTokenAuth: []
        - OrganizationApiKeyAuth: []
          TokenAuth: []
components:
  schemas:
    SubscriptionRecordCancelRequest:
      type: object
      properties:
        flat_fee_behavior:
          enum:
            - refund
            - charge_prorated
            - charge_full
            - null
          type: string
          nullable: true
          description: >-
            When canceling a subscription, the behavior used to calculate the
            flat fee. If null or not provided, the charge's default behavior
            will be used according to the subscription's start and end dates. If
            charge_full, the full flat fee will be charged, regardless of the
            duration of the subscription. If refund, the flat fee will not be
            charged. If charge_prorated, the prorated flat fee will be charged.


            * `refund` - Refund

            * `charge_prorated` - Prorate

            * `charge_full` - Charge Full
        usage_behavior:
          enum:
            - bill_full
            - bill_none
          type: string
          default: bill_full
          description: >-
            If bill_full, current usage will be billed on the invoice. If
            bill_none, current unbilled usage will be dropped from the invoice.
            Defaults to bill_full.


            * `bill_full` - Bill Full

            * `bill_none` - Bill None
        invoicing_behavior:
          enum:
            - add_to_next_invoice
            - invoice_now
          type: string
          default: invoice_now
          description: >-
            Whether to invoice now or invoice at the end of the billing period.
            Defaults to invoice now.


            * `add_to_next_invoice` - Add to Next Invoice

            * `invoice_now` - Invoice Now
    SubscriptionRecord:
      type: object
      properties:
        subscription_id:
          type: string
        start_date:
          type: string
          format: date-time
          description: >-
            The time the subscription starts. This will be a string in
            yyyy-mm-dd HH:mm:ss format in UTC time.
        end_date:
          type: string
          format: date-time
          description: >-
            The time the subscription starts. This will be a string in
            yyyy-mm-dd HH:mm:ss format in UTC time.
        auto_renew:
          type: boolean
          description: Whether the subscription automatically renews. Defaults to true.
        is_new:
          type: boolean
          description: >-
            Whether this subscription came from a renewal or from a first-time.
            Defaults to true on creation.
        subscription_filters:
          type: array
          items:
            $ref: '#/components/schemas/SubscriptionFilter'
        customer:
          $ref: '#/components/schemas/LightweightCustomer'
        billing_plan:
          $ref: '#/components/schemas/LightweightPlanVersion'
        fully_billed:
          type: boolean
          readOnly: true
        addons:
          type: array
          items:
            $ref: '#/components/schemas/LightweightAddOnSubscriptionRecord'
        metadata:
          type: object
          additionalProperties: {}
      required:
        - addons
        - auto_renew
        - billing_plan
        - customer
        - end_date
        - fully_billed
        - is_new
        - metadata
        - start_date
        - subscription_filters
        - subscription_id
    SubscriptionFilter:
      type: object
      properties:
        value:
          type: string
        property_name:
          type: string
          description: 'The string name of the property to filter on. Example: ''product_id'''
      required:
        - property_name
        - value
    LightweightCustomer:
      type: object
      properties:
        customer_name:
          type: string
          readOnly: true
          nullable: true
          description: The display name of the customer
        email:
          type: string
          format: email
          readOnly: true
          nullable: true
          description: >-
            The primary email address of the customer, must be the same as the
            email address used to create the customer in the payment provider
        customer_id:
          type: string
          readOnly: true
          nullable: true
          description: >-
            The id provided when creating the customer, we suggest matching with
            your internal customer id in your backend
      required:
        - customer_id
        - customer_name
        - email
    LightweightPlanVersion:
      type: object
      properties:
        plan_name:
          type: string
          readOnly: true
        plan_id:
          type: string
        version_id:
          type: string
          readOnly: true
        version:
          oneOf:
            - type: integer
            - enum:
                - custom_version
              type: string
          readOnly: true
      required:
        - plan_id
        - plan_name
        - version
        - version_id
    LightweightAddOnSubscriptionRecord:
      type: object
      properties:
        addon_subscription_id:
          type: string
        start_date:
          type: string
          format: date-time
          readOnly: true
          description: >-
            The time the subscription starts. This will be a string in
            yyyy-mm-dd HH:mm:ss format in UTC time.
        end_date:
          type: string
          format: date-time
          readOnly: true
          description: >-
            The time the subscription starts. This will be a string in
            yyyy-mm-dd HH:mm:ss format in UTC time.
        addon:
          $ref: '#/components/schemas/LightweightAddOn'
        fully_billed:
          type: boolean
          readOnly: true
      required:
        - addon
        - addon_subscription_id
        - end_date
        - fully_billed
        - start_date
    LightweightAddOn:
      type: object
      properties:
        addon_name:
          type: string
          description: The name of the add-on plan.
        addon_id:
          type: string
          description: The ID of the add-on plan.
        addon_type:
          enum:
            - flat
            - usage_based
          type: string
          readOnly: true
        billing_frequency:
          enum:
            - one_time
            - recurring
          description: |-
            * `one_time` - one_time
            * `recurring` - recurring
          readOnly: true
      required:
        - addon_id
        - addon_name
        - addon_type
        - billing_frequency
  securitySchemes:
    knoxTokenAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Token-based authentication with required prefix "Token"
    OrganizationApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````