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

# Checkout-Sitzung erstellen

> Dieser Endpunkt erstellt eine Stripe-Checkout-Sitzung zum Kauf von Credits.

## POST /credits/checkout

Dieser Endpunkt erstellt eine Stripe-Checkout-Sitzung zum Kauf eines Credit-Pakets. Erfordert Sitzungsauthentifizierung (JWT-Access-Token nach Login).

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

### Anfragetext

<ParamField body="packageId" type="string" required>
  Kennung des zu kaufenden Credit-Pakets. Verfügbare Pakete über `/credits/packages`.
</ParamField>

<ParamField body="successUrl" type="string">
  URL nach erfolgreichem Kauf. Standard: Dashboard mit Erfolgsanzeige.
</ParamField>

<ParamField body="cancelUrl" type="string">
  URL bei Abbruch des Kaufs. Standard: Dashboard mit Abbruchanzeige.
</ParamField>

### Antwort

<ResponseField name="sessionId" type="string">
  Kennung der Stripe-Checkout-Sitzung.
</ResponseField>

<ResponseField name="url" type="string">
  URL der Stripe-Checkout-Seite. Nutzer zur Zahlungsabschluss dorthin weiterleiten.
</ResponseField>

<ResponseField name="package" type="object">
  Details des gewählten Pakets.

  <Expandable title="Eigenschaften von package">
    <ResponseField name="id" type="string">
      Paketkennung.
    </ResponseField>

    <ResponseField name="name" type="string">
      Paketname.
    </ResponseField>

    <ResponseField name="credits" type="number">
      Anzahl Credits im Paket.
    </ResponseField>

    <ResponseField name="priceCents" type="number">
      Preis in Cent.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/credits/checkout \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
          "packageId": "pkg_pro",
          "successUrl": "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
          "cancelUrl": "https://example.com/cancel"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/checkout', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      packageId: 'pkg_pro'
    })
  });

  const data = await response.json();
  // Redirect user to data.url
  window.location.href = data.url;
  ```
</RequestExample>

<ResponseExample>
  ```json Erfolg (200) theme={null}
  {
    "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
    "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4e5f6g7h8i9j0",
    "package": {
      "id": "pkg_pro",
      "name": "Pro Pack",
      "credits": 500,
      "priceCents": 1999
    }
  }
  ```

  ```json Paket nicht gefunden (404) theme={null}
  {
    "message": "Credit package not found"
  }
  ```
</ResponseExample>

***

## POST /credits/checkout/api

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

### Authentifizierung

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### Anfragetext

Wie bei `/credits/checkout` oben.

### Antwort

Wie bei `/credits/checkout` oben.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/credits/checkout/api \
    -H "Authorization: Bearer llmgen_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
          "packageId": "pkg_pro",
          "successUrl": "https://yourapp.com/success?session_id={CHECKOUT_SESSION_ID}",
          "cancelUrl": "https://yourapp.com/cancel"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/checkout/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      packageId: 'pkg_pro',
      successUrl: 'https://yourapp.com/success?session_id={CHECKOUT_SESSION_ID}',
      cancelUrl: 'https://yourapp.com/cancel'
    })
  });

  const data = await response.json();
  // Redirect user to data.url in your app
  ```

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/credits/checkout/api',
      headers={
          'Authorization': 'Bearer llmgen_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'packageId': 'pkg_pro',
          'successUrl': 'https://yourapp.com/success',
          'cancelUrl': 'https://yourapp.com/cancel'
      }
  )

  data = response.json()
  ```
</RequestExample>
