> ## Documentation Index
> Fetch the complete documentation index at: https://docs.littledemo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Purchase a credit pack

Development implementation directly adds credits. Production checkout can use the same response shape after payment confirmation.

` POST /api/v1/credits/purchase `

Purchase a credit pack

Development implementation directly adds credits. Production checkout can use the same response shape after payment confirmation.

## Servers

- ` https://littledemo.com ` — Production

## Authentication

The operation accepts these alternatives. Schemes within one alternative are required together.

### Alternative 1

- ` bearerAuth `: ` http `

  - HTTP scheme: ` bearer `

  - Live API key, for example `Authorization: Bearer ld_live_...`.

### Alternative 2

- ` cookieAuth `: ` apiKey `

  - Credential: ` better-auth.session_token ` in ` cookie `

  - Dashboard session cookie.

## Request body (optional)

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` packId `

  - ` packId `: type ` string ` — Credit pack ID

    - enum: ` ["5","20","50","100"] `

## Responses

### ` 200 ` — Credits added

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` success `, ` creditsAdded `, ` balance `, ` transactionId `, ` pack `

  - ` success `: type ` boolean `

    - enum: ` [true] `

  - ` creditsAdded `: type ` number `

  - ` balance `: type ` number `

  - ` transactionId `: type ` string `

  - ` pack `: type ` object `

    - Required fields: ` id `, ` credits `, ` price `, ` perCredit `, ` savings `, ` label `

    - ` id `: type ` string `

      - enum: ` ["5","20","50","100"] `

    - ` credits `: type ` number `

    - ` price `: type ` number `

    - ` perCredit `: type ` number `

    - ` savings `: type ` number `

    - ` label `: type ` string `

    - ` popular `: type ` boolean `

### ` 400 ` — Invalid pack

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` string `

### ` 401 ` — Unauthorized

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` string `

## Request examples

### cURL

```curl
curl -X POST 'https://littledemo.com/api/v1/credits/purchase' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "packId": "5"
}'
```

### JavaScript

```javascript
const response = await fetch('https://littledemo.com/api/v1/credits/purchase', {
  method: 'POST',
  headers: {
      "Authorization": "Bearer YOUR_API_TOKEN",
      "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "packId": "5"
  })
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN'
}

response = requests.post('https://littledemo.com/api/v1/credits/purchase', headers=headers, json={
  "packId": "5"
})
print(response.json())
```