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

# Criar sessão de checkout

> Este endpoint cria uma sessão Stripe Checkout para compra de créditos.

## POST /credits/checkout

Este endpoint cria uma sessão Stripe Checkout para o usuário adquirir um pacote de créditos. Exige autenticação por sessão (JWT de acesso obtido no login).

<Note>
  **Para integrações de terceiros:** use `POST /credits/checkout/api` com autenticação por chave de API.
</Note>

### Corpo da requisição

<ParamField body="packageId" type="string" required>
  ID do pacote de créditos. Pacotes disponíveis em `/credits/packages`.
</ParamField>

<ParamField body="successUrl" type="string">
  URL para redirecionar após compra bem-sucedida. Por padrão, o dashboard com indicador de sucesso.
</ParamField>

<ParamField body="cancelUrl" type="string">
  URL caso o usuário cancele a compra. Por padrão, o dashboard com indicador de cancelamento.
</ParamField>

### Resposta

<ResponseField name="sessionId" type="string">
  ID da sessão Stripe Checkout.
</ResponseField>

<ResponseField name="url" type="string">
  URL da página Stripe Checkout. Redirecione o usuário para concluir a compra.
</ResponseField>

<ResponseField name="package" type="object">
  Detalhes do pacote selecionado.

  <Expandable title="Propriedades do pacote">
    <ResponseField name="id" type="string">
      Identificador do pacote.
    </ResponseField>

    <ResponseField name="name" type="string">
      Nome do pacote.
    </ResponseField>

    <ResponseField name="credits" type="number">
      Quantidade de créditos no pacote.
    </ResponseField>

    <ResponseField name="priceCents" type="number">
      Preço em centavos.
    </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 Sucesso (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 Pacote não encontrado (404) theme={null}
  {
    "message": "Credit package not found"
  }
  ```
</ResponseExample>

***

## POST /credits/checkout/api

Este endpoint cria uma sessão Stripe Checkout com autenticação por chave de API. Indicado para integrações externas.

### Autenticação

Inclua sua chave no cabeçalho `Authorization`:

```
Authorization: Bearer llmgen_your_api_key_here
```

### Corpo da requisição

Igual ao de `/credits/checkout`, acima.

### Resposta

Igual ao de `/credits/checkout`, acima.

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