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

# Terminate a subscription

> This endpoint allows you to terminate a subscription.

<RequestExample>
  ```bash cURL theme={"dark"}
  LAGO_URL="https://api.getlago.com"
  API_KEY="__YOUR_API_KEY__"
  EXTERNAL_ID="__YOUR_SUBSCRIPTION_ID__"

  curl --location --request DELETE "$LAGO_URL/api/v1/subscriptions/$EXTERNAL_ID?status=pending" \
    --header "Authorization: Bearer $API_KEY"
  ```

  ```python Python theme={"dark"}
  from lago_python_client.client import Client
  from lago_python_client.exceptions import LagoApiError

  client = Client(api_key='__YOUR_API_KEY__')

  try:
      client.subscriptions.destroy('external_id')
  except LagoApiError as e:
      repair_broken_state(e)  # do something on error or raise your own exception
  ```

  ```ruby Ruby theme={"dark"}
  require 'lago-ruby-client'

  client = Lago::Api::Client.new(api_key: '__YOUR_API_KEY__')
  client.subscriptions.destroy("5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba")
  ```

  ```js Javascript theme={"dark"}
  await client.subscriptions.destroySubscription("external_id");
  ```

  ```go Go theme={"dark"}
  import "fmt"
  import "github.com/getlago/lago-go-client"

  func main() {
  lagoClient := lago.New().
      SetApiKey("__YOUR_API_KEY__")

  subscription, err := lagoClient.Subscription().Terminate("__EXTERNAL_ID__")
  if err != nil {
      // Error is *lago.Error
      panic(err)
  }

  // subscription is *lago.Subscription
  fmt.Println(subscription)
  }
  ```
</RequestExample>


## OpenAPI

````yaml DELETE /subscriptions/{external_id}
openapi: 3.1.0
info:
  title: Lago API documentation
  description: >-
    Lago API allows your application to push customer information and metrics
    (events) from your application to the billing application.
  version: 1.45.2
  license:
    name: AGPLv3
    url: https://github.com/getlago/lago-openapi/blob/main/LICENSE
  contact:
    email: tech@getlago.com
servers:
  - url: https://api.getlago.com/api/v1
    description: US Lago cluster
  - url: https://api.eu.getlago.com/api/v1
    description: EU Lago cluster
security:
  - bearerAuth: []
tags:
  - name: activity_logs
    description: Everything about Activity logs
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/audit-logs/activity-logs-object
  - name: analytics
    description: Everything about Analytics
  - name: api_logs
    description: Everything about API logs
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/audit-logs/api-logs-object
  - name: billable_metrics
    description: Everything about Billable metric collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/billable-metrics/object
  - name: features
    description: Everything about Feature collection
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/entitlements/features/feature-object
  - name: entitlements
    description: Everything about Entitlement collection
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/entitlements/plan-entitlements/plan-entitlement-object
  - name: billing_entities
    description: Everything about Billing Entities
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/billing-entities/object
  - name: customers
    description: Everything about Customer collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/customers/object
  - name: plans
    description: Everything about Plan collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/plans/object
  - name: subscriptions
    description: Everything about Subscription collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/subscriptions/subscription-object
  - name: events
    description: Everything about Event collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/events/event-object
  - name: organizations
    description: Everything about Organization collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/organizations/organization-object
  - name: taxes
    description: Everything about Tax collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/taxes/tax-object
  - name: coupons
    description: Everything about Coupon collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/coupons/coupon-object
  - name: add_ons
    description: Everything about Add-on collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/add-ons/add-on-object
  - name: fees
    description: Everything about Fees
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/invoices/invoice-object#fee-object
  - name: invoices
    description: Everything about Invoice collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/invoices/invoice-object
  - name: wallets
    description: Everything about Wallet collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/wallets/wallet-object
  - name: credit_notes
    description: Everything about Credit notes collection
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/credit-notes/credit-note-object
  - name: webhooks
    description: Everything about Webhooks
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/webhooks/format---signature#1-retrieve-the-public-key
  - name: webhook_endpoints
    description: Everything about Webhook Endpoints
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/webhook-endpoints/webhook-endpoint-object
  - name: payment_receipts
    description: Everything about Payment receipts
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/payment-receipts/payment-receipt-object
  - name: payment_requests
    description: Everything about PaymentRequests
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/payment-requests/payment-request-object
  - name: payments
    description: Everything about Payments
    externalDocs:
      description: Find out more
      url: https://getlago.com/docs/api-reference/payments/payment-object
  - name: payment_methods
    description: Everything about Payment Methods
    externalDocs:
      description: Find out more
      url: >-
        https://getlago.com/docs/api-reference/payment-methods/payment-method-object
