# Create a Pay-out Instance

This endpoint allows you to create a new payment instance and receive a URL that can be used to launch the **Tylt CrossRamp Pay-In widget.** Through the widget, the merchant's end customer can make a deposit or payment to the merchant using **PIX**. The payment is settled in USDT into the merchants wallet.

**Endpoint**

<mark style="color:green;">**`POST`**</mark>`https://api.tylt.money/v2/prime/BR/PIX/instance`

**Request Headers**

{% tabs %}
{% tab title="First Tab" %}

<table data-full-width="true"><thead><tr><th width="133">Name</th><th width="79">Type</th><th width="167">Example</th><th>Description</th></tr></thead><tbody><tr><td>X-TLP-APIKEY</td><td>string</td><td>93ee3c5e133697251b5362bcf9cc8532476785t8768075616f58d88</td><td>Your Tylt API Key, used to identify your account in API requests.</td></tr><tr><td>X-TLP-SIGNATURE</td><td>string</td><td>d0afef3853dfc8489c8b9affa5825171fdd7y7685675e4966a05f66ed2b3eaf9462b3c9c0</td><td>HMAC SHA-256 signature generated using the API Secret Key to secure the request.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
When using the API, ensure to include your API Key and generate the signature for the request payload using your API Secret. The tables provided above contain example values for illustration purposes only. Please refer to the code snippets for detailed instructions on how to sign the request and generate the signature properly.
{% endhint %}

**Request Body**

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

<table data-header-hidden><thead><tr><th width="204"></th><th width="121"></th><th></th></tr></thead><tbody><tr><td><strong>Field Name</strong></td><td><strong>Type</strong></td><td><strong>Description</strong></td></tr><tr><td><code>isBuyTrade</code></td><td><code>number</code></td><td>Must be set to 0 for a Pay-out transaction.</td></tr><tr><td><code>userDetails</code></td><td><code>JSON Object</code></td><td>Custom fields associated with the user, supplied by the merchant. These fields are included in web-hook notifications and other API responses for easy reference and tracking. An empty object can be sent.</td></tr><tr><td><code>merchantOrderId</code></td><td><code>string</code></td><td>A UUID used by the merchant to reference this instance or any transaction related to it.</td></tr><tr><td><code>callBackUrl</code></td><td><code>string</code></td><td>The URL to which payment status updates are sent.</td></tr><tr><td><code>redirectUrl</code></td><td><code>string</code></td><td>The URL to redirect the user after completing the payment.</td></tr><tr><td><code>amount</code></td><td><code>number</code></td><td>Mandatory. This is the amount the user wants to withdraw in USDT or BRL equivalent. </td></tr><tr><td><code>currencySymbol</code></td><td><code>string</code></td><td>Supported Currency is "USDT" or "BRL" only.</td></tr><tr><td><code>autoPayout</code></td><td><code>integer</code></td><td>Set to <code>1</code> if you want the payout to be processed automatically, without requiring the user to interact with the Pay-Out widget. When set to <code>0</code>, the user must manually confirm the payout through the widget interface.</td></tr><tr><td><code>pixDetails</code></td><td><code>JSON Object</code></td><td><table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td>Object containing the beneficiary’s payout details — required if autoPayout is <code>1</code></td></tr></tbody></table><table data-header-hidden><thead><tr><th>Fields inside userPayoutDetails</th></tr></thead><tbody><tr><td><h4> </h4><table data-header-hidden><thead><tr><th>Field</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td><code>fullName</code></td><td>Full legal name of the bank account holder, as registered with their bank.</td><td>Yes</td></tr><tr><td><code>cpfKey</code></td><td>CPF (individual) or CNPJ (business) number linked to the account.</td><td>Yes</td></tr><tr><td><code>pixKeyType</code></td><td>Type of PIX key associated with the account. Accepted values: <code>CPF</code>, <code>EMAIL</code>, <code>MOBILE</code>.</td><td>Yes</td></tr><tr><td><code>pixKey</code></td><td>Actual PIX key value corresponding to the selected <code>pixKeyType</code>.</td><td>Yes</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Important Note on `autoPayout` Usage**

If using `autoPayout = 1`, please make note of the following:

1. **KYC / Risk Triggers:**\
   If the payout request triggers a compliance or risk requirement (e.g., due to cumulative 30-day transaction volume or CPF-linked payment thresholds), the payout will **fail automatically**.
2. **KYC Requirement:**\
   Users who exceed permitted payout limits may be required to complete KYC verification. Since the `autoPayout` flow does not invoke the payout widget, **KYC submission cannot be completed automatically**, and the payout will not proceed.
3. **Recommended Approach:**\
   It is generally recommended to use the **widget-based payout flow**, which handles user KYC interactions seamlessly. However, `autoPayout` may be used for **verified users** or **pre-approved payout routes** where no compliance intervention is expected.
4. **Widget URL Omission**\
   When `autoPayout` is set to `1`, the **payout widget URL will not be included** in the API response, since no user interaction is required.
   {% endhint %}

**Code Snippet**

{% tabs %}
{% tab title="JavaScript (Axios)" %}

