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

# Create Checkout Session

> This endpoint creates a Stripe checkout session for purchasing credits.

## POST /credits/checkout

This endpoint creates a Stripe checkout session to allow a user to purchase a credit package. Requires session-based authentication (JWT access token from login).

<Note>
  **For third-party integrations:** Use `POST /credits/checkout/api` with API Key authentication instead.
</Note>

### Request Body

<ParamField body="packageId" type="string" required>
  The ID of the credit package to purchase. Get available packages from `/credits/packages`.
</ParamField>

<ParamField body="successUrl" type="string">
  The URL to redirect to after a successful purchase. Defaults to dashboard with success indicator.
</ParamField>

<ParamField body="cancelUrl" type="string">
  The URL to redirect to if the purchase is canceled. Defaults to dashboard with canceled indicator.
</ParamField>

### Response

<ResponseField name="sessionId" type="string">
  The ID of the Stripe checkout session.
</ResponseField>

<ResponseField name="url" type="string">
  The URL of the Stripe checkout page. Redirect the user here to complete purchase.
</ResponseField>

<ResponseField name="package" type="object">
  Details of the selected package.

  <Expandable title="package properties">
    <ResponseField name="id" type="string">
      Package identifier.
    </ResponseField>

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

    <ResponseField name="credits" type="number">
      Number of credits in the package.
    </ResponseField>

    <ResponseField name="priceCents" type="number">
      Price in cents.
    </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 Success (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 Package Not Found (404) theme={null}
  {
    "message": "Credit package not found"
  }
  ```
</ResponseExample>

***

## POST /credits/checkout/api

This endpoint creates a Stripe checkout session using API Key authentication. Ideal for third-party integrations and external applications.

### Authentication

Requires API Key authentication. Include your API key in the `Authorization` header:

```
Authorization: Bearer llmgen_your_api_key_here
```

### Request Body

Same as `/credits/checkout` above.

### Response

Same as `/credits/checkout` above.

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