externalDocs:
  description: Lago Github
  url: https://github.com/getlago
paths:
  /subscriptions/{external_id}:
    parameters:
      - name: external_id
        in: path
        description: External ID of the existing subscription
        required: true
        schema:
          type: string
          example: 5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba
    delete:
      tags:
        - subscriptions
      summary: Terminate a subscription
      description: This endpoint allows you to terminate a subscription.
      operationId: destroySubscription
      parameters:
        - name: status
          in: query
          description: >-
            If the field is not defined, Lago will terminate only `active`
            subscriptions. However, if you wish to cancel a `pending`
            subscription, please ensure that you include `status=pending` in
            your request.
          required: false
          explode: true
          schema:
            type: string
            example: pending
        - name: on_termination_credit_note
          in: query
          description: >
            When a pay-in-advance subscription is terminated before the end of
            its billing period, we generate a credit note for the unused
            subscription time by default.

            This field allows you to control the behavior of the credit note
            generation:


            - `credit`: A credit note is generated for the unused subscription
            time. The unused amount is credited back to the customer.

            - `refund`: A credit note is generated for the unused subscription
            time. If the invoice is paid or partially paid, the unused paid
            amount is refunded; any unpaid unused amount is credited back to the
            customer.

            - `skip`: No credit note is generated for the unused subscription
            time.


            _Note: This field is only applicable to pay-in-advance plans and is
            ignored for pay-in-arrears plans._
          required: false
          schema:
            type: string
            enum:
              - credit
              - refund
              - skip
            example: credit
        - name: on_termination_invoice
          in: query
          description: >
            When a subscription is terminated before the end of its billing
            period, we generate an invoice for the unbilled usage.

            This field allows you to control the behavior of the invoice
            generation:


            - `generate`: An invoice is generated for the unbilled usage.

            - `skip`: No invoice is generated for the unbilled usage.
          required: false
          schema:
            type: string
            enum:
              - generate
              - skip
            example: generate
      responses:
        '200':
          description: Subscription terminated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Subscription'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
