Read client spending by period
Expenditure during the period
Section titled “Expenditure during the period”https://gptunnel.ru/api/v1/balance/spendingReturns client spending in rubles for the requested period, grouped by day or month. Identify the client using exactly one of the following fields.
user_idincludes the user’s spending from their personal account and from the accounts of the partner’s client organizations where they work.org_idincludes spending by all employees from the specified 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.
Spending includes charges for model requests and other paid features, minus refunds for failed generations. A refund can arrive on a different day from the charge, so the total for a period can be negative. Top-ups, transfers, and refunds of transfers are excluded.
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. |
date_from* | string | First day of the period, in YYYY-MM-DD format (inclusive) |
date_to* | string | Last day of the period, in YYYY-MM-DD format (inclusive). Must be on or after date_from. |
group_by | string | day (default) or month |
by_user | boolean | Set to true for an employee breakdown in each period. Requires org_id. |
Day and month boundaries use Moscow time. The maximum date range is 92 days with group_by: "day" and 366 days with group_by: "month".
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", "date_from": "2026-11-01", "date_to": "2026-11-02"}request = Request( "https://gptunnel.ru/api/v1/balance/spending", 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/spending' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "user_id": "6ad72133269dc8d9f75a33bc", "date_from": "2026-11-01", "date_to": "2026-11-02"}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "user_id": "6ad72133269dc8d9f75a33bc", "date_from": "2026-11-01", "date_to": "2026-11-02"}const response = await fetch("https://gptunnel.ru/api/v1/balance/spending", { 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 | user or org - for which the report is built |
id | string | User or organization ID |
date_from | string | Start of period from request |
date_to | string | End of period from request |
group_by | string | day or month |
currency | string | Always RUB |
periods | array | One entry per day or month in chronological order. Periods without spending are included with zero amounts. |
summary | object | Totals for the entire date range, with the same fields as each periods entry except period and users. |
One period (periods)
| Parameter | Type | Description |
|---|---|---|
period | string | YYYY-MM-DD for the day group, YYYY-MM by month |
amount | number | Spent rubles. Negative if returns are higher than write-offs during the period |
bonus | number | Bonus points spent. One point is worth 0.5 RUB. |
total | number | Total in rubles, including amount and the ruble value of bonus points spent |
personal | object | For user only: personal account expenditures - amount, bonus, total |
orgs | array | Returned only for a user. Spending from organization accounts includes org_id, amount, bonus, and total. Sorted by total in descending order. |
users | array | Returned only with org_id and by_user: true. For each employee it includes user_id, amount, bonus, and total. Sorted by total in descending order. |
With monthly grouping, a partial month includes only the days from date_from through date_to, inclusive.
{ "code": 0, "type": "user", "id": "6ad72133269dc8d9f75a33bc", "date_from": "2026-11-01", "date_to": "2026-11-02", "group_by": "day", "currency": "RUB", "periods": [ { "period": "2026-11-01", "amount": 86.4, "bonus": 0, "total": 86.4, "personal": { "amount": 36.4, "bonus": 0, "total": 36.4 }, "orgs": [ { "org_id": "6ad7a4f2269dc8d9f75a41d0", "amount": 50, "bonus": 0, "total": 50 } ] }, { "period": "2026-11-02", "amount": 0, "bonus": 0, "total": 0, "personal": { "amount": 0, "bonus": 0, "total": 0 }, "orgs": [] } ], "summary": { "amount": 86.4, "bonus": 0, "total": 86.4, "personal": { "amount": 36.4, "bonus": 0, "total": 36.4 }, "orgs": [ { "org_id": "6ad7a4f2269dc8d9f75a41d0", "amount": 50, "bonus": 0, "total": 50 } ] }}{ "code": 0, "type": "org", "id": "6ad7a4f2269dc8d9f75a41d0", "date_from": "2026-10-01", "date_to": "2026-10-31", "group_by": "month", "currency": "RUB", "periods": [ { "period": "2026-10", "amount": 1240.75, "bonus": 0, "total": 1240.75, "users": [ { "user_id": "6ad72133269dc8d9f75a33bc", "amount": 900.5, "bonus": 0, "total": 900.5 }, { "user_id": "6ad8c0be269dc8d9f75a52e1", "amount": 340.25, "bonus": 0, "total": 340.25 } ] } ], "summary": { "amount": 1240.75, "bonus": 0, "total": 1240.75 }}Errors
Section titled “Errors”| HTTP | code | When |
|---|---|---|
| 400 | 3 | Identify exactly one client and use only supported fields. An ID must contain exactly 24 characters from 0-9a-f. Dates must exist and use YYYY-MM-DD. The period must be within the limit, and date_from cannot be later than date_to. Using by_user: true requires org_id. 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 | 40 | 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.