Skip to content

Freeze or unfreeze a client balance

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

Blocks or restores spending on a client account. For example, you can freeze spending while you process a contract termination or refund.

Specify exactly one field. Use user_id or user_data for a personal account, or org_id for an organization account. The freeze applies only to the specified account. Personal and organization accounts can be frozen independently.

While the account is frozen, the following rules apply.

  • New charges are blocked. GPTunneL rejects new generations in chat, Creative Lab, and the API, as well as outgoing transfers. The client sees a message that spending is blocked.
  • Top-ups and refunds still work. You can refund funds from a frozen account to recover the remaining balance.
  • Generations in progress are charged. If a response is already being generated when the freeze takes effect, it completes and the account is charged.
  • Spending history remains available. You can still retrieve client spending, including for past periods.
  • Clients retain dashboard access. They can sign in and view their chats, generations, and history.

Repeating a request with the same blocked value succeeds with changed: false. To read the current state, check spend_blocked in the response from balance/get or orgs/list.

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.
blocked*booleanSet true to freeze the account or false to unfreeze it.

Set GPTUNNEL_API_KEY and replace user_id with the ID of your test client.

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",
"blocked": True
}
request = Request(
"https://gptunnel.ru/api/v1/balance/setSpendBlocked",
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 is a personal account of the user, org is an organization account
idstringUser or organization ID
spend_blockedbooleanAccount status after request: true — frozen
changedbooleanfalse, if the account was already in this state and the request didn't change anything
{
"code": 0,
"type": "user",
"id": "6ad72133269dc8d9f75a33bc",
"spend_blocked": true,
"changed": true
}
HTTP code When
400 3 The request must identify exactly one client, include blocked, and 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 47 This endpoint is not enabled for the organization that owns the key.
404 12 The server does not support this endpoint. Ask support about availability.
404 17 User not found, deleted or not a customer of partner
404 24 Organization not found, deleted or not a customer of partner

See the Business API error reference for all error codes, including the 401 response for an invalid key.