Read a client balance
Client balance
Section titled “Client balance”POST
https://gptunnel.ru/api/v1/balance/getReturns the current balance of a client account. Identify the account using exactly one of the following fields.
user_idselects a user’s personal account.org_idselects an organization’s account.user_data.phoneselects a user’s personal account by phone number in the format+79XXXXXXXXX. Phone lookup must be enabled for the partner.
This read-only operation does not require an Idempotency-Key header.
Request headers
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | Organization API key |
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. |
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"}request = Request( "https://gptunnel.ru/api/v1/balance/get", method="POST", headers={ "Authorization": key, "Content-Type": "application/json", }, 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/get' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "user_id": "6ad72133269dc8d9f75a33bc"}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "user_id": "6ad72133269dc8d9f75a33bc"}const response = await fetch("https://gptunnel.ru/api/v1/balance/get", { method: "POST", headers: { Authorization: key, "Content-Type": "application/json", }, 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 |
type | string | Account type: user for a personal account, org for an organization account. |
id | string | ID of the user or organization whose balance is returned. |
balance | number | Balance in rubles. It can be negative. |
bonus | number | User’s bonus points. One point is worth 0.5 RUB. Always zero for organizations. |
credit_limit | number | Only for the organization: credit limit in rubles, 0 if not assigned |
inn | string | null | For organizations only: Russian taxpayer identification number (INN) |
ogrn | string | null | For organizations only: Russian primary state registration number (OGRN) |
spend_blocked | boolean | true if spending is blocked on the account. Use balance/setSpendBlocked to change this setting. |
currency | string | Always RUB |
{ "code": 0, "type": "user", "id": "6ad72133269dc8d9f75a33bc", "balance": 412.5, "bonus": 0, "spend_blocked": false, "currency": "RUB"}{ "code": 0, "type": "org", "id": "6ad7a4f2269dc8d9f75a41d0", "balance": 18250, "bonus": 0, "credit_limit": 0, "inn": "7701234567", "ogrn": "1027700123456", "spend_blocked": false, "currency": "RUB"}{ "code": 17, "message": "Recipient not found."}Errors
Section titled “Errors”| HTTP | code | When |
|---|---|---|
| 400 | 3 | The request must identify exactly one client and may contain only supported fields. An ID must contain exactly 24 characters from 0-9a-f. See details. |
| 403 | 13 | The key belongs to a personal account rather than an organization |
| 403 | 27 | Phone lookup with user_data is disabled for the organization. |
| 403 | 34 | This endpoint is not enabled for the organization that owns the key. |
| 404 | 17 | User not found, deleted or not a customer of partner |
| 404 | 24 | Organization not found, deleted or not a customer of partner |
The API checks the key’s permissions before validating the request body. A key without access receives HTTP 403 even if the body is invalid.
See the Business API error reference for all error codes, including the 401 response for an invalid key.