# Funds Withdrawal

### Authentication

A separate API key must be used for authentication. It can be generated in the «Security» section in your account settings. The key is displayed only once, so make sure to store it in a secure place and do not disclose it.

### What the method allows you to do

* Creates a withdrawal request in the specified currency.
* Minimum interval between requests — 12 seconds.

### Endpoint

<mark style="color:green;">`POST`</mark> `https://api.cryptocloud.plus/v2/invoice/api/out/create`

### Headers

| Name                                            | Type   | Example                             | Description                                                  |
| ----------------------------------------------- | ------ | ----------------------------------- | ------------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark> | string | Token eyJ0eXAiOiJK<...>4npi1ksS8tSY | API key from the «Security» section in your account settings |

### Request Body

Key parameters

| Name                                             | Type   | Example                        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------------------------------ | ------ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| currency\_code<mark style="color:red;">\*</mark> | string | ETH                            | <p>Currency code:</p><p></p><p>BTC, LTC, TRX, SOL, TON, BNB, ETH, ETH\_ARB, ETH\_BASE, ETH\_OPT, USDT\_ARB, USDT\_BSC, USDT\_ERC20, USDT\_OPT, USDT\_SOL, USDT\_TON, USDT\_TRC20, USDC\_ARB, USDC\_BASE, USDC\_BSC, USDC\_ERC20, USDC\_OPT, USDC\_SOL, DAI\_ARB, DAI\_BASE, DAI\_BSC, DAI\_ERC20, DAI\_OPT, USDD\_TRC20, PYUSD\_ERC20, PYUSD\_SOL, XAUT\_ERC20, XAUT\_TON, ARB\_ARB, OP\_OPT, PEPE\_BSC, PEPE\_ERC20, SHIB\_BSC, SHIB\_ERC20, TRUMP\_SOL</p> |
| to\_address<mark style="color:red;">\*</mark>    | string | 0x396343<...>210945346fb82Aa49 | Recipient's wallet address                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| amount<mark style="color:red;">\*</mark>         | float  | 0.003                          | Withdrawal request amount in the specified currency                                                                                                                                                                                                                                                                                                                                                                                                          |

### Request examples

These examples show how to create a withdrawal request.

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.cryptocloud.plus/v2/invoice/api/out/create \
  -H 'Authorization: Token YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "currency_code": "BTC",
    "to_address": "YOUR_RECIPIENT_ADDRESS",
    "amount": 0.00023
  }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from typing import Optional


class PayoutAPIClient:
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.base_url = 'https://api.cryptocloud.plus'
        self.headers = {
            'Authorization': f'Token {self.api_key}',
            'Content-Type': 'application/json'
        }

    def create_payout(self, currency_code: str, to_address: str, amount: float) -> dict:
        """
        Creates a withdrawal request.

        :param currency_code: Currency code (e.g. “BTC”, “ETH”, “USDT”, “LTC”).
        :param to_address: Recipient's address.
        :param amount: Amount to send.
        :return: API response in dict format.
        """
        url = f"{self.base_url}/v2/invoice/api/out/create"
        payload = {
            "currency_code": currency_code,
            "to_address": to_address,
            "amount": amount
        }

        response = requests.post(url, json=payload, headers=self.headers)

        if response.status_code == 200:
            return response.json()
        else:
            raise PayoutAPIError(response.status_code, response.json())


class PayoutAPIError(Exception):
    def __init__(self, status_code: int, error_data: Optional[dict] = None):
        self.status_code = status_code
        self.error_data = error_data or {}
        message = f"API Request failed with status {status_code}: {self.error_data}"
        super().__init__(message)


# Example of use:
if __name__ == "__main__":
    # Client Configuration
    api_key = ""

    client = PayoutAPIClient(api_key)

    try:
        result = client.create_payout(
            currency_code="BTC",
            to_address="",
            amount=0.00023
        )
        print("Success:", result)
    except PayoutAPIError as e:
        print("Error occurred:", e)
```

{% endtab %}

{% tab title="JavaScript " %}
{% code title="Axios.js:" %}

```javascript
/**
 * Custom error for handling payout API response failures.
 */
class PayoutAPIError extends Error {
  /**
   * @param {number} statusCode - HTTP status code returned by the API.
   * @param {object} [errorData={}] - Error details returned by the API.
   */
  constructor(statusCode, errorData = {}) {
    super(`API Request failed with status ${statusCode}: ${JSON.stringify(errorData)}`);
    this.name = 'PayoutAPIError';
    this.statusCode = statusCode;
    this.errorData = errorData;
  }
}

/**
 * Client for interacting with CryptoCloud Payout API.
 */
