Skip to content

Read client spending by period

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

Returns client spending in rubles for the requested period, grouped by day or month. Identify the client using exactly one of the following fields.

  • user_id includes the user’s spending from their personal account and from the accounts of the partner’s client organizations where they work.
  • org_id includes spending by all employees from the specified 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.

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

ParameterTypeDescription
Authorization*stringOrganization API key
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.
date_from*stringFirst day of the period, in YYYY-MM-DD format (inclusive)
date_to*stringLast day of the period, in YYYY-MM-DD format (inclusive). Must be on or after date_from.
group_bystringday (default) or month
by_userbooleanSet 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".

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

Response fields

ParameterTypeDescription
codenumber0 on success
typestringuser or org - for which the report is built
idstringUser or organization ID
date_fromstringStart of period from request
date_tostringEnd of period from request
group_bystringday or month
currencystringAlways RUB
periodsarrayOne entry per day or month in chronological order. Periods without spending are included with zero amounts.
summaryobjectTotals for the entire date range, with the same fields as each periods entry except period and users.

One period (periods)

ParameterTypeDescription
periodstringYYYY-MM-DD for the day group, YYYY-MM by month
amountnumberSpent rubles. Negative if returns are higher than write-offs during the period
bonusnumberBonus points spent. One point is worth 0.5 RUB.
totalnumberTotal in rubles, including amount and the ruble value of bonus points spent
personalobjectFor user only: personal account expenditures - amount, bonus, total
orgsarrayReturned only for a user. Spending from organization accounts includes org_id, amount, bonus, and total. Sorted by total in descending order.
usersarrayReturned 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 }
]
}
}
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.