Freeze or unfreeze a client balance
Freezing and unfreezing
Section titled “Freezing and unfreezing”https://gptunnel.ru/api/v1/balance/setSpendBlockedBlocks 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
| 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. |
blocked* | boolean | Set true to freeze the account or false to unfreeze it. |
Example request
Section titled “Example request”Set GPTUNNEL_API_KEY and replace user_id with the ID of your test client.
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", "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))curl --request POST \ --url 'https://gptunnel.ru/api/v1/balance/setSpendBlocked' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "user_id": "6ad72133269dc8d9f75a33bc", "blocked": true}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "user_id": "6ad72133269dc8d9f75a33bc", "blocked": true}const response = await fetch("https://gptunnel.ru/api/v1/balance/setSpendBlocked", { 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 is a personal account of the user, org is an organization account |
id | string | User or organization ID |
spend_blocked | boolean | Account status after request: true — frozen |
changed | boolean | false, 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}{ "code": 17, "message": "Recipient not found."}Errors
Section titled “Errors”| 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.