Skip to main content

API Overview

The Balance Query API retrieves your account’s current quota usage, including total quota, used quota, remaining balance, and request count. This API helps you easily monitor your account balance, enabling proactive and flexible balance alert management.

How to Get Authorization Token

1

Access Console

Visit api.apiyi.com/account/profile to access your profile page
2

Find System Token

Locate the “Account Options - System Token” section at the bottom of the page
3

Generate AccessToken

Enter your account password to receive an AccessToken that can be used for subsequent API queries
Get System Token

API Information

Request Details

Request Headers

Request Parameters

This is a GET request and does not require any request body parameters.

Response Details

Success Response Example

Key Response Fields

Quota Conversion

Conversion Rule

500,000 quota = $1.00 USD
Calculation Formulas:
  • USD amount = quota ÷ 500,000
  • Remaining quota = quota (quota represents current remaining balance)
  • Remaining USD = quota ÷ 500,000
Examples:
  • quota: 24997909 → $49.99 USD (current remaining balance)
  • used_quota: 10027091 → $20.05 USD (used amount)

Error Responses

HTTP 401 - Authentication Failed

Reason: Authorization token is invalid or expired Solution: Verify and update your API token

HTTP 403 - Permission Denied

Reason: Current token lacks permission to access this API Solution: Contact administrator to verify permission settings

Code Examples

cURL Example

Important: The --compressed option is required because the API returns gzip-compressed content, otherwise you’ll receive garbled output.
Quick Test (replace YOUR_TOKEN_HERE):
Note: The -s option hides progress bar, --compressed automatically decompresses gzip response

Python Example (Basic)

Python Example (Optimized)

We provide a complete optimized script quota_optimized.py with the following features:

Error Handling

Complete exception handling and error capture

Environment Variables

Secure token management, avoid hardcoding

Formatted Output

Beautiful table display and number formatting

Auto Conversion

Automatic USD amount calculation
Usage:
Output Example:

FAQ

Please refer to the “How to Get Authorization Token” section above, or visit the profile page in the console to obtain a system token.
No, the balance query API does not consume your quota.
We recommend a query interval of at least 1 second to avoid triggering rate limits.
This field returns pricing information for various AI models. You can ignore it if you only need balance information.
The quota field represents the current remaining balance. If quota is 0 or close to 0, your account balance is insufficient and needs recharging.
Issue: Executing curl returns garbled text, or jq reports “Invalid numeric literal”Reason: The API returns gzip-compressed content (Content-Encoding: gzip), and curl doesn’t automatically decompress it.Solution: Add the --compressed option to make curl decompress automatically:

Important Notes

Security Reminders
  • Never hardcode Authorization tokens in your code
  • Use environment variables or configuration files to manage sensitive information
  • Don’t commit code containing tokens to public repositories
Request Limits
  • Set reasonable request timeout (recommended: 10 seconds)
  • Avoid excessively frequent query requests

Exception Handling Recommendations

  • Always handle network exceptions, timeouts, and authentication failures
  • Log errors for easier troubleshooting

Response Format Notes

  • API returns gzip-compressed content; curl requires the --compressed option
  • Python’s requests library automatically handles gzip decompression without additional configuration