# Read a client balance

Source: [Read a client balance](<https://docs.gptunnel.ru/en/business/balance-get/>)

<a id="_top"></a>
> **Note: Partner organization key**
>
> Use the partner organization’s API key. The organization must have access to the partner endpoints. See the [Business API overview](<https://docs.gptunnel.ru/en/business/#partner-clients>) for client eligibility and how to enable access.

<a id="client-balance"></a>
## Client balance

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

Returns the current balance of a client account. Identify the account using exactly one of the following fields.

- `user_id` selects a user’s personal account.
- `org_id` selects an organization’s account.
- `user_data.phone` selects 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` (required) | `string` | Organization API key |
| `Content-Type` (required) | `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. |

<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"
}
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))
```

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

```bash
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"
}'
```

<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"
}
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())
```

<a id="response"></a>
### 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 |

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

```json
{
  "code": 0,
  "type": "user",
  "id": "6ad72133269dc8d9f75a33bc",
  "balance": 412.5,
  "bonus": 0,
  "spend_blocked": false,
  "currency": "RUB"
}
```

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

```json
{
  "code": 0,
  "type": "org",
  "id": "6ad7a4f2269dc8d9f75a41d0",
  "balance": 18250,
  "bonus": 0,
  "credit_limit": 0,
  "inn": "7701234567",
  "ogrn": "1027700123456",
  "spend_blocked": false,
  "currency": "RUB"
}
```

<a id="tab-panel-1-2"></a>
**404 Not a Partner's Customer**

```json
{
  "code": 17,
  "message": "Recipient not found."
}
```

<a id="errors"></a>
### 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](<https://docs.gptunnel.ru/en/business/errors/>) for all error codes, including the `401` response for an invalid key.
