cred.diy/ docs
    Sign inGet an API key
    All documentation

    Credit Swaps - cred.diy API documentation

    Credit Swaps

    Enable users to exchange between different credit types atomically. Configure swap pairs with exchange rates and fees to create flexible credit economies.

    List Swap Pairs

    Retrieve available swap pairs for your project.

    // List available swap pairs
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/swap-pairs',
      {
        headers: {
          'x-api-key': 'sk_live_your_api_key'
        }
      }
    );
    
    const result = await response.json();
    // { swap_pairs: [{ id: '...', source_credit_type_name: 'Gold', target_credit_type_name: 'Silver', exchange_rate: 10, ... }] }

    Execute Swap

    Perform an atomic swap between two credit types.

    // Execute a credit swap
    const response = await fetch(
      'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/swap',
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': 'sk_live_your_api_key'
        },
        body: JSON.stringify({
          user_id: 'user_123',
          swap_pair_id: 'swap_abc123',
          source_amount: 100
        })
      }
    );
    
    const result = await response.json();
    // { 
    //   success: true, 
    //   transaction_id: 'swap_tx_xyz789',
    //   source_amount: 100,
    //   target_amount: 975,
    //   exchange_rate: 10,
    //   fee_amount: 25,
    //   source_new_balance: 400,
    //   target_new_balance: 1975
    // }

    Swap Pair Fields

    FieldTypeDescription
    exchange_ratenumberHow many target credits per source credit
    fee_percentnumberFee deducted from output (e.g., 2.5)
    min_swap_amountnumberMinimum source credits per swap
    max_swap_amountnumberMaximum source credits per swap
    is_bidirectionalbooleanCan swap in both directions

    Exchange Rate Calculation

    The formula is: target = source × rate × (1 - fee%/100)

    Example: 100 Gold at 10:1 with 2.5% fee = 100 × 10 × 0.975 = 975 Silver

    Your first credit is one request away.

    Create a project, copy an API key, and issue a credit from your server.