class PayoutAPIClient {
  /**
   * @param {string} apiKey - API token used for authentication.
   */
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://api.cryptocloud.plus';
    this.headers = {
      'Authorization': `Token ${this.apiKey}`,
      'Content-Type': 'application/json'
    };
  }

  /**
   * Creates a payout request.
   *
   * @param {string} currencyCode - Currency code (e.g., "BTC", "ETH", "USDT", "LTC").
   * @param {string} toAddress - Recipient address.
   * @param {number} amount - Amount to send.
   * @returns {Promise<object>} - API response data.
   * @throws {PayoutAPIError} - On failed request.
   */
  async createPayout(currencyCode, toAddress, amount) {
    const url = `${this.baseUrl}/v2/invoice/api/out/create`;
    const payload = {
      currency_code: currencyCode,
      to_address: toAddress,
      amount: amount
    };

    try {
      const response = await axios.post(url, payload, {
        headers: this.headers
      });
      return response.data;
    } catch (error) {
      const status = error.response?.status || 500;
      const data = error.response?.data || {};
      throw new PayoutAPIError(status, data);
    }
  }
}

// Example usage with Axios
(async () => {
  const client = new PayoutAPIClient('<your_api_key_here>');

  try {
    const result = await client.createPayout("BTC", "<recipient_address>", 0.00023);
    console.log("Success:", result);
  } catch (error) {
    console.error("Error occurred:", error);
  }
})();
```

{% endcode %}

{% code title="Fetch.js:" %}

```javascript
const apiKey = '<your_api_key>';
const payload = {
  currency_code: 'BTC',
  to_address: '<recipient_address>',
  amount: 0.00023
};

