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

# Cancel a subscription item

> End one recurring add-on on a customer's subscription, at the period end or now, with no refund.

Cancels one recurring add-on (a plan with `addOn: true`) on the customer's subscription. The base plan and any other add-ons are untouched.

* `timing: "period_end"` (the default): the item becomes `canceling`, with `endsAt` at the period end. Its features and credits last until then, and the renewal bills the subscription without it, with no proration. The item then ends.
* `timing: "immediately"`: the item ends now, and its credits and features end with it. Stripe stops billing it from now on, and nothing is refunded or credited.
* `itemId` is an `id` from the subscription's `items` in [List customer subscriptions](https://docs.integrateledger.com/api-reference/customers/subscriptions.md); `customerId` goes in the query string.
* Send an `Idempotency-Key` header, and reuse it on every retry of the same cancellation. Without one the request is refused with `400 idempotency_key_required`.
* The base plan's item is refused with `400 item_not_cancellable`: stop its renewal with [Stop or resume renewal](https://docs.integrateledger.com/api-reference/customers/cancellation.md), which ends the whole subscription.
* An item that already ended is `409 item_ended`. A change on the subscription still waiting on payment is `409 subscription_change_pending`, and a downgrade scheduled for the period end is `409 downgrade_scheduled`: cancel the downgrade first. While an add-on is canceling, attaching another add-on, upgrading or downgrading is `409 subscription_change_pending` until the renewal.
* Cancelling an add-on that is already canceling at the period end returns that cancellation.

Needs the **Billing** permission.

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/subscription-items/7/cancellation?customerId=user_123" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Idempotency-Key: cancel_sso_123" \
  -H "Content-Type: application/json" \
  -d '{"timing": "period_end"}'
```

```typescript TypeScript theme={"system"}
import ledger from "integrateledger";

const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });

const cancelled = await client.cancelSubscriptionItem({
  itemId: 7,
  customerId: "user_123",
  idempotencyKey: "cancel_sso_123",
  body: { timing: "period_end" },
});
console.log(cancelled.item.status);
```

```python Python theme={"system"}
import os
from integrateledger import ledger

client = ledger(api_key=os.environ["LEDGER_API_KEY"])

