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

# Abonnement-Checkout erstellen

> Stripe-Checkout-Sitzung zum Abschluss eines Abonnements erstellen.

## Überblick

Erstellt eine Stripe-Checkout-Sitzung für ein Abonnement und liefert eine URL, zu der Sie den Nutzer zur Zahlung weiterleiten. Erfordert Sitzungsauthentifizierung (JWT-Access-Token).

<Note>
  **Für Drittanbieter-Integrationen:** Verwenden Sie `POST /subscriptions/checkout/api` mit API-Schlüssel-Authentifizierung.
</Note>

## Authentifizierung

<ParamField header="Authorization" type="string" required>
  JWT-Access-Token. Format: `Bearer YOUR_ACCESS_TOKEN`
</ParamField>

## Anfragetext

<ParamField body="planId" type="string" required>
  Tarifkennung: einer von `starter`, `professional`, `business` oder `agency`.
</ParamField>

<ParamField body="billingCycle" type="string" default="monthly">
  Abrechnungsintervall: `monthly` oder `yearly`.
</ParamField>

<ParamField body="successUrl" type="string">
  URL nach erfolgreicher Zahlung. Standard: App-Dashboard.
</ParamField>

<ParamField body="cancelUrl" type="string">
  URL bei Abbruch der Zahlung. Standard: Preisseite.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/checkout \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "planId": "professional",
      "successUrl": "https://yourapp.com/subscription/success",
      "cancelUrl": "https://yourapp.com/pricing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/checkout', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      planId: 'professional',
      successUrl: 'https://yourapp.com/subscription/success',
      cancelUrl: 'https://yourapp.com/pricing'
    })
  });

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

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/checkout',
      headers={
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'planId': 'professional',
          'successUrl': 'https://yourapp.com/subscription/success',
          'cancelUrl': 'https://yourapp.com/pricing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>

<ResponseExample>
  ```json Antwort theme={null}
  {
    "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
    "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4...",
    "plan": {
      "id": "professional",
      "name": "Professional",
      "monthlyCredits": 3000,
      "priceCents": 1299
    }
  }
  ```
</ResponseExample>

## Antwortfelder

<ResponseField name="sessionId" type="string">
  Stripe-Checkout-Sitzungs-ID. Später zur Verifikation nutzbar.
</ResponseField>

<ResponseField name="url" type="string">
  URL zur Zahlung. Stripe-gehostete Checkout-Seite.
</ResponseField>

<ResponseField name="plan" type="object">
  Details des gewählten Tarifs.
</ResponseField>

## Checkout-Ablauf

1. **Sitzung erstellen**: Endpunkt mit gewünschtem Tarif aufrufen
2. **Nutzer weiterleiten**: Zu der zurückgegebenen `url` navigieren
3. **Zahlung**: Nutzer schließt bei Stripe ab
4. **Webhook**: Stripe benachrichtigt Ihren Webhook-Endpunkt
5. **Erfolgs-Redirect**: Nutzer wird zu `successUrl` geleitet
6. **Optional prüfen**: Status über `/subscriptions/current`

## Fehlerantworten

<ResponseField name="400">
  Ungültige Anfrage – Ungültige Tarif-ID oder Nutzer hat bereits ein aktives Abonnement.
</ResponseField>

<ResponseField name="401">
  Nicht autorisiert – Ungültiges oder fehlendes Token.
</ResponseField>

<Note>
  Hat der Nutzer bereits ein aktives Abonnement, sollte der Tarifwechsel über das Abrechnungsportal (`/subscriptions/portal`) erfolgen.
</Note>

***

## POST /subscriptions/checkout/api

Erstellt eine Stripe-Checkout-Sitzung mit API-Schlüssel-Authentifizierung. Geeignet für Drittanbieter-Integrationen.

### Authentifizierung

API-Schlüssel erforderlich. Übergeben Sie ihn im Header `Authorization`:

```
Authorization: Bearer llmgen_your_api_key_here
```

### Anfragetext

Wie bei `/subscriptions/checkout` oben.

### Antwort

Wie bei `/subscriptions/checkout` oben.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/checkout/api \
    -H "Authorization: Bearer llmgen_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "planId": "professional",
      "successUrl": "https://yourapp.com/subscription/success",
      "cancelUrl": "https://yourapp.com/pricing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/checkout/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      planId: 'professional',
      successUrl: 'https://yourapp.com/subscription/success',
      cancelUrl: 'https://yourapp.com/pricing'
    })
  });

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

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/checkout/api',
      headers={
          'Authorization': 'Bearer llmgen_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'planId': 'professional',
          'successUrl': 'https://yourapp.com/subscription/success',
          'cancelUrl': 'https://yourapp.com/pricing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>
