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

# Abrechnungsportal-Sitzung erstellen

> Stripe-Kundenportal-Sitzung für Abonnement- und Zahlungsmittelverwaltung erstellen.

## Überblick

Erstellt eine Stripe-Customer-Portal-Sitzung. Nutzer können dort:

* Zahlungsmittel aktualisieren
* Rechnungshistorie einsehen
* Abonnementtarife wechseln
* Rechnungen herunterladen
* Das Abonnement kündigen

Erfordert Sitzungsauthentifizierung (JWT-Access-Token).

<Note>
  **Für Drittanbieter-Integrationen:** Verwenden Sie `POST /subscriptions/portal/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="returnUrl" type="string">
  URL nach Verlassen des Portals. Standard: App-Dashboard.
</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 Antwort theme={null}
  {
    "url": "https://billing.stripe.com/p/session/test_a1b2c3d4..."
  }
  ```
</ResponseExample>

## Antwortfelder

<ResponseField name="url" type="string">
  URL zum Stripe-gehosteten Abrechnungsportal.
</ResponseField>

## Portal-Funktionen

Im Stripe Customer Portal können Nutzer:

| Funktion                | Beschreibung                                     |
| ----------------------- | ------------------------------------------------ |
| **Zahlungsmittel**      | Karten hinzufügen, ändern oder entfernen         |
| **Rechnungen**          | Vergangene Rechnungen anzeigen und herunterladen |
| **Tarifwechsel**        | Abonnement upgraden oder downgraden              |
| **Kündigung**           | Abonnement beenden                               |
| **Abrechnungshistorie** | Alle Transaktionen einsehen                      |

## Fehlerantworten

<ResponseField name="400">
  Ungültige Anfrage – Kein Abrechnungskonto gefunden. Zuerst einen Kauf tätigen.
</ResponseField>

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

<Note>
  Das Abrechnungsportal steht Nutzern zur Verfügung, die bereits gekauft haben oder ein aktives Abonnement besitzen. Neue Nutzer sollten den Checkout-Endpunkt verwenden.
</Note>

***

## POST /subscriptions/portal/api

Erstellt eine Stripe-Customer-Portal-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/portal` oben.

### Antwort

Wie bei `/subscriptions/portal` oben.

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

## Bewährte Praktiken

* **Link in den Einstellungen**: Button „Abrechnung verwalten“ in den Kontoeinstellungen
* **Nach dem Checkout**: Nach Abonnementabschluss Zugang zum Portal anbieten
* **Support**: Portal als Self-Service für Abrechnungsfragen bereitstellen
