Skip to main content

Endpoint

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

Authentication

HeaderRequiredValue
X-API-KeyYesYour API key (bun_...)
Content-TypeYesapplication/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

FieldTypeRequiredDescription
numberstringYesCredit card number (spaces and dashes are ignored)

Example

{
  "number": "4111 1111 1111 1111"
}

Response

200 OK

FieldTypeDescription
validbooleantrue if both Luhn check and length are valid
luhn_validbooleanWhether the number passes the Luhn algorithm
length_validbooleanWhether the digit count matches the expected length for the detected brand
brandstringCard brand: Visa, Mastercard, Amex, Discover, Diners, JCB, Elo, Hipercard, or Unknown
digitsnumberNumber of digits in the card number
maskedstringCard number with middle digits replaced by asterisks (e.g. 4111 **** **** 1111)
Example
{
  "valid": true,
  "luhn_valid": true,
  "length_valid": true,
  "brand": "Visa",
  "digits": 16,
  "masked": "4111 **** **** 1111"
}

401 Unauthorized

{
  "detail": "Missing API key. Include X-API-Key header."
}

402 Payment Required

{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}

422 Unprocessable Entity

{
  "detail": "Missing required field: number"
}

429 Too Many Requests

{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}

cURL example

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"}'