Skip to main content

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

1

Open account settings

Log in to the LaoZhang API console and open account settings.
2

Open system token

Select “System Token” and complete the password verification flow shown in the console.
3

Save the AccessToken

Copy the token immediately after it is generated. Creating a new token may invalidate the previous token.
Do not expose the full AccessToken in source code, browser apps, logs, screenshots, or support tickets. For support diagnostics, provide the request time, HTTP status code, response message, and a redacted command only.

Endpoint

ItemValue
Endpoint URLhttps://api.laozhang.ai/api/user/self
MethodGET
AuthenticationAuthorization header
Request parametersNone
Response formatJSON; add --compressed when using cURL

Request

Headers

HeaderRequiredDescription
AuthorizationYesSystem AccessToken, passed directly as the header value
AcceptNoRecommended: application/json
Content-TypeNoRecommended: 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

{
  "success": true,
  "message": null,
  "data": {
    "id": 19489,
    "username": "demo_user",
    "display_name": "demo_user",
    "role": 1,
    "status": 1,
    "email": "",
    "quota": 24997909,
    "used_quota": 10027091,
    "request_count": 339,
    "group": "svip",
    "ModelFixedPrice": []
  }
}

Core Fields

FieldTypeDescription
successBooleanWhether the request succeeded
messageString / nullError message; usually null on success
data.usernameStringUsername
data.display_nameStringDisplay name
data.quotaIntegerCurrent remaining quota, suitable for alert thresholds
data.used_quotaIntegerUsed quota
data.request_countIntegerTotal request count
data.groupStringCurrent account group
data.ModelFixedPriceArrayModel pricing list; can be ignored when only checking balance
data.access_tokenStringSensitive field; do not write it to normal logs if returned
The response may include additional fields depending on the account state. Depend only on the fields your integration needs, and allow unknown fields so your parser does not fail when the response expands.

Quota And Balance Calculation

The quota field is returned in quota units, not directly in USD. Use this conversion for balance display:
ItemFormulaExample
Remaining USD balancequota ÷ 500K24997909 ÷ 500K = 49.995818, approximately 50.00 USD
Used USD amountused_quota ÷ 500K10027091 ÷ 500K = 20.054182, approximately 20.05 USD
Historical total amount(quota + used_quota) ÷ 500KApproximately 70.05 USD in the sample response
In other words, 500K quota is approximately 1 USD. If the API returns quota: 24997909, the current available balance is approximately 50.00 USD.
Use this formula for balance display. Actual model charges still depend on current model pricing, account group, usage logs, and console display. For production alerts, store both the raw quota value and the converted USD amount so diagnostics keep full precision.

Code Examples

export LAOZHANG_ACCESS_TOKEN='YOUR_ACCESS_TOKEN'

curl --compressed -s 'https://api.laozhang.ai/api/user/self' \
  -H 'Accept: application/json' \
  -H "Authorization: ${LAOZHANG_ACCESS_TOKEN}" \
  -H 'Content-Type: application/json'
--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

{
  "success": false,
  "message": "Unauthorized"
}
Common causes include an empty Authorization header, an incomplete token, an expired token, or using a regular API key instead of the system AccessToken.

HTTP 403 - Permission Denied

{
  "success": false,
  "message": "Forbidden"
}
Common causes include insufficient token permissions or an account state that needs support confirmation.

Garbled Response Or jq Error

If cURL returns garbled output or jq reports Invalid numeric literal, the gzip response was likely not decompressed. Add --compressed.

Monitoring Recommendations

  • Store LAOZHANG_ACCESS_TOKEN in 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, converted remaining_usd, used_quota, request_count, request time, and HTTP status in alerts
  • Do not log the full Authorization, access_token, or sensitive account fields