This endpoint uses a system AccessToken, not the API key you use for model requests. An AccessToken has broader account permissions, so keep it on your server in an environment variable or a secrets manager.
Get an AccessToken
1
Open account settings
Sign in to the console and open account settings.
2
Open the system token dialog
Select System Token, then enter your account password when the console asks for it.
3
Copy the AccessToken
Copy the AccessToken as soon as it appears and store it securely. Generating a new AccessToken may invalidate the previous one, so update every service that uses it.
Endpoint
Authorization value, as the examples below do. Accept: application/json and Content-Type: application/json are optional. With cURL, --compressed is recommended so that the response is decompressed.
Response
A successful request returns:
The response can include other fields, depending on the account. Read only the fields you need, and let your parser ignore unknown ones.
Convert quota to US dollars
quota and used_quota are returned in quota units, not dollars. 500,000 quota units are about 1 USD.
Use this conversion for display. What a request actually costs depends on the model price, your token group, and the charge shown in call logs. For alerts, store the raw
quota together with the converted amount so that you keep full precision.
Code examples
Set the AccessToken in your terminal once, replacing the placeholder:- cURL
- cURL with jq
- Python
- Node.js
--compressed, the terminal can show garbled output, and jq can report Invalid numeric literal.Errors
401 Unauthorized
Authorization header is empty, the AccessToken is incomplete or no longer valid, or the request sent a model API key instead of the AccessToken. Fix a 401 from the balance API walks through each cause.
403 Forbidden
Garbled output or a jq error
If cURL prints garbled characters orjq reports Invalid numeric literal, the compressed response was not decoded. Add --compressed to the cURL command.
Monitoring recommendations
- Store
LAOZHANG_ACCESS_TOKENin an environment variable or a secrets manager. - Set a request timeout, such as 10 seconds.
- Poll at a modest interval; balance alerts rarely need per-second checks.
- Include
quota, the converted balance,used_quota,request_count, the request time, and the HTTP status in alerts. - Never log the
Authorizationheader,access_token, or other sensitive account fields.