Overview
The Balance Query API returns the current account quota, used quota, request count, and account group. Use it for backend monitoring, low-balance alerts, billing diagnostics, and internal operations dashboards.This endpoint uses a system AccessToken, not the regular API key used for model calls. The AccessToken has broader account permissions, so keep it on the server side and store it in environment variables or a secrets manager.
Get Authorization
Open account settings
Log in to the LaoZhang API console and open account settings.
Open system token
Select “System Token” and complete the password verification flow shown in the console.
Endpoint
| Item | Value |
|---|---|
| Endpoint URL | https://api.laozhang.ai/api/user/self |
| Method | GET |
| Authentication | Authorization header |
| Request parameters | None |
| Response format | JSON; add --compressed when using cURL |
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | System AccessToken, passed directly as the header value |
Accept | No | Recommended: application/json |
Content-Type | No | Recommended: application/json |
Parameters
This endpoint does not require query parameters or a request body. Keep alert thresholds, business labels, and notification channels in your monitoring configuration rather than in the endpoint URL.Response
Successful Response
Core Fields
| Field | Type | Description |
|---|---|---|
success | Boolean | Whether the request succeeded |
message | String / null | Error message; usually null on success |
data.username | String | Username |
data.display_name | String | Display name |
data.quota | Integer | Current remaining quota, suitable for alert thresholds |
data.used_quota | Integer | Used quota |
data.request_count | Integer | Total request count |
data.group | String | Current account group |
data.ModelFixedPrice | Array | Model pricing list; can be ignored when only checking balance |
data.access_token | String | Sensitive field; do not write it to normal logs if returned |
Quota And Balance Calculation
Thequota field is returned in quota units, not directly in USD. Use this conversion for balance display:
| Item | Formula | Example |
|---|---|---|
| Remaining USD balance | quota ÷ 500K | 24997909 ÷ 500K = 49.995818, approximately 50.00 USD |
| Used USD amount | used_quota ÷ 500K | 10027091 ÷ 500K = 20.054182, approximately 20.05 USD |
| Historical total amount | (quota + used_quota) ÷ 500K | Approximately 70.05 USD in the sample response |
500K quota is approximately 1 USD. If the API returns quota: 24997909, the current available balance is approximately 50.00 USD.
Code Examples
- cURL
- jq Extract
- Python
- Node.js
--compressed tells cURL to decompress gzip responses. Without it, the terminal may show garbled output and jq may report Invalid numeric literal.Error Responses
HTTP 401 - Authentication Failed
Authorization header, an incomplete token, an expired token, or using a regular API key instead of the system AccessToken.
HTTP 403 - Permission Denied
Garbled Response Or jq Error
If cURL returns garbled output orjq reports Invalid numeric literal, the gzip response was likely not decompressed. Add --compressed.
Monitoring Recommendations
- Store
LAOZHANG_ACCESS_TOKENin environment variables or a secrets manager - Set a reasonable timeout, such as 10 seconds
- Avoid high-frequency polling; balance monitoring usually does not need second-level checks
- Include
quota, convertedremaining_usd,used_quota,request_count, request time, and HTTP status in alerts - Do not log the full
Authorization,access_token, or sensitive account fields
Related Docs
- For the FAQ version, see How to Query Account Balance via API
- If requests fail even with remaining quota, see Insufficient Balance
- To inspect per-request model, token, and billing records, see Usage Logs