> ## 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.

# 청구 포털 세션 생성

> 구독과 결제 수단 관리용 Stripe 고객 포털 세션을 만듭니다.

## 개요

사용자가 다음을 할 수 있는 Stripe Customer Portal 세션을 만듭니다:

* 결제 수단 갱신
* 청구 내역 조회
* 구독 플랜 변경
* 인보이스 다운로드
* 구독 취소

세션 기반 인증(JWT 액세스 토큰)이 필요합니다.

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

## 인증

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

## 요청 본문

<ParamField body="returnUrl" type="string">
  사용자가 포털을 나왔을 때 돌아갈 URL입니다. 기본값은 앱 대시보드입니다.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/portal \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "returnUrl": "https://yourapp.com/settings/billing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/portal', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      returnUrl: 'https://yourapp.com/settings/billing'
    })
  });

  const data = await response.json();
  // Redirect user to Stripe portal
  window.location.href = data.url;
  ```

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/portal',
      headers={
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'returnUrl': 'https://yourapp.com/settings/billing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "url": "https://billing.stripe.com/p/session/test_a1b2c3d4..."
  }
  ```
</ResponseExample>

## 응답 필드

<ResponseField name="url" type="string">
  사용자를 보낼 URL입니다. Stripe에서 호스트하는 청구 포털입니다.
</ResponseField>

## 포털 기능

Stripe Customer Portal에서 사용자가 할 수 있는 작업은 다음과 같습니다:

| 기능        | 설명                 |
| --------- | ------------------ |
| **결제 수단** | 카드 추가·수정·삭제        |
| **인보이스**  | 과거 인보이스 조회 및 다운로드  |
| **플랜 변경** | 구독 업그레이드 또는 다운그레이드 |
| **구독 취소** | 구독 해지              |
| **청구 기록** | 과거 거래 조회           |

## 오류 응답

<ResponseField name="400">
  잘못된 요청 — 청구 계정이 없습니다. 먼저 결제가 있어야 합니다.
</ResponseField>

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

<Note>
  청구 포털은 이전에 구매했거나 활성 구독이 있는 사용자에게만 제공됩니다. 신규 사용자는 Checkout 엔드포인트를 사용하세요.
</Note>

***

## POST /subscriptions/portal/api

API 키 인증으로 Stripe Customer Portal 세션을 생성합니다. 서드파티 연동에 적합합니다.

### 인증

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### 요청 본문

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

### 응답

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

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/portal/api \
    -H "Authorization: Bearer llmgen_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "returnUrl": "https://yourapp.com/settings/billing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/portal/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      returnUrl: 'https://yourapp.com/settings/billing'
    })
  });

  const data = await response.json();
  // Redirect user to Stripe portal
  window.location.href = data.url;
  ```

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/portal/api',
      headers={
          'Authorization': 'Bearer llmgen_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'returnUrl': 'https://yourapp.com/settings/billing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>

## 권장 사항

* **설정에 링크**: 앱 설정에「청구 관리」버튼을 둡니다
* **결제 직후**: 구독 구매 후 포털로 안내합니다
* **지원**: 청구 관련 문의는 셀프서비스로 포털을 제공합니다
