Skip to content

Refund a client balance

POSThttps://gptunnel.ru/api/v1/balance/refund

Returns 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

ParameterTypeDescription
Authorization*stringOrganization API key
Idempotency-Key*stringUnique key for this refund, 8–60 characters from A-Za-z0-9_-
Content-Type*stringapplication/json

Request parameters

ParameterTypeDescription
user_idstringClient user ID, 24 lowercase hexadecimal characters. Provide exactly one of user_id, org_id, and user_data.
org_idstringClient organization ID, 24 lowercase hexadecimal characters. Provide exactly one of user_id, org_id, and user_data.
user_dataobjectLook up a user by phone: {"phone":"+79XXXXXXXXX"}. This feature requires separate activation.
amountnumberAmount 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_balancebooleanSet 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.

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

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": 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))

Response fields

ParameterTypeDescription
codenumber0 on success
transaction_idstringThe Idempotency-Key from your request
org_idstringThe organization to which the money returned
client_user_idstring | nullUser from whose personal account the return is made
client_org_idstring | nullThe organization from which the return is made
amountnumberAmount debited from the client account in rubles. With refund_all_balance, the actual amount can exceed 100,000.
discount_revertednumberAmount of the partner discount reversed for this refund. Zero if the transfers had no discount.
net_amountnumberNet credit to the organization’s balance, equal to amount minus discount_reverted
currencystringAlways RUB
created_atstringOperating time, ISO 8601
replayedbooleantrue 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
}

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.

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.