fetch('https://api.cryptocloud.plus/v2/invoice/api/out/create', {
  method: 'POST',
  headers: {
    'Authorization': `Token ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(payload)
})
  .then(response => {
    if (!response.ok) throw new Error(`HTTP error ${response.status}`);
    return response.json();
  })
  .then(data => console.log('Success:', data))
  .catch(err => console.error('Error:', err));
```

{% endcode %}

{% code title="Ajax.js:" %}

```javascript
const apiKey = '<your_api_key>';
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.cryptocloud.plus/v2/invoice/api/out/create");
xhr.setRequestHeader("Authorization", `Token ${apiKey}`);
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onload = function () {
  if (xhr.status === 200) {
    console.log("Success:", JSON.parse(xhr.responseText));
  } else {
    console.error("Error:", xhr.status, xhr.responseText);
  }
};

const payload = {
  currency_code: 'BTC',
  to_address: '<recipient_address>',
  amount: 0.00023
};

xhr.send(JSON.stringify(payload));
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}

<pre class="language-php" data-title="PHP 8.0 +"><code class="lang-php"><strong>&#x3C;?php
</strong>
/**
 * Class PayoutAPIError
 *
 * Custom exception for API errors.
 */
class PayoutAPIError extends Exception
{
    public int $statusCode;
    public array $errorData;

    /**
     * PayoutAPIError constructor.
     *
     * @param int $statusCode
     * @param array $errorData
     */
    public function __construct(int $statusCode, array $errorData = [])
    {
        $this->statusCode = $statusCode;
        $this->errorData = $errorData;
        $message = "API Request failed with status $statusCode: " . json_encode($errorData);
        parent::__construct($message, $statusCode);
    }
}

/**
 * Class PayoutAPIClient
 *
 * Client for creating crypto payouts via CryptoCloud API.
 */
class PayoutAPIClient
{
    private string $apiKey;
    private string $baseUrl;
    private array $headers;

    /**
     * PayoutAPIClient constructor.
     *
     * @param string $apiKey
     */
    public function __construct(string $apiKey)
    {
        $this->apiKey = $apiKey;
        $this->baseUrl = 'https://api.cryptocloud.plus';
        $this->headers = [
            'Authorization: Token ' . $this->apiKey,
            'Content-Type: application/json'
        ];
    }

    /**
     * Create payout request.
     *
     * @param string $currencyCode Currency code (e.g., BTC, ETH).
     * @param string $toAddress Recipient address.
     * @param float $amount Amount to send.
     * @return array Response from API.
     * @throws PayoutAPIError On API failure.
     */
    public function createPayout(string $currencyCode, string $toAddress, float $amount): array
    {
        $url = $this->baseUrl . '/v2/invoice/api/out/create';

        $payload = json_encode([
            'currency_code' => $currencyCode,
            'to_address' => $toAddress,
            'amount' => $amount,
        ]);

        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $decoded = json_decode($response, true);

        curl_close($ch);

        if ($httpCode === 200) {
            return $decoded;
        } else {
            throw new PayoutAPIError($httpCode, $decoded ?? []);
        }
    }
}

// Example usage
try {
    $client = new PayoutAPIClient('&#x3C;your_api_key_here>');
    $response = $client->createPayout('BTC', '&#x3C;recipient_address>', 0.00023);
    echo "Success:\n";
    print_r($response);
} catch (PayoutAPIError $e) {
    echo "Error occurred:\n" . $e->getMessage();
}
</code></pre>

{% endtab %}
{% endtabs %}

### Response example

A successful request returns a response with the status `success` and a `result` object.

{% tabs %}
{% tab title="200: OK – Request created" %}

```json
{
    "status": "success",
    "result": {
        "uuid": "INV-2Q2SICZN",
        "created": "2026-01-01 08:03:02.216905",
        "address": "TT2T11KZhoDu48i2p4FWxfG79zdkEWkU9N",
        "currency": {
            "id": 4,
            "code": "USDT",
            "fullcode": "USDT_TRC20",
            "network": {
                "code": "TRC20",
                "id": 4,
                "icon": "https://cdn.cryptocloud.plus/img/network/TRC20.svg",
                "fullname": "Tron"
            },
            "name": "Tether",
            "is_email_required": false,
            "stablecoin": true,
            "icon_base": "https://cdn.cryptocloud.plus/img/currency/USDT.svg",
            "icon_network": "https://cdn.cryptocloud.plus/img/currency_network/USDT_TRC.svg",
            "icon_qr": "https://cdn.cryptocloud.plus/img/stroke/USDT_STROKE.svg",
            "order": 1
        },
        "date_finished": null,
        "expiry_date": null,
        "side_commission": "client",
        "side_commission_cc": "merchant",
        "type_payments": "crypto",
        "status": "created",
        "invoice_status": "start",
        "is_email_required": false,
        "project": {
            "id": 1,
            "name": "Test",
            "fail": "https://test.com/failed-payment",
            "success": "https://test.com/successful-payment",
            "logo": ""
        },
        "tx_list": [],
        "step": 1,
        "test_mode": false,
        "type": "dw",
        "user_email": "",
        "pay_url": "None",
        "phone": "",
        "order_id": "None",
        "amount_in_crypto": null,
        "amount_in_fiat": 0,
        "amount": 10.0,
        "amount_usd": 10.0,
        "amount_to_pay": 10.0,
        "amount_to_pay_usd": 10.0,
        "amount_paid": 0.0,
        "amount_paid_usd": 0.0,
        "fee": 0.0,
        "fee_usd": 0.0,
        "service_fee": 0.0,
        "service_fee_usd": 0.0,
        "received": 0,
        "received_usd": 0,
        "to_surcharge": 10.0,
        "to_surcharge_usd": 10.0,
        "total_rub": 0,
        "currency_list": [
            {
                "code": "USDT",
                "fullcode": "USDT_TRC20",
                "name": "Tether",
                "is_email_required": false,
                "stablecoin": true,
                "icon_base": "https://cdn.cryptocloud.plus/img/currency/USDT.svg",
                "icon_qr": "https://cdn.cryptocloud.plus/img/stroke/USDT_STROKE.svg",
                "order": 28,
                "network": [
                    {
                        "code": "TRC20",
                        "id": 4,
                        "icon": "https://cdn.cryptocloud.plus/img/network/TRC20.svg",
                        "fullname": "Tron"
                    }
                ]
            }
        ],
        "aml_enabled": false,
        "aml_side": "merchant",
        "aml_cost": 0.0,
        "aml_cost_usd": 0.0,
        "aml_checks": [],
        "links": [],
        "quiz_result": false,
        "quiz_detail": {
            "invoice": null,
            "rating": null,
            "comment": null,
            "created": null
        },
        "memo": ""
    }
}
```

{% endtab %}
{% endtabs %}

### Parameter description

The `result` object contains:

<table data-full-width="false"><thead><tr><th>Name</th><th>Type</th><th>Example</th><th>Description</th></tr></thead><tbody><tr><td>invoice_id</td><td>string</td><td>INV-89UX09KA</td><td>Unique withdrawal request identifier with the INV prefix</td></tr><tr><td>status</td><td>string</td><td>created</td><td>Withdrawal request status — always <code>created</code> when the request is submitted</td></tr><tr><td>currency</td><td>string</td><td>ETH</td><td>Code of the selected cryptocurrency in the withdrawal request</td></tr><tr><td>amount</td><td>float</td><td>0.0029</td><td>Withdrawal request amount in cryptocurrency</td></tr></tbody></table>
