Error Codes

Complete reference of API error codes.

This page documents all error codes returned by the Bitrefill API.

Invoice Creation Errors

Errors when creating invoices via POST /invoices or POST /esims:

Error CodeDescriptionSolution
unsupported_payment_methodPayment method not supportedUse: balance, bitcoin, lightning, ethereum, etc.
missing_paramRequired parameter missingCheck the message for which parameter
parse_errorFailed to parse requestVerify JSON structure
not_foundProduct doesn't existVerify product ID is correct
out_of_stockProduct unavailableTry later or different product
invalid_paramParameter has wrong typeCheck the message for details
too_many_itemsMore than 20 itemsSplit into multiple invoices
create_invoice_failedInternal errorContact support if persistent
balance_too_lowInsufficient balanceAdd funds or use crypto

Examples

Missing parameter:

{
  "error_code": "missing_param",
  "message": "Missing required parameter: product_id"
}

Out of stock:

{
  "error_code": "out_of_stock",
  "message": "Product 'amazon-us' is currently out of stock"
}

Balance too low:

{
  "error_code": "balance_too_low",
  "message": "Insufficient balance. Required: $50.00, Available: $25.00"
}

Authentication Errors

HTTP CodeErrorSolution
401UnauthorizedVerify API key/credentials
403ForbiddenCheck account permissions

Common Causes

401 Unauthorized:

  • Wrong API key
  • Malformed Authorization header
  • Expired or revoked credentials
  • Using Bearer when Basic is required (or vice versa)

403 Forbidden:

  • Account doesn't have API access
  • Trying to access affiliate-only endpoints
  • Account suspended

Rate Limit Errors

HTTP CodeErrorSolution
429Too Many RequestsWait and retry

Response headers indicate limits:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1704067200

Wait until X-RateLimit-Reset (Unix timestamp) to retry.

Order/Delivery Errors

Order-level errors appear in the order object:

{
  "id": "ord_xyz789",
  "status": "failed",
  "error": "Provider temporarily unavailable"
}
StatusMeaningAction
failedDelivery failedAutomatic refund usually
refundedPayment returnedCheck balance/refund address

Validation Errors

Error CodeDescriptionSolution
invalid_phone_numberPhone number invalidUse E.164 format (+15551234567)
unsupported_operatorOperator not supportedCheck with /check_phone_number
invalid_valueValue outside allowed rangeCheck product range or packages
invalid_package_idPackage ID doesn't existVerify against product details
invalid_quantityQuantity invalidUse positive integer

BRGC Batch Errors

Error CodeDescriptionSolution
batch_creation_failedFailed to create batchContact support
invalid_quantityInvalid batch sizeCheck limits
invalid_currencyCurrency not supportedUse USD, EUR, etc.

Handling Unknown Errors

For undocumented error codes:

  1. Log the full error response
  2. Check the message for details
  3. If persistent, contact support with:
    • Error code and message
    • Request body (without sensitive data)
    • Timestamp

Error Handling Best Practices

async function safeApiCall(url, options) {
  try {
    const response = await fetch(url, options);
    const data = await response.json();
    
    if (!response.ok) {
      // Handle known errors
      switch (data.error_code) {
        case 'balance_too_low':
          return { success: false, error: 'insufficient_balance' };
        case 'out_of_stock':
          return { success: false, error: 'unavailable' };
        case 'not_found':
          return { success: false, error: 'product_not_found' };
        default:
          // Log unknown errors
          console.error('Unknown error:', data);
          return { success: false, error: 'unknown', details: data };
      }
    }
    
    return { success: true, data: data.data };
    
  } catch (networkError) {
    // Handle network errors
    console.error('Network error:', networkError);
    return { success: false, error: 'network_error' };
  }
}