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

# 구독 취소

> 현재 과금 기간 종료 시점에 구독을 취소하도록 예약합니다.

## 개요

구독을 취소합니다. 현재 과금 기간이 끝날 때까지는 구독이 유지되며, 이후에는 갱신되지 않습니다. 세션 기반 인증(JWT 액세스 토큰)이 필요합니다.

<Note>
  **서드파티 연동:** API 키 인증을 사용할 때는 대신 `POST /subscriptions/cancel/api`를 사용하세요.
</Note>

<Warning>
  이 작업은 기간 종료 시 취소를 예약합니다. 사용자는 `currentPeriodEnd`까지 이용할 수 있습니다. 즉시 해지하려면 청구 포털을 사용하세요.
</Warning>

## 인증

<ParamField header="Authorization" type="string" required>
  JWT 액세스 토큰입니다. 형식: `Bearer YOUR_ACCESS_TOKEN`
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/cancel \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/cancel', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
    }
  });

  const data = await response.json();
  if (data.success) {
    console.log('Subscription will end on:', data.cancellationDate);
  }
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/cancel',
      headers={'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
  )
  data = response.json()
  if data['success']:
      print(f"Subscription will end on: {data['cancellationDate']}")
  ```
</RequestExample>

<ResponseExample>
  ```json Success theme={null}
  {
    "success": true,
    "message": "Subscription cancelled successfully",
    "cancellationDate": "2024-02-15T00:00:00Z"
  }
  ```

  ```json No Active Subscription theme={null}
  {
    "message": "No active subscription to cancel"
  }
  ```
</ResponseExample>

## 응답 필드

<ResponseField name="success" type="boolean">
  취소 예약 성공 여부입니다.
</ResponseField>

<ResponseField name="message" type="string">
  사람이 읽을 수 있는 상태 메시지입니다.
</ResponseField>

<ResponseField name="cancellationDate" type="string">
  구독이 종료될 시각(ISO 8601, 성공 시에만)입니다.
</ResponseField>

## 오류 응답

<ResponseField name="400">
  잘못된 요청 — 취소할 활성 구독이 없거나 API로 취소할 수 없는 구독입니다.
</ResponseField>

<ResponseField name="401">
  인증 실패 — 토큰이 없거나 유효하지 않습니다.
</ResponseField>

## 취소 동작

| 시나리오            | 동작              |
| --------------- | --------------- |
| 활성 구독           | 기간 종료 시 취소로 표시됨 |
| 이미 취소됨          | 오류 반환           |
| 구독 없음           | 오류 반환           |
| Stripe 구독 ID 없음 | 오류(API로 취소 불가)  |

## 재활성화

사용자가 다시 이용하려면:

1. 청구 포털(`/subscriptions/portal`)을 사용하거나
2. 현재 구독이 끝난 뒤 새 구독을 만들 수 있습니다.

## 권장 사항

* **확인 대화 상자**: 취소 전 항상 확인을 받습니다
* **사유 수집**: 피드백을 위해 취소 사유를 묻습니다
* **이탈 방지**: 할인 또는 일시정지 옵션을 고려합니다
* **명확한 안내**: 서비스 이용 종료 시점을 사용자에게 표시합니다

***

## POST /subscriptions/cancel/api

API 키 인증으로 사용자 구독을 취소(기간 종료 예약)합니다. 서드파티 연동에 적합합니다.

### 인증

API 키 인증이 필요합니다. `Authorization` 헤더에 API 키를 넣습니다:

```
Authorization: Bearer llmgen_your_api_key_here
```

### 응답

`/subscriptions/cancel`와 동일합니다.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/cancel/api \
    -H "Authorization: Bearer llmgen_your_api_key_here"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/cancel/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here'
    }
  });

  const data = await response.json();
  if (data.success) {
    console.log('Subscription will end on:', data.cancellationDate);
  }
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/cancel/api',
      headers={'Authorization': 'Bearer llmgen_your_api_key_here'}
  )
  data = response.json()
  if data['success']:
      print(f"Subscription will end on: {data['cancellationDate']}")
  ```
</RequestExample>
