> ## Documentation Index
> Fetch the complete documentation index at: https://razorpay-60c89f9a-mintlify-audit-missing-sections-1778528421.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel a subscription

> Cancels an active subscription. You can choose to cancel immediately or at the end of the current billing cycle.



## OpenAPI

````yaml /openapi/products.json post /subscriptions/{id}/cancel
openapi: 3.1.0
info:
  title: Razorpay Products API
  description: >-
    API specification for Razorpay Payment Links, Subscriptions, and QR Codes
    products.
  version: 1.0.0
  contact:
    name: Razorpay Support
    url: https://razorpay.com/support
servers:
  - url: https://api.razorpay.com/v1
    description: Razorpay Production API
security:
  - basicAuth: []
tags:
  - name: Payment Links
    description: >-
      Create and manage payment links to collect payments from customers without
      building a checkout flow.
  - name: Plans
    description: >-
      Create and manage plans that define the billing period and amount for
      subscriptions.
  - name: Subscriptions
    description: >-
      Create and manage recurring subscriptions for customers based on defined
      plans.
  - name: QR Codes
    description: Create and manage QR codes for accepting UPI payments in-store or online.
  - name: Invoices
    description: Create and manage invoices to bill customers for products and services.
paths:
  /subscriptions/{id}/cancel:
    post:
      tags:
        - Subscriptions
      summary: Cancel a subscription
      description: >-
        Cancels an active subscription. You can choose to cancel immediately or
        at the end of the current billing cycle.
      operationId: cancelSubscription
      parameters:
        - name: id
          in: path
          required: true
          description: Unique identifier of the subscription to cancel.
          schema:
            type: string
            example: sub_00000000000001
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelSubscriptionRequest'
            example:
              cancel_at_cycle_end: 0
      responses:
        '200':
          description: Subscription cancelled successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Subscription'
              example:
                id: sub_00000000000001
                entity: subscription
                plan_id: plan_00000000000001
                status: cancelled
                total_count: 6
                paid_count: 1
                remaining_count: 5
                customer_notify: 1
                start_at: 1580453311
                end_at: null
                charge_at: null
                created_at: 1580453311
        '400':
          description: >-
            Bad request. The subscription may already be cancelled or in a
            non-cancellable state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized. Invalid or missing API credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Subscription not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    CancelSubscriptionRequest:
      type: object
      properties:
        cancel_at_cycle_end:
          type: integer
          description: >-
            Set to `1` to cancel the subscription at the end of the current
            billing cycle. Set to `0` to cancel immediately.
          enum:
            - 0
            - 1
          example: 0
    Subscription:
      type: object
      description: A Razorpay Subscription object.
      properties:
        id:
          type: string
          description: Unique identifier of the subscription.
          example: sub_00000000000001
        entity:
          type: string
          description: Entity type. Always `subscription`.
          example: subscription
        plan_id:
          type: string
          description: Unique identifier of the plan associated with this subscription.
          example: plan_00000000000001
        status:
          type: string
          description: Current status of the subscription.
          enum:
            - created
            - authenticated
            - active
            - pending
            - halted
            - cancelled
            - completed
            - expired
          example: created
        total_count:
          type: integer
          description: Total number of billing cycles in the subscription.
          example: 6
        paid_count:
          type: integer
          description: Number of billing cycles that have been successfully paid.
          example: 0
        remaining_count:
          type: integer
          description: Number of billing cycles remaining.
          example: 6
        customer_notify:
          type: integer
          description: >-
            Indicates whether the customer should be notified. `1` for yes, `0`
            for no.
          enum:
            - 0
            - 1
          example: 1
        start_at:
          type: integer
          description: Unix timestamp at which the subscription starts billing.
          example: 1580453311
          nullable: true
        end_at:
          type: integer
          description: Unix timestamp at which the subscription ends.
          example: null
          nullable: true
        charge_at:
          type: integer
          description: Unix timestamp of the next scheduled charge.
          example: 1580453311
          nullable: true
        created_at:
          type: integer
          description: Unix timestamp at which the subscription was created.
          example: 1580453311
    ErrorResponse:
      type: object
      description: Standard error response from the Razorpay API.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Error code.
              example: BAD_REQUEST_ERROR
            description:
              type: string
              description: Human-readable description of the error.
              example: The amount must be greater than 0.
            field:
              type: string
              description: The field that caused the error, if applicable.
              example: amount
              nullable: true
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Use your Razorpay Key ID as the username and Key Secret as the password.

````