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

# POST /credit-card-validator

> Validate credit card numbers using the Luhn algorithm and identify card network and type.

## Endpoint

```
POST https://api.bunny.build/api/v1/credit-card-validator
```

## Authentication

| Header         | Required | Value                    |
| -------------- | -------- | ------------------------ |
| `X-API-Key`    | Yes      | Your API key (`bun_...`) |
| `Content-Type` | Yes      | `application/json`       |

## Overview

Validate credit and debit card numbers using the Luhn algorithm and identify the card network (Visa, Mastercard, Amex, etc.) and card type. Use this API to provide instant feedback on payment forms before processing a charge, reducing failed transactions and improving checkout UX.

## Use cases

* Validate card numbers client-side before calling your payment gateway
* Display the correct card network logo in checkout forms
* Reduce fraud by catching obviously invalid numbers early
* Enforce card type restrictions (e.g. credit only, no prepaid)

## Details

Accepts card numbers with or without spaces and dashes. Validation uses the Luhn algorithm; it confirms the number is structurally valid, not that the account exists or has funds. Never log or store raw card numbers.

## Request body

| Field    | Type   | Required | Description                                        |
| -------- | ------ | -------- | -------------------------------------------------- |
| `number` | string | Yes      | Credit card number (spaces and dashes are ignored) |

### Example

```json theme={null}
{
  "number": "4111 1111 1111 1111"
}
```

## Response

### 200 OK

| Field          | Type    | Description                                                                                             |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------- |
| `valid`        | boolean | `true` if both Luhn check and length are valid                                                          |
| `luhn_valid`   | boolean | Whether the number passes the Luhn algorithm                                                            |
| `length_valid` | boolean | Whether the digit count matches the expected length for the detected brand                              |
| `brand`        | string  | Card brand: `Visa`, `Mastercard`, `Amex`, `Discover`, `Diners`, `JCB`, `Elo`, `Hipercard`, or `Unknown` |
| `digits`       | number  | Number of digits in the card number                                                                     |
| `masked`       | string  | Card number with middle digits replaced by asterisks (e.g. `4111 **** **** 1111`)                       |

**Example**

```json theme={null}
{
  "valid": true,
  "luhn_valid": true,
  "length_valid": true,
  "brand": "Visa",
  "digits": 16,
  "masked": "4111 **** **** 1111"
}
```

### 401 Unauthorized

```json theme={null}
{
  "detail": "Missing API key. Include X-API-Key header."
}
```

### 402 Payment Required

```json theme={null}
{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}
```

### 422 Unprocessable Entity

```json theme={null}
{
  "detail": "Missing required field: number"
}
```

### 429 Too Many Requests

```json theme={null}
{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}
```

## cURL example

```bash theme={null}
curl -X POST https://api.bunny.build/api/v1/credit-card-validator \
  -H "X-API-Key: bun_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"number": "4111111111111111"}'
```