```javascript
const axios = require('axios');
const crypto = require('crypto');

// Replace with your API Key and Secret
const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';

// Request body
const requestBody = {
  isBuyTrade: 0, // 0 = Sell (Off-Ramp), 1 = Buy (On-Ramp)
  userDetails: {}, // Optional user metadata (e.g., email, phone, userId)
  merchantOrderId: crypto.randomUUID(),
  callBackUrl: 'https://www.test.com/callback',
  redirectUrl: 'https://www.test.com/callback',
  amount: 10,
  currencySymbol: 'BRL',
  autoPayout: 1, // 1 = Auto process payout, 0 = Manual via widget ( Default)
  pixDetails: { // Required if autoPayout is set to 1
    fullName: 'João Pereira',
    cpfKey: '12345678910',
    pixKeyType: 'CPF', // Accepted values: 'CPF', 'EMAIL', 'MOBILE'
    pixKey: '12345678910'
  }
};

// Print request body for reference
console.log('requestBody',requestBody);

// Convert request body to JSON
const raw = JSON.stringify(requestBody);

// Function to create HMAC SHA-256 signature
const createSignature = (secret, data) => {
    return crypto.createHmac('sha256', secret)
                 .update(data)
                 .digest('hex');
};

// Generate signature
const signature = createSignature(apiSecret, raw);

// Define headers
const headers = {
    "X-TLP-APIKEY": apiKey,
    "X-TLP-SIGNATURE": signature
};

// Send the request
axios.post('https://api.tylt.money/v2/prime/BR/PIX/instance', raw, { headers })
    .then(response => console.log("Success:", response.data))
    .catch(error => console.error("Error:", error));

```

{% endtab %}

{% tab title="Python" %}

```python
import json
import hashlib
import hmac
import requests
import uuid

# Replace with your API Key and Secret
api_key = 'your-api-key'
api_secret = 'your-api-secret'

# Function to create HMAC SHA-256 signature
def create_signature(secret, data):
    return hmac.new(secret.encode(), data.encode(), hashlib.sha256).hexdigest()

# Function to send a POST request
def send_post_request(url, body):
    raw = json.dumps(body, separators=(',', ':'), ensure_ascii=False)
    signature = create_signature(api_secret, raw)

    headers = {
        'Content-Type': 'application/json',
        'X-TLP-APIKEY': api_key,
        'X-TLP-SIGNATURE': signature
    }

    response = requests.post(url, headers=headers, data=raw)
    return response.json()

# Request body
request_body = {
  "isBuyTrade": 0,
  "userDetails": {},
  "merchantOrderId": str(uuid.uuid4()),
  "callBackUrl": "https://www.test.com/callback",
  "redirectUrl": "https://www.test.com/callback",
  "amount": 10,
  "currencySymbol": "BRL",
  "autoPayout": 1,
  "pixDetails": {
    "fullName": "João Pereira",
    "cpfKey": "12345678910",
    "pixKeyType": "CPF",
    "pixKey": "12345678910"
  }
}

# Print request body for reference
print('requst_body',request_body)


# Send the request
response = send_post_request('https://api.tylt.money/v2/prime/BR/PIX/instance', request_body)
print("Response:", response)


```

{% endtab %}

{% tab title="JavaScript (Fetch)" %}

```javascript
const fetch = require('node-fetch');
const crypto = require('crypto');

// Replace with your API Key and Secret
const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';

// Request body
const requestBody = {
  isBuyTrade: 0, // 0 = Sell (Off-Ramp), 1 = Buy (On-Ramp)
  userDetails: {}, // Optional user metadata (e.g., email, phone, userId)
  merchantOrderId: crypto.randomUUID(),
  callBackUrl: 'https://www.test.com/callback',
  redirectUrl: 'https://www.test.com/callback',
  amount: 10.00,
  currencySymbol: 'BRL',
  autoPayout: 1, // 1 = Auto process payout, 0 = Manual via widget
  pixDetails: {
    fullName: 'João Pereira',
    cpfKey: '12345678910',
    pixKeyType: 'CPF', // Accepted values: 'CPF', 'EMAIL', 'MOBILE'
    pixKey: '12345678910'
  }
};

// Print request body for reference
console.log("requestBody", requestBody);

// Convert request body to JSON
const raw = JSON.stringify(requestBody);

// Function to create HMAC SHA-256 signature
const createSignature = (secret, data) => {
    return crypto.createHmac('sha256', secret)
                 .update(data)
                 .digest('hex');
};

// Generate signature
const signature = createSignature(apiSecret, raw);

// Define headers
const headers = {
    "Content-Type": "application/json",
    "X-TLP-APIKEY": apiKey,
    "X-TLP-SIGNATURE": signature
};

// Function to send the request
const sendRequest = async (url, headers, body) => {
    const response = await fetch(url, {
        method: 'POST',
        headers: headers,
        body: body,
    });
    return response.json();
};

// Send the request
sendRequest('https://api.tylt.money/v2/prime/BR/PIX/instance', headers, raw)
    .then(result => console.log("Success:", result))
    .catch(error => console.error("Error:", error));

```

{% endtab %}
{% endtabs %}

**Response**

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

```json
{
    "msg": "Instance created successfully",
    "data": {
        "url": "https://app.tylt.money/prime-brl/d0f6cc25-e8f8-11ef-830e-02d8461243e9", // will not be sent if autoPayout is set to 1
        "instanceId": "d0f6cc25-e8f8-11ef-830e-02d8461243e9",
        "tradeId": 10432

        }    
}
```

{% endtab %}

{% tab title="Response Fields" %}

<table data-header-hidden><thead><tr><th width="236"></th><th width="96"></th><th></th></tr></thead><tbody><tr><td><strong>Field Name</strong></td><td><strong>Type</strong></td><td><strong>Description</strong></td></tr><tr><td>url</td><td>string</td><td>The unique link to the Tylt Prime Payment widget. You can display this url either on iframe or a browser.</td></tr><tr><td>instanceId</td><td>string</td><td>The instance ID generated by Tylt, used as a UUID global identifier. </td></tr><tr><td>tradeId</td><td>number</td><td>The trade ID generated by Tylt, used as a numerical unique global identifier</td></tr></tbody></table>
{% endtab %}
{% endtabs %}