cancelled = client.cancel_subscription_item(
    customer_id="user_123", item_id=7, timing="period_end", idempotency_key="cancel_sso_123"
)
print(cancelled["item"]["status"])
```

```json 200 theme={"system"}
{
  "itemChangeId": 12,
  "timing": "period_end",
  "status": "scheduled",
  "item": {
    "id": 7,
    "planId": "sso_addon",
    "kind": "add_on",
    "group": "default",
    "quantity": 1,
    "status": "canceling",
    "endsAt": "2026-12-07T07:40:38.000Z"
  }
}
```

```json 400 theme={"system"}
{
  "error": "item_not_cancellable"
}
```


## OpenAPI

````yaml openapi.json POST /v1/customers/subscription-items/{itemId}/cancellation
openapi: 3.1.0
info:
  title: Ledger API
  version: 0.1.0
servers:
  - url: https://api.integrateledger.com
    description: Hosted Ledger API
security: []
paths:
  /v1/customers/subscription-items/{itemId}/cancellation:
    post:
      tags:
        - Customers
      summary: Cancel one add-on on a subscription
      description: 'timing: "immediately" ends it now, with no refund.'
      operationId: cancelSubscriptionItem
      parameters:
        - schema:
            type: integer
            exclusiveMinimum: 0
            maximum: 2147483647
            description: >-
              The item's `id` from the subscription's `items` in List customer
              subscriptions.
          required: true
          description: >-
            The item's `id` from the subscription's `items` in List customer
            subscriptions.
          name: itemId
          in: path
        - schema:
            type: string
            minLength: 1
            maxLength: 255
            description: Your ID for the customer, such as your user ID.
          required: true
          description: Your ID for the customer, such as your user ID.
          name: customerId
          in: query
        - schema:
            type: string
            maxLength: 255
            description: >-
              Required: identifies this one cancellation. Reuse it on every
              retry; a key lasts 24 hours.
          required: false
          description: >-
            Required: identifies this one cancellation. Reuse it on every retry;
            a key lasts 24 hours.
          name: idempotency-key
          in: header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelSubscriptionItemInput'
      responses:
        '200':
          description: The cancellation, and the item as it stands now
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelSubscriptionItemResponse'
        '400':
          description: >-
            Invalid request, no Idempotency-Key (idempotency_key_required), a
            base plan's item (item_not_cancellable), or a Stripe subscription
            Ledger can't change (ineligible_stripe_subscription)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '401':
          description: Missing or invalid Ledger API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '403':
          $ref: '#/components/responses/InsufficientPermissions'
        '404':
          description: >-
            Unknown customer (customer_not_found), or no such item for this
            customer (item_not_found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '409':
          description: >-
            The item already ended (item_ended), another change on the bill is
            waiting on payment or Stripe (subscription_change_pending), a
            downgrade is scheduled for the period end (downgrade_scheduled), the
            whole subscription is set to cancel (cancellation_scheduled), the
            key was used for another change (idempotency_key_mismatch), or
            Stripe holds something other than Ledger's record
            (stripe_plan_mismatch)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: >-
            No Stripe connection (stripe_not_configured), or Stripe unavailable
            or refused the change (stripe_item_change_failed; retry with the
            same key)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '503':
          description: >-
            The cancellation needs another pass with Stripe
            (item_change_reconciliation_required); retry with the same key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
                    description: >-
                      What went wrong and what to do about it, for a person or
                      an agent to read. Every Ledger error has one. The wording
                      can change: branch on `error`, not on this text.
                    example: >-
                      No customer "user_123" exists in this environment. Create
                      it with POST /v1/customers, or check that the API key is
                      for the right environment.
                  itemChangeId:
                    type: integer
                required:
                  - error
      security:
        - ApiKey: []
      x-codeSamples:
        - lang: python
          label: Python SDK
          source: >-
            import os

            from integrateledger import ledger


            client = ledger(api_key=os.environ["LEDGER_API_KEY"])

            client.cancel_subscription_item(customer_id="user_123", item_id=7,
            timing="period_end", idempotency_key="cancel_sso_123")
        - lang: bash
          label: cURL
          source: >-
            curl --request POST
            'https://api.integrateledger.com/v1/customers/subscription-items/{itemId}/cancellation?customerId=user_123'
            \
              -H "Authorization: Bearer $LEDGER_API_KEY" \
              -H 'Idempotency-Key: cancel_sso_123' \
              -H 'Content-Type: application/json' \
              --data '{"timing":"period_end"}'
        - lang: typescript
          label: TypeScript SDK
          source: >-
            import ledger from "integrateledger";


            const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? ""
            });

            await client.cancelSubscriptionItem({ itemId: 7, customerId:
            "user_123", idempotencyKey: "cancel_sso_123", body: { timing:
            "period_end" } });
components:
  schemas:
    CancelSubscriptionItemInput:
      type: object
      properties:
        timing:
          type: string
          enum:
            - period_end
            - immediately
          description: >-
            period_end (the default): the add-on and its features and credits
            stay until the bill's period end, and the renewal bills without it.
            immediately: it ends now, its credits and features with it, and
            nothing is refunded or credited.
      additionalProperties: false
    CancelSubscriptionItemResponse:
      type: object
      properties:
        itemChangeId:
          type: integer
        timing:
          type: string
          enum:
            - period_end
            - immediately
        status:
          type: string
          enum:
            - applied
            - scheduled
            - closed
          description: >-
            applied: the add-on ended now. scheduled: it ends at the period end.
            closed: Stripe refused the change and nothing changed.
        item:
          $ref: '#/components/schemas/CustomerBillItem'
      required:
        - itemChangeId
        - timing
        - status
        - item
    CustomerError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        issues:
          type: array
          items:
            type: object
            properties:
              path:
                type: string
              message:
                type: string
            required:
              - path
              - message
          description: >-
            With `invalid_request`: each field that failed validation and why.
            `path` is empty for the body itself, such as an unknown field.
      required:
        - error
    CustomerBillItem:
      type: object
      properties:
        id:
          type: integer
          description: The item's ID, which Cancel a subscription item takes.
        planId:
          type: string
          description: The plan's public ID.
        kind:
          $ref: '#/components/schemas/CustomerBillItemKind'
        group:
          type: string
          description: 'The plan''s group: default unless the catalog names one.'
        quantity:
          type: integer
          exclusiveMinimum: 0
          description: 'How many of the plan the item holds: 1 for a base plan.'
        status:
          $ref: '#/components/schemas/CustomerBillItemStatus'
        endsAt:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When a canceling item ends, or when an ended one ended. Null while
            it keeps renewing.
      required:
        - id
        - planId
        - kind
        - group
        - quantity
        - status
        - endsAt
    InsufficientPermissionsError:
      type: object
      properties:
        error:
          type: string
          example: insufficient_permissions
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        requiredScope:
          type: string
          example: customers:read
      required:
        - error
        - requiredScope
    PayloadTooLargeError:
      type: object
      properties:
        error:
          type: string
          example: payload_too_large
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
    RateLimitError:
      type: object
      properties:
        error:
          type: string
          example: rate_limited
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
    CustomerBillItemKind:
      type: string
      enum:
        - plan
        - add_on
        - license
      description: >-
        plan: a base plan. add_on: a recurring add-on beside it. license: seats
        of a seat plan.
    CustomerBillItemStatus:
      type: string
      enum:
        - pending
        - active
        - canceling
        - paused
        - ended
      description: >-
        pending: waiting on Checkout or on a change's payment. active: held.
        canceling: held until endsAt, then it ends. paused: held but not
        applying (a trial that went back). ended: no longer held.
  responses:
    InsufficientPermissions:
      description: >-
        The API key works but lacks the permission this endpoint needs, named in
        requiredScope. See the API keys guide.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/InsufficientPermissionsError'
    PayloadTooLarge:
      description: 'The request body is over the limit: 1 MiB, or 5 MiB for a webhook.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PayloadTooLargeError'
    RateLimited:
      description: >-
        Too many requests. Wait Retry-After seconds, then retry. See the rate
        limits guide.
      headers:
        Retry-After:
          description: Seconds until a request is allowed again
          schema:
            type: integer
        RateLimit-Limit:
          description: 'The burst: requests allowed at once'
          schema:
            type: integer
        RateLimit-Remaining:
          description: Requests left right now
          schema:
            type: integer
        RateLimit-Reset:
          description: Seconds until the full burst is back
          schema:
            type: integer
        RateLimit-Policy:
          description: >-
            The sustained rate per second and the burst, such as
            200;w=1;burst=1000
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer

````

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