Skip to main content

Short Answer

Use https://api2.laozhang.ai/api/user/self to query your LaoZhang API account balance. Generate a system AccessToken in account settings, pass it in the Authorization header, and add --compressed when using cURL so gzip responses are decoded correctly.

Read the full Balance Query API docs

For production monitoring, complete response fields, error handling, and code examples, use the developer API reference.

Get System Token (AccessToken)

Before calling the balance query API, you need to obtain a system token (AccessToken).
1

Go to Account Settings

After logging in, visit the Account Settings page and click on “System Token”.System Token Entry
2

Verify Account Password

Enter your account password in the popup dialog for identity verification.Password Verification
3

Get AccessToken

After successful verification, the system will display your AccessToken. Copy and save it immediately.Token Result
Security Warning:
  • AccessToken has full account permissions, keep it safe
  • Token is only displayed once when created, cannot be retrieved later
  • Generating a new Token will immediately invalidate the old one
  • Never hardcode in source code or commit to public repositories

API Reference

Endpoint Information

Request Headers

Response Fields

Successful response example:
Core fields:
The response may include additional fields depending on account state. Depend only on the fields your integration needs, such as quota, used_quota, request_count, and group, and allow unknown fields. If access_token or another sensitive field is returned, do not include it in regular logs or alert messages.

Quota And Amount Display

quota and used_quota are returned in quota units. For balance display, use 500K quota as approximately 1 USD:
  • Remaining USD balance: quota ÷ 500K
  • Used USD amount: used_quota ÷ 500K
  • Historical total amount: (quota + used_quota) ÷ 500K
For example, if the API returns quota: 24997909, the remaining balance is 24997909 ÷ 500K = 49.995818, approximately 50.00 USD.For alerts, store both the raw quota value and the converted USD amount. Actual model charges still depend on current model pricing, account group, usage logs, and console display.

Code Examples

Basic Request (must add --compressed option):
Important: You must add --compressed option because the API returns gzip compressed content, otherwise you’ll get garbled output.

Error Handling

HTTP 401 - Authentication Failed

Cause: Authorization token is invalid or expired Solution: Check and update your system token

HTTP 403 - Permission Denied

Cause: Current token doesn’t have permission to access this endpoint Solution: Contact admin to verify permission settings

FAQ

The quota field represents your current remaining balance (available quota). If quota is 0 or near 0, your account balance is insufficient and needs to be updated.
Use 500K quota as approximately 1 USD for balance display. The formula is: remaining USD balance = quota ÷ 500K; used USD amount = used_quota ÷ 500K.For example, quota: 24997909 means 24997909 ÷ 500K = 49.995818, approximately 50.00 USD. For production alerts, store both the raw quota value and the converted USD amount; actual model charges still follow the console pricing page, usage logs, and current account rules.
Cause: API returns gzip compressed content, curl doesn’t auto-decompress.Solution: Add --compressed option:
This usually happens because curl didn’t decompress the gzip content. Add --compressed option to fix it.
This field returns pricing information for various AI models. If you only care about balance info, you can ignore this field.
You can write a scheduled script to periodically query the balance, and send alert notifications (email, Slack, etc.) when quota falls below a threshold.

Notes

Security

  • Use environment variables for Token
  • Don’t commit to public repos
  • Rotate Token regularly

Rate Limits

  • Set reasonable timeout (10s recommended)
  • Avoid too frequent queries
  • Recommended interval ≥ 1 minute

Error Handling

  • Handle network errors and timeouts
  • Handle authentication failures
  • Log errors for troubleshooting

Response Format

  • API returns gzip compressed content
  • curl must add --compressed
  • requests library handles automatically