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

# Verify Checkout Session

> Verify a completed checkout session and ensure credits have been added.

## Overview

After a successful checkout, use this endpoint to verify the payment was processed and credits were added to the account. This is useful as a fallback in case the webhook wasn't processed.

<Note>
  Credits are typically added automatically via Stripe webhooks. This endpoint provides a manual verification option for edge cases or client-side confirmation.
</Note>

<Note>
  **For third-party integrations:** Use `GET /credits/verify-session/{sessionId}/api` with API Key authentication instead.
</Note>

## Authentication

<ParamField header="Authorization" type="string" required>
  Your JWT access token (session auth). Format: `Bearer YOUR_ACCESS_TOKEN`
</ParamField>

## Path Parameters

<ParamField path="sessionId" type="string" required>
  The Stripe checkout session ID returned from `/credits/checkout`.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/verify-session/cs_test_a1b2c3d4e5f6 \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```javascript JavaScript theme={null}
  const sessionId = 'cs_test_a1b2c3d4e5f6';
  const response = await fetch(
    `https://api.llmgenerator.com/api/v1/credits/verify-session/${sessionId}`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
      }
    }
  );

  const data = await response.json();
  if (data.success) {
    console.log(`Added ${data.credits} credits`);
  }
  ```

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

  session_id = 'cs_test_a1b2c3d4e5f6'
  response = requests.get(
      f'https://api.llmgenerator.com/api/v1/credits/verify-session/{session_id}',
      headers={'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
  )
  data = response.json()
  print(f"Verified: {data['credits']} credits")
  ```
</RequestExample>

<ResponseExample>
  ```json Success theme={null}
  {
    "success": true,
    "credits": 500,
    "sessionId": "cs_test_a1b2c3d4e5f6"
  }
  ```

  ```json Payment Not Completed theme={null}
  {
    "success": false,
    "message": "Payment not completed"
  }
  ```
</ResponseExample>

## Response Fields

<ResponseField name="success" type="boolean">
  Whether the session verification was successful.
</ResponseField>

<ResponseField name="credits" type="integer">
  Number of credits from the purchase.
</ResponseField>

<ResponseField name="sessionId" type="string">
  The verified session ID.
</ResponseField>

## Error Responses

<ResponseField name="400">
  Bad Request - Payment not completed or invalid session metadata.
</ResponseField>

<ResponseField name="401">
  Unauthorized - Invalid or missing token.
</ResponseField>

<ResponseField name="403">
  Forbidden - Session does not belong to the authenticated user.
</ResponseField>

## Idempotency

This endpoint is idempotent. If the credits were already added (via webhook), it will not add them again. It will still return success with the credit amount.

## Typical Flow

1. User completes checkout at Stripe
2. Stripe redirects to your `successUrl`
3. Call this endpoint to verify and confirm credits
4. Display confirmation to user
5. Refresh credit balance in your UI

<Tip>
  While this endpoint is available, the recommended flow is to listen for Stripe webhooks and update your UI based on the `/credits/balance` endpoint.
</Tip>

***

## GET /credits/verify-session/{sessionId}/api

This endpoint verifies a checkout session using API Key authentication. Ideal for third-party integrations.

### Authentication

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### Path Parameters

Same as above.

### Response

Same as above.

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/verify-session/cs_test_a1b2c3d4e5f6/api \
    -H "Authorization: Bearer llmgen_your_api_key_here"
  ```

  ```javascript JavaScript theme={null}
  const sessionId = 'cs_test_a1b2c3d4e5f6';
  const response = await fetch(
    `https://api.llmgenerator.com/api/v1/credits/verify-session/${sessionId}/api`,
    {
      headers: {
        'Authorization': 'Bearer llmgen_your_api_key_here'
      }
    }
  );

  const data = await response.json();
  if (data.success) {
    console.log(`Added ${data.credits} credits`);
  }
  ```

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

  session_id = 'cs_test_a1b2c3d4e5f6'
  response = requests.get(
      f'https://api.llmgenerator.com/api/v1/credits/verify-session/{session_id}/api',
      headers={'Authorization': 'Bearer llmgen_your_api_key_here'}
  )
  data = response.json()
  print(f"Verified: {data['credits']} credits")
  ```
</RequestExample>
