API Overview
The Log Query API returns a detailed record of every API call made under your account, including the model used, the actual amount charged, latency, whether the call was streamed, and the error code when a call fails. It complements the Balance Query API: balance query tells you how much credit is left, log query tells you where it went. Three typical use cases:Automated reconciliation
Aggregate actual spend by time range or by model and reconcile it against your own billing
Self-service troubleshooting
Inspect error codes on failed requests to tell parameter problems from upstream problems
Support tickets
Provide the
request_id to support so they can pinpoint the exact callLogs are also viewable in the console under the Logs page. This API is the programmatic entry
point to the same data, intended for automated reconciliation, scheduled exports, or feeding
your own monitoring. For manual inspection, use the console — see
How to view my call records.
How to Get Your System Token
The Log Query API authenticates with a System Token, which is not the same thing as an API key (see Important Notes at the end of this page).1
Access Console
Visit
api.apiyi.com/account/profile to access your profile page2
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

API Information
Request Details
Request Headers
Query Parameters
Log Types
Response Details
Success Response Example
Key Response Fields
The
other field holds a JSON string, not a nested object, so it needs a second parse
(json.loads() in Python, JSON.parse() in JavaScript). It contains billing_type,
request_path (the endpoint actually called), group_ratio, model_ratio, and usage.Quota Conversion
Conversion Rule
500,000 quota = $1.00 USD
quota ÷ 500,000
Examples:
quota: 7500→ $0.015 USDquota: 22500→ $0.045 USDquota: 18→ $0.000036 USD
Error Responses
HTTP 401 - Authentication Failed
sk-) was
mistakenly used as a system token.
Solution: Regenerate the system token in the console, and make sure Authorization carries
the raw value without a Bearer prefix.
Code Examples
cURL Example (single page, quick check)
This command returns at most 10 records. For real reconciliation, use the paginated version below.
Python Example (paginated, ready to run)
Node.js Example (paginated)
Both the Python requests library and the Node.js fetch API decompress gzip automatically,
so no extra configuration is needed there. Only curl requires the explicit
--compressed flag.Common Scenarios
Calculating spend over a time range
Use the Python example above. The two things that matter are passingtype=2 and dividing the
summed quota by 500,000. To scope it to a single model, add the model_name parameter.
Finding failed calls
Requests rejected by the gateway (invalid parameters and similar) have
quota of 0 and
are not charged. The error_code in the log lets you separate “the call failed” from
“the call succeeded but I did not like the result.”Providing a request ID for support
Locate the problematic call in the logs and give support therequest_id. That identifies the
exact request end to end, which is far more efficient than describing “a call to some model
failed around a certain time.”
FAQ
Why do I only get 10 records?
Why do I only get 10 records?
The server-side cap on
page_size is 10. Larger values do not error but do not take effect
either. To retrieve more you must paginate (p=0, p=1, p=2 and so on) until the response
returns an empty array. The Python and Node.js examples above already encapsulate this.Some fields in the response are empty — is something wrong?
Some fields in the response are empty — is something wrong?
No. Certain fields hold platform-internal information and are empty or zero from a regular
account’s perspective. This is expected and does not affect the fields you need for
reconciliation or troubleshooting —
quota, model_name, error_code, and request_id
are all fully populated.Why does token_group differ from the group name shown in the console?
Why does token_group differ from the group name shown in the console?
The API returns the group identifier, while the console displays the group’s label.
These can differ — for example the API returns
default while the console shows Default.The full mapping is available from the public endpoint https://api.apiyi.com/api/pricing
under the usable_group field, which maps identifier to label. If you want your reports to
match the console, apply that mapping yourself.How far back can I query?
How far back can I query?
Specify any range with
start_timestamp and end_timestamp. For the exact retention period
of historical data, please contact support. We recommend exporting reconciliation data
periodically rather than relying on the API for long-term lookback.curl returns garbled text, or jq throws an error
curl returns garbled text, or jq throws an error
Reason: the API returns gzip-compressed content (The Python requests library and the Node.js fetch API decompress automatically.
Content-Encoding: gzip) and curl is
not decompressing it.Solution: add the --compressed flag:Does querying logs consume quota?
Does querying logs consume quota?
No. The log query endpoint does not consume any quota.
Important Notes
Request limits
- Keep at least 1 second between queries to avoid rate limiting
- Set a reasonable request timeout (30 seconds recommended)
- For wide time ranges, implement pagination and retry handling
Related Documentation
- Balance Query API — check remaining account credit
- Token Management API — create and manage API keys programmatically
- How to view my call records — manual inspection in the console
- Understanding logs and billing — how to read the billing fields