Refund a client balance
Refunds
Section titled “Refunds”https://gptunnel.ru/api/v1/balance/refundReturns funds from a client account to the balance of the organization that owns the API key. Identify the source account using exactly one field. Use user_id for a personal account, org_id for an organization, or user_data.phone to find a personal account by phone number. Phone lookup must be enabled for the partner.
Refund rules
- Original transfers. You can refund only the portion of your transfers to this client that has not already been refunded. Bonus points cannot be refunded.
- Current balance. A refund cannot exceed the client’s current balance. If the client spends part of a transfer and later tops up the account, the top-up counts toward the balance available for a refund. The original transfer limit still applies.
- Frozen accounts. You can refund a balance from an account frozen by the partner or GPTunneL. This lets you recover the remaining funds when a contract ends.
- Oldest transfers first. A refund reduces the outstanding amounts on your transfers to this client, starting with the oldest. The operation is atomic. If it fails, none of the transfers change.
Send exactly one of amount or refund_all_balance: true. A full refund returns the smaller of the customer’s balance and the total amount from transfers that has yet to be refunded. The 100,000 ₽ ceiling applies only to amount.
Request headers
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | Organization API key |
Idempotency-Key* | string | Unique key for this refund, 8–60 characters from A-Za-z0-9_- |
Content-Type* | string | application/json |
Request parameters
| Parameter | Type | Description |
|---|---|---|
user_id | string | Client user ID, 24 lowercase hexadecimal characters. Provide exactly one of user_id, org_id, and user_data. |
org_id | string | Client organization ID, 24 lowercase hexadecimal characters. Provide exactly one of user_id, org_id, and user_data. |
user_data | object | Look up a user by phone: {"phone":"+79XXXXXXXXX"}. This feature requires separate activation. |
amount | number | Amount in RUB, greater than 0 and at most 100,000, with at most two decimal places. Provide exactly one of amount or refund_all_balance: true. |
refund_all_balance | boolean | Set to true to refund the full eligible balance. The 100,000 RUB limit does not apply. Provide exactly one of amount or refund_all_balance: true. |
Example request
Section titled “Example request”Set GPTUNNEL_API_KEY and replace the placeholders with values for your organization.
import jsonimport osfrom 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": 300}request = Request( "https://gptunnel.ru/api/v1/balance/refund", method="POST", headers={ "Authorization": key, "Content-Type": "application/json", "Idempotency-Key": "refund-2026-11-06-000041", }, data=json.dumps(body).encode("utf-8"),)with urlopen(request, timeout=30) as response: print(json.load(response))curl --request POST \ --url 'https://gptunnel.ru/api/v1/balance/refund' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --header 'Idempotency-Key: refund-2026-11-06-000041' \ --data '{ "user_id": "6ad72133269dc8d9f75a33bc", "amount": 300}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "user_id": "6ad72133269dc8d9f75a33bc", "amount": 300}const response = await fetch("https://gptunnel.ru/api/v1/balance/refund", { method: "POST", headers: { Authorization: key, "Content-Type": "application/json", "Idempotency-Key": "refund-2026-11-06-000041", }, body: JSON.stringify(body),})if (!response.ok) throw new Error(await response.text())console.log(await response.json())Response
Section titled “Response”Response fields
| Parameter | Type | Description |
|---|---|---|
code | number | 0 on success |
transaction_id | string | The Idempotency-Key from your request |
org_id | string | The organization to which the money returned |
client_user_id | string | null | User from whose personal account the return is made |
client_org_id | string | null | The organization from which the return is made |
amount | number | Amount debited from the client account in rubles. With refund_all_balance, the actual amount can exceed 100,000. |
discount_reverted | number | Amount of the partner discount reversed for this refund. Zero if the transfers had no discount. |
net_amount | number | Net credit to the organization’s balance, equal to amount minus discount_reverted |
currency | string | Always RUB |
created_at | string | Operating time, ISO 8601 |
replayed | boolean | true if this request repeats a refund with the same Idempotency-Key |
{ "code": 0, "transaction_id": "refund-2026-11-06-000041", "org_id": "6ad5e0c3269dc8d9f75a1f07", "client_user_id": "6ad72133269dc8d9f75a33bc", "client_org_id": null, "amount": 300, "discount_reverted": 0, "net_amount": 300, "currency": "RUB", "created_at": "2026-11-06T08:21:07.000Z", "replayed": false}{ "code": 37, "message": "Insufficient funds on the client balance."}{ "code": 38, "message": "Amount exceeds the unreturned transfers to this client."}Partnership discount
Section titled “Partnership discount”If the original transfer included a partner discount, the refund reverses the discount in proportion to the amount refunded, using the rate recorded for each transfer. The organization receives amount. A separate transaction deducts discount_reverted, leaving a net credit of net_amount.
Errors
Section titled “Errors”| HTTP | code | When |
|---|---|---|
| 400 | 3 | The request must identify exactly one client, use only supported fields, and specify either amount or refund_all_balance: true. An ID must contain exactly 24 characters from 0-9a-f, and the amount must be within the allowed range. See details. |
| 400 | 21 | The Idempotency-Key header is missing or invalid. It must contain 8–60 characters from A-Za-z0-9_-. |
| 403 | 13 | The key belongs to a personal account. This endpoint requires an organization key. |
| 403 | 22 | Transfers are disabled on the key. |
| 403 | 27 | Phone lookup with user_data is disabled for the organization. |
| 403 | 35 | The refund endpoint is not enabled for the organization that owns the key, transfers are disabled for the organization, or a distributor manages it. |
| 404 | 17 | The user does not exist, has been deleted, or is not a client of this partner. |
| 404 | 24 | The organization does not exist, has been deleted, or is not a client of this partner. |
| 409 | 20 | The Idempotency-Key has already been used for a different client or amount. |
| 409 | 39 | Another operation is in progress for this organization. Retry with the same Idempotency-Key. |
| 422 | 37 | The client’s balance is below the requested amount. With refund_all_balance, this means there are no eligible funds to refund. |
| 422 | 38 | The requested amount exceeds the portion of your transfers to this client that has not yet been refunded. |
The API checks the key’s permissions first, then the Idempotency-Key header, and finally the request body. A key without access receives HTTP 403 even when the header is missing.
If the client is deleted while the refund is being processed, the response is HTTP 404 with code 23 for a user or 25 for an organization. If the organization’s current owner is not your client, the API returns HTTP 404 with code 24. You cannot use this endpoint to recover funds from that organization, even if you previously transferred funds to it.
See the Business API error reference for all error codes, including the 401 response for an invalid key.