components:
  schemas:
    Subscription:
      type: object
      required:
        - subscription
      properties:
        subscription:
          $ref: '#/components/schemas/SubscriptionObject'
    SubscriptionObject:
      type: object
      required:
        - billing_time
        - canceled_at
        - created_at
        - current_billing_period_ending_at
        - current_billing_period_started_at
        - downgrade_plan_date
        - ending_at
        - external_customer_id
        - external_id
        - lago_customer_id
        - lago_id
        - name
        - next_plan_code
        - on_termination_credit_note
        - on_termination_invoice
        - plan_code
        - previous_plan_code
        - started_at
        - status
        - subscription_at
        - terminated_at
        - trial_ended_at
      properties:
        lago_id:
          type: string
          format: uuid
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
          description: >-
            Unique identifier assigned to the subscription within the Lago
            application. This ID is exclusively created by Lago and serves as a
            unique identifier for the subscription's record within the Lago
            system
        external_id:
          type: string
          example: 5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba
          description: >-
            The subscription external unique identifier (provided by your own
            application).
        lago_customer_id:
          type: string
          format: uuid
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
          description: >-
            Unique identifier assigned to the customer within the Lago
            application. This ID is exclusively created by Lago and serves as a
            unique identifier for the customer's record within the Lago system
        external_customer_id:
          type: string
          example: 5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba
          description: >-
            The customer external unique identifier (provided by your own
            application).
        billing_time:
          type: string
          description: >-
            The billing time for the subscription, which can be set as either
            `anniversary` or `calendar`. If not explicitly provided, it will
            default to `calendar`. The billing time determines the timing of
            recurring billing cycles for the subscription. By specifying
            `anniversary`, the billing cycle will be based on the specific date
            the subscription started (billed fully), while `calendar` sets the
            billing cycle at the first day of the week/month/year (billed with
            proration).
          example: anniversary
          enum:
            - calendar
            - anniversary
        name:
          type:
            - string
            - 'null'
          example: Repository A
          description: >-
            The display name of the subscription on an invoice. This field
            allows for customization of the subscription's name for billing
            purposes, especially useful when a single customer has multiple
            subscriptions using the same plan.
        plan_code:
          type: string
          example: premium
          description: >-
            The unique code representing the plan to be attached to the
            customer. This code must correspond to the `code` property of one of
            the active plans.
        plan_amount_cents:
          type: integer
          description: >-
            The base cost of the related plan, excluding any applicable taxes,
            that is billed on a recurring basis.
          example: 10000
        plan_amount_currency:
          $ref: '#/components/schemas/Currency'
          description: >-
            The currency of the related plan. It indicates the monetary unit in
            which the plan's cost, including taxes and usage-based charges, is
            expressed.
          example: USD
        status:
          type: string
          description: >-
            The status of the subscription, which can have the following values:

            - `active`: the subscription is currently active and applied to the
            customer.

            - `canceled`: the subscription has been stopped before its
            activation. This can occur when two consecutive downgrades have been
            applied to a customer or when a subscription with a pending status
            is terminated.

            - `pending`: a previous subscription has been downgraded, and the
            current one is awaiting automatic activation at the end of the
            billing period.

            - `terminated`: the subscription is no longer active.
          example: active
          enum:
            - active
            - canceled
            - pending
            - terminated
        created_at:
          type: string
          format: date-time
          example: '2022-08-08T00:00:00Z'
          description: >-
            The creation date of the subscription, represented in ISO 8601
            datetime format and expressed in Coordinated Universal Time (UTC).
            This date provides a timestamp indicating when the subscription was
            initially created.
        canceled_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-09-14T16:35:31Z'
          description: >-
            The cancellation date of the subscription. This field is not null
            when the subscription is `canceled`. This date should be provided in
            ISO 8601 datetime format and expressed in Coordinated Universal Time
            (UTC).
        started_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-08-08T00:00:00Z'
          description: >-
            The effective start date of the subscription. This field can be null
            if the subscription is `pending` or `canceled`. This date should be
            provided in ISO 8601 datetime format and expressed in Coordinated
            Universal Time (UTC).
        ending_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-10-08T00:00:00Z'
          description: >-
            The effective end date of the subscription. If this field is set to
            null, the subscription will automatically renew. This date should be
            provided in ISO 8601 datetime format, and use Coordinated Universal
            Time (UTC).
        subscription_at:
          type: string
          format: date-time
          example: '2022-08-08T00:00:00Z'
          description: >-
            The anniversary date and time of the initial subscription. This date
            serves as the basis for billing subscriptions with `anniversary`
            billing time. The `anniversary_date` should be provided in ISO 8601
            datetime format and expressed in Coordinated Universal Time (UTC).
        terminated_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-09-14T16:35:31Z'
          description: >-
            The termination date of the subscription. This field is not null
            when the subscription is `terminated`. This date should be provided
            in ISO 8601 datetime format and expressed in Coordinated Universal
            Time (UTC)
        previous_plan_code:
          type:
            - string
            - 'null'
          example: null
          description: >-
            The code identifying the previous plan associated with this
            subscription.
        next_plan_code:
          type:
            - string
            - 'null'
          example: null
          description: The code identifying the next plan in the case of a downgrade.
        downgrade_plan_date:
          type:
            - string
            - 'null'
          format: date
          example: '2022-04-30'
          description: >-
            The date when the plan will be downgraded, represented in ISO 8601
            date format.
        trial_ended_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-08-08T00:00:00Z'
          description: >-
            The date when the free trial is ended, represented in ISO 8601 date
            format.
        current_billing_period_started_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-08-08T00:00:00Z'
          description: >-
            The date and time when the current billing period started,
            represented in ISO 8601 date format.
        current_billing_period_ending_at:
          type:
            - string
            - 'null'
          format: date-time
          example: '2022-09-08T00:00:00Z'
          description: >-
            The date and time when the current billing period ends, represented
            in ISO 8601 date format.
        on_termination_credit_note:
          type:
            - string
            - 'null'
          description: >
            When a pay-in-advance subscription is terminated before the end of
            its billing period, we generate a credit note for the unused
            subscription time by default.

            This field allows you to control the behavior of the credit note
            generation:


            - `credit`: A credit note is generated for the unused subscription
            time. The unused amount is credited back to the customer.

            - `refund`: A credit note is generated for the unused subscription
            time. If the invoice is paid or partially paid, the unused paid
            amount is refunded; any unpaid unused amount is credited back to the
            customer.

            - `offset`: A credit note is generated for the unused subscription
            time. If the invoice is paid or partially paid, the unused paid
            amount is refunded; any unpaid unused amount is applied to the
            invoice reducing its amount due.

            - `skip`: No credit note is generated for the unused subscription
            time.


            _Note: This field is only applicable to pay-in-advance plans and
            will be `null` for pay-in-arrears plans._
          example: credit
          enum:
            - credit
            - refund
            - offset
            - skip
        on_termination_invoice:
          type:
            - string
          example: generate
          enum:
            - generate
            - skip
          default: generate
          description: >
            When a subscription is terminated before the end of its billing
            period, we generate an invoice for the unbilled usage.

            This field allows you to control the behavior of the invoice
            generation:


            - `generate`: An invoice is generated for the unbilled usage.

            - `skip`: No invoice is generated for the unbilled usage.
        applied_invoice_custom_sections:
          description: >-
            The invoice custom sections applied to invoices generated by this
            subscription.
          type: array
          items:
            $ref: '#/components/schemas/AppliedInvoiceCustomSectionObject'
        payment_method:
          $ref: '#/components/schemas/PaymentMethodReference'
          description: >-
            The payment method assigned to this subscription for processing
            payments.
    ApiErrorUnauthorized:
      type: object
      required:
        - status
        - error
      properties:
        status:
          type: integer
          format: int32
          example: 401
        error:
          type: string
          example: Unauthorized
    ApiErrorNotFound:
      type: object
      required:
        - status
        - error
        - code
      properties:
        status:
          type: integer
          format: int32
          example: 404
        error:
          type: string
          example: Not Found
        code:
          type: string
          example: object_not_found
    ApiErrorUnprocessableEntity:
      type: object
      required:
        - status
        - error
        - code
        - error_details
      properties:
        status:
          type: integer
          format: int32
          example: 422
        error:
          type: string
          example: Unprocessable entity
        code:
          type: string
          example: validation_errors
        error_details:
          type: object
    Currency:
      type: string
      example: USD
      enum:
        - AED
        - AFN
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CDF
        - CHF
        - CLF
        - CLP
        - CNY
        - COP
        - CRC
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - ISK
        - JMD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRO
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLL
        - SOS
        - SRD
        - STD
        - SZL
        - THB
        - TJS
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
    AppliedInvoiceCustomSectionObject:
      type: object
      required:
        - lago_id
        - created_at
        - invoice_custom_section
      properties:
        lago_id:
          type: string
          format: uuid
          description: >-
            Unique identifier of the applied invoice custom section in the Lago
            application.
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
        created_at:
          type: string
          format: date-time
          description: >-
            The date of the applied invoice custom section creation, represented
            in ISO 8601 datetime format and expressed in Coordinated Universal
            Time (UTC).
          example: '2023-07-06T14:35:58Z'
        invoice_custom_section_id:
          deprecated: true
          type: string
          format: uuid
          description: Unique identifier of the invoice custom section that was applied.
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
        invoice_custom_section:
          $ref: '#/components/schemas/InvoiceCustomSectionObject'
    PaymentMethodReference:
      type: object
      description: Reference to a specific payment method for processing the payment.
      properties:
        payment_method_type:
          type: string
          enum:
            - provider
            - manual
          description: The type of payment method to use.
          example: provider
        payment_method_id:
          type: string
          format: uuid
          description: >-
            The unique identifier of the payment method (required when using a
            specific provider payment method).
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
    InvoiceCustomSectionObject:
      type: object
      required:
        - lago_id
        - name
        - code
      properties:
        lago_id:
          type: string
          format: uuid
          description: >-
            Unique identifier for the invoice custom section in the Lago
            application, generated by Lago to ensure record uniqueness within
            the system.
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
        name:
          type: string
          description: Name of the invoice custom section.
          example: EU Bank Details
        code:
          type: string
          description: >-
            Unique code identifying the invoice custom section for the API
            request.
          example: eu_bank_details
        description:
          type: string
          description: Internal description of the invoice custom section.
          example: This section contains the bank details for EU customers.
        details:
          type: string
          description: The value shown on the invoice PDF.
          example: 'Bank Name: Lago Bank, IBAN: FR7630004000031234567890143'
        display_name:
          type: string
          description: The name of the invoice custom section displayed on the invoice.
          example: 'Bank Details:'
        applied_to_organization:
          type: boolean
          deprecated: true
          description: >-
            This field is deprecated and will be removed in a future version.
            When set to true, it applies the invoice custom section to the
            organization's default billing entity. To apply or remove an invoice
            custom section from any billing entity (including the default one),
            please use the `PUT /billing_entities/:code` endpoint instead.
          example: true
        organization_id:
          type: string
          format: uuid
          description: >-
            Unique identifier for the organization associated with the invoice
            custom section.
          example: 1a901a90-1a90-1a90-1a90-1a901a901a90
        created_at:
          type: string
          format: date-time
          description: Creation date of the tax.
          example: '2023-07-06T14:35:58Z'
  responses:
    Unauthorized:
      description: Unauthorized error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorUnauthorized'
    NotFound:
      description: Not Found error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorNotFound'
    UnprocessableEntity:
      description: Unprocessable entity error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorUnprocessableEntity'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````