# Transfer funds

Source: [Transfer funds](<https://docs.gptunnel.ru/en/business/transfer/>)

<a id="_top"></a>
> **Note: Organization API key**
>
> Use a business organization API key with Transfers enabled. See the [Business API overview](<https://docs.gptunnel.ru/en/business/>) for setup instructions.

<a id="transfer-of-balance"></a>
## Transfer of balance

`POST https://gptunnel.ru/api/v1/balance/transfer`

The API debits `amount` from the organization that owns the key and credits the same amount to the recipient. Specify the recipient in exactly one of the following ways.

- `user_id` credits the user’s personal account.
- `org_id` credits the organization’s account.
- `user_data.phone` credits the user’s personal account by phone number in the format `+79XXXXXXXXX`. Phone lookup must be enabled for the partner.

The transfer is atomic. Both balances update together. If the transfer fails, neither balance changes. The sender can find the transfer in the journal in the organization dashboard. The recipient sees a transfer in their transaction history.

### Request headers

| Parameter | Type | Description |
| --- | --- | --- |
| `Authorization` (required) | `string` | Organization API key |
| `Idempotency-Key` (required) | `string` | Unique key for this transfer, 8–64 characters from A-Za-z0-9\_- |
| `Content-Type` (required) | `string` | application/json |

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `user_id` | `string` | Recipient user ID, 24 lowercase hexadecimal characters. Provide exactly one of user\_id, org\_id, and user\_data. |
| `org_id` | `string` | Recipient organization ID, 24 lowercase hexadecimal characters. Provide exactly one of user\_id, org\_id, and user\_data. |
| `user_data` | `object` | Look up the recipient by phone: {"phone":"+79XXXXXXXXX"}. This feature requires separate activation. |
| `amount` (required) | `number` | Amount in rubles, greater than 0 and not more than 100,000, up to 2 decimal places |

> **Caution: Retry a transfer with the same key and request body**
>
> Generate an `Idempotency-Key` before sending the request and save it with the client’s transfer request. If the connection drops, retry with the same key and body. The server returns the original result with `replayed: true` without debiting the sender again.

<a id="example-request"></a>
### Example request

Set `GPTUNNEL_API_KEY` and replace the placeholders with values for your organization.

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

key = os.environ.get("GPTUNNEL_API_KEY")
if not key:
    raise SystemExit("Set GPTUNNEL_API_KEY")

body = {
  "user_id": "6ad72133269dc8d9f75a33bc",
  "amount": 500
}
request = Request(
    "https://gptunnel.ru/api/v1/balance/transfer",
    method="POST",
    headers={
        "Authorization": key,
        "Content-Type": "application/json",
        "Idempotency-Key": "order-2026-10-20-000153",
    },
    data=json.dumps(body).encode("utf-8"),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --request POST \
  --url 'https://gptunnel.ru/api/v1/balance/transfer' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --header 'Idempotency-Key: order-2026-10-20-000153' \
  --data '{
  "user_id": "6ad72133269dc8d9f75a33bc",
  "amount": 500
}'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const key = process.env.GPTUNNEL_API_KEY
if (!key) throw new Error("Set GPTUNNEL_API_KEY")

const body = {
  "user_id": "6ad72133269dc8d9f75a33bc",
  "amount": 500
}
const response = await fetch("https://gptunnel.ru/api/v1/balance/transfer", {
  method: "POST",
  headers: {
    Authorization: key,
    "Content-Type": "application/json",
    "Idempotency-Key": "order-2026-10-20-000153",
  },
  body: JSON.stringify(body),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="response"></a>
### Response

### Response fields

| Parameter | Type | Description |
| --- | --- | --- |
| `code` | `number` | 0 on success |
| `transaction_id` | `string` | The Idempotency-Key from your request. Use it to find the transfer in the transaction history or organization journal. |
| `org_id` | `string` | Sending organization |
| `recipient_user_id` | `string \| null` | Recipient user ID when the transfer uses user\_id |
| `recipient_org_id` | `string \| null` | Recipient organization ID when the transfer uses org\_id |
| `recipient_created` | `boolean` | Always false for transfers by ID |
| `amount` | `number` | Amount credited to the recipient in rubles |
| `currency` | `string` | Always RUB |
| `discount_percent` | `number` | Partner discount on transfers, as a percentage. Zero if no discount is assigned. |
| `discount_amount` | `number` | Amount of discount returned to the sender's balance as a separate transaction |
| `created_at` | `string` | Transfer timestamp in ISO 8601 format |
| `replayed` | `boolean` | true if the request repeated a transfer with the same Idempotency-Key |

<a id="tab-panel-1-0"></a>
**200 OK**

```json
{
  "code": 0,
  "transaction_id": "order-2026-10-20-000153",
  "org_id": "6ad5e0c3269dc8d9f75a1f07",
  "recipient_user_id": "6ad72133269dc8d9f75a33bc",
  "recipient_org_id": null,
  "recipient_created": false,
  "amount": 500,
  "currency": "RUB",
  "discount_percent": 0,
  "discount_amount": 0,
  "created_at": "2026-10-20T09:15:42.000Z",
  "replayed": false
}
```

<a id="tab-panel-1-1"></a>
**422 Insufficient funds**

```json
{
  "code": 19,
  "message": "Insufficient funds on the organization balance."
}
```

<a id="tab-panel-1-2"></a>
**409 Key conflict**

```json
{
  "code": 20,
  "message": "Idempotency-Key was already used with a different request body."
}
```

<a id="partnership-discount"></a>
### Partnership discount

The recipient always receives the full `amount`. If the sending organization has a partner discount, the API debits the full transfer amount and credits the discount back to the sender in a separate transaction. The response shows the discount in `discount_amount`. Both entries appear in the transaction history.

<a id="errors"></a>
### Errors

| HTTP | code | Cause |
| --- | --- | --- |
| 400 | 3 | The request body does not match the schema. The recipient is missing, more than one recipient field is set, or the amount is outside the allowed range. See `details`. |
| 400 | 18 | The sending and receiving organizations are the same. |
| 400 | 21 | The `Idempotency-Key` header is missing or has an invalid format. |
| 403 | 16 | Transfers are enabled on the key, but the organization cannot send funds. Transfers are disabled for the organization, the organization has been deleted, or a distributor manages it. |
| 403 | 22 | Transfers are disabled on the key. A personal account key also returns this code. |
| 404 | 17 | No user was found with the given `user_id`. |
| 404 | 23 | The user account has been deleted. |
| 404 | 24 | No organization was found with the given `org_id`. |
| 404 | 25 | The receiving organization has been deleted. |
| 409 | 20 | The `Idempotency-Key` has already been used with a different request body. |
| 422 | 19 | Available funds, including the credit limit, do not cover the transfer. |

The server processes simultaneous transfers from the same organization one at a time. Queuing does not produce a separate error. If two requests arrive together with the same `Idempotency-Key`, the second waits for the first. If their bodies match, the second returns the original result with `replayed: true`. If the bodies differ, it returns HTTP `409` with code `20`.

See the [Business API error reference](<https://docs.gptunnel.ru/en/business/errors/>) for the full list of codes, including the `401` response for an invalid key.
