# Cancel a subscription (immediately or at period end)

`POST /api/v1/subscriptions/{id}/cancel`

With `at_period_end: true` the subscription becomes `non_renewing` and keeps access until `effective_at`; the renewal sweep expires it there. Otherwise it is canceled immediately.

Needs the `subscriptions:write` scope, or a full-access key.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | required |  |

## Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | optional | A unique value for this operation, chosen by you. A retry with the same key and the same body returns the first response instead of running again. The same key with a different body answers 409 `idempotency_key_reused`; a key whose first request is still running answers 409 `idempotency_in_progress`. |

## Request body

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "at_period_end": {
      "type": "boolean",
      "description": "true keeps access until the paid period ends (status `non_renewing`); the renewal sweep then expires it. Default false = immediate."
    },
    "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500
    }
  }
}
```

## Responses

### 200

Subscription canceled or scheduled to cancel.

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "subscription_id": {
          "type": "string",
          "format": "uuid",
          "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
        },
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        },
        "cancel_at_period_end": {
          "type": "boolean"
        },
        "effective_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "subscription_id",
        "from",
        "to"
      ]
    },
    "_agent": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok"
          ]
        },
        "next_actions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "summary",
        "status",
        "next_actions",
        "warnings"
      ]
    },
    "api_version": {
      "type": "string",
      "example": "2026-07-01"
    }
  },
  "required": [
    "data",
    "_agent",
    "api_version"
  ]
}
```
