How to Reconcile AI API Cost and Failures from Usage Records
A daily AI API report becomes unreliable when it answers only one question: “How much did we spend?” Operations teams also need to know which requests failed, whether those failures consumed billable usage, whether aggregate totals agree with request-level evidence, and whether the application balance moved as expected.
That is a reconciliation problem, not merely a dashboard problem.
This guide presents a concrete daily workflow using AceDataCloud usage records, aggregate usage, CSV exports, and application balance data. It stays focused on evidence and reporting. Credential issuance and access governance are separate concerns.
¶ What a reconciled daily report should prove
A useful report should connect four layers of evidence:
- Aggregate totals for the reporting window.
- Individual request records for failures and outliers.
- A bounded export that can be archived or loaded into an internal reporting system.
- Application balance context that explains the operational effect of the day’s usage.
No single layer is sufficient on its own. Aggregates are efficient but hide individual traces. Request records are detailed but require pagination and can be expensive to process at scale. Exports are portable but must be checked for truncation. A balance is operationally important, but it does not explain which requests produced the movement.

¶ The fields that matter
AceDataCloud retains API usage records and billing summaries for the most recent 60 days. Request and response bodies are retained for 30 days, so investigations of older records may still have status and billing data without full request or response payloads.
For daily reconciliation, the most useful request-level fields are:
| Field | Reconciliation purpose |
|---|---|
created_at |
Places the request inside the reporting window |
application_id |
Identifies the application charged or associated with the call |
api_id |
Groups requests by endpoint |
credential_id |
Attributes activity to a workload when needed |
model |
Separates model-level consumption where populated |
status_code |
Distinguishes successful and failed HTTP outcomes |
trace_id |
Provides a request-level investigation key |
used_amount |
Records usage under the applicable calculation |
original_amount |
Preserves the amount before application discounts where applicable |
deducted_amount |
Shows the final amount deducted |
remaining_amount |
Captures the post-request application balance reported on the record |
elapsed |
Helps identify latency outliers |
Do not assume these amounts are US dollars. Application and service records expose a unit, and reconciliation should preserve that unit in every report.
¶ Define the daily boundary first
Use an explicit timezone and half-open interval:
[start_of_day, start_of_next_day)
For example, a UTC report for 2026-11-24 should query from 2026-11-24T00:00:00Z up to, but not including, 2026-11-25T00:00:00Z.
This avoids double-counting midnight records when reports are rerun. Store both the business timezone and the equivalent UTC bounds in the report metadata.
Also select the correct perspective:
billingfor calls paid for by the current account;actorfor calls initiated by the current account;bothfor the union.
A finance-oriented report should normally begin with billing. An operational report investigating what the account initiated may need actor. Mixing these perspectives silently can create unexplained differences.
¶ Step 1: Pull the aggregate control total
Start with the aggregate usage endpoint for the exact reporting window. Aggregate by day for the top-line total, then by API and model for the breakdown used in the report.
The purpose of this step is to establish a compact control total before examining individual records. Capture at least:
- reporting window;
- perspective;
- aggregate amount;
- unit;
- request count where returned;
- API and model breakdowns;
- time the report was generated.
Treat this result as the daily control total, not as proof that every request succeeded.
¶ Step 2: Enumerate status codes before choosing filters
AceDataCloud provides a status-code listing for usage visible to the caller. Use it to discover the codes present in the reporting window rather than assuming every failure is a 4xx or 5xx response.
Then query request records for non-success codes and any success codes that your application treats as incomplete. A production report should keep transport outcome and business outcome separate. An HTTP success response can still contain an unsuccessful asynchronous task, while a failed request does not automatically imply a deduction of zero.
For each failed or anomalous record, retain:
- timestamp;
- API and model;
- status code;
- trace ID;
- elapsed time;
- used, original, and deducted amounts;
- remaining amount;
- a short classification such as authentication, quota, validation, provider, timeout, or unknown.
Classifications should come from verified response evidence or documented error contracts. Do not infer a cause from the status code alone.
¶ Step 3: Page through request records deterministically
The usage list is paginated. Use a fixed ordering, narrow time bounds, and stable filters. Daily windows are preferable to broad monthly scans.
A safe extraction pattern is:
window = {
"created_at_from": start_utc,
"created_at_to": end_utc,
"perspective": "billing",
"ordering": "-created_at",
"limit": 100,
}
offset = 0
records = []
while True:
page = get_usage_records(**window, offset=offset)
records.extend(page["items"])
if offset + len(page["items"]) >= page["count"]:
break
offset += len(page["items"])
In real code, use the documented API contract and handle authentication, timeouts, and response validation. If the platform returns usage_query_in_progress, follow its retry guidance instead of launching identical concurrent queries. If a query times out, narrow the window or add application, API, credential, or status filters.
¶ Step 4: Reconcile aggregates against request-level sums
Build a request-level ledger keyed by the usage record ID and trace ID. Sum the amount field that corresponds to the question being asked:
- use
deducted_amountfor the amount actually deducted; - use
original_amountto analyze pre-discount usage; - retain
used_amountas the usage calculated under the original rule recorded for that call.
Do not substitute one for another simply because all three are numeric.
Compare the request-level sum with the aggregate control total for the same:
- time bounds;
- perspective;
- API filter;
- account scope;
- unit.
If totals differ, investigate in this order:
- Timezone or boundary mismatch.
- Different billing versus actor perspective.
- Missing pagination.
- Different amount fields.
- Late-arriving or updated records.
- Filters applied to only one side.
- Unit mismatch.
Record the variance even when it is zero. A report that omits its reconciliation result cannot demonstrate that the check occurred.
¶ Step 5: Export a portable evidence file
Use the CSV export for the same bounded window and filters. The export is useful for archival, finance review, or loading into a warehouse, but it is not enough to call the endpoint and save whatever arrives.
Validate:
- the returned byte size against the requested maximum;
- any truncation or error markers documented by the endpoint;
- the header schema;
- row count against the paginated list where comparable;
- earliest and latest timestamps;
- the hash of the saved file.
If the export exceeds its bound, split the extraction by day, application, API, or status. Never label a partial file as a complete daily ledger.
A suitable archive name is:
usage-billing-2026-11-24T000000Z-2026-11-25T000000Z.csv
Store a small manifest beside it containing the query parameters, generation timestamp, row count, byte size, and checksum.
¶ Step 6: Add application balance context
Retrieve the application record after the usage extraction. Capture:
remaining_amount;used_amountwhere available;- service unit;
- disabled status;
- expiry;
- any documented balance freshness caveat relevant to the service type.
The balance is a context check, not a replacement for usage reconciliation. A positive remaining amount does not by itself prove the service is available, and a balance movement should not be reconstructed from only the first and last request unless the documentation guarantees that interpretation.
For proxy services, stored balances may be stale if synchronization pauses or times out. Mark balance freshness as unknown rather than presenting the last stored value as real-time.
¶ A daily report structure that operators can use
A concise report can use five sections:
¶ 1. Control totals
| Metric | Value |
|---|---|
| Window | Explicit UTC bounds |
| Perspective | Billing, actor, or both |
| Total deducted amount | Value plus unit |
| Request count | Count |
| Failed request count | Count |
| Reconciliation variance | Aggregate minus request-level sum |
¶ 2. Breakdown
Show usage by API and model. Keep the unit visible in every table.
¶ 3. Failure ledger
List status, API, model, trace ID, elapsed time, deducted amount, and verified classification.
¶ 4. Balance context
Show remaining amount, unit, disablement, expiry, and freshness caveat.
¶ 5. Evidence manifest
Record the API filters, CSV filename, row count, byte size, checksum, and generation timestamp.
This format makes the report useful to engineering, finance, and support without forcing every reader to inspect raw payloads.
¶ What not to conclude
Usage records can support strong operational conclusions, but only within their documented scope.
Do not claim:
- that every failed request was free;
- that every successful HTTP response produced a successful downstream task;
- that a positive balance proves service health;
- that old records still contain request and response bodies after the body-retention period;
- that a CSV is complete without checking its limit and markers;
- that Credits, counts, tokens, and currency values are interchangeable.
Where evidence is missing, use unknown rather than forcing a pass or fail.
¶ How this fits AceDataCloud operations
AceDataCloud exposes usage listing, aggregation, export, and application balance as separate management surfaces. That separation is useful because each surface answers a different question:
- aggregation answers “what is the control total?”;
- records answer “which calls produced it?”;
- export answers “what evidence can we retain?”;
- application detail answers “what is the current operating context?”
A trustworthy daily report joins those answers without pretending they are the same dataset.
¶ Conclusion
Daily API reporting should be reproducible, bounded, and explainable. Begin with one exact time window and perspective, establish an aggregate control total, inspect request-level failures, reconcile the appropriate amount fields, validate the export, and add balance context with its unit and freshness caveats.
The result is more than a spend chart. It is a compact evidence package that can explain cost, failures, variance, and remaining capacity without relying on assumptions.

