Export billing records Export filtered billing records as an Excel file.
Filter by time range and optional API Key/model names. Success returns Excel; authentication, validation, or processing failures may return JSON business errors with HTTP 200. Check Content-Type and the response body.
token <token>
Billing authentication token, sent in the token Header without Bearer. In Try It, enter the system access token generated in personal settings; the billing credential is obtained automatically. Code examples show the full process.
In: header
TypeScript Definitions
Use the request body type in TypeScript.
Copy
cURL
JavaScript
Go
Python
Java
C#
Rustset -euo pipefail
ACCESS_TOKEN='your-user-token'
BILLING_TOKEN=$(curl --fail --silent --show-error "https://api.agtcloud.cn/api/user/self" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" | \
jq -er '
select(.success == true)
| .data.remark | fromjson | .token
| select(type == "string" or type == "number")
| tostring | select(length > 0)
')
response_file=$(mktemp './.bill_export.XXXXXX')
[[ "$response_file" == ./.bill_export.* && -f "$response_file" && ! -L "$response_file" ]] || exit 1
trap 'if [[ "$response_file" == ./.bill_export.* && -f "$response_file" && ! -L "$response_file" ]]; then rm -f -- "$response_file"; fi' EXIT
response_meta=$(curl --silent --show-error "https://api.agtcloud.cn/bill/excel" \
-X POST \
-H "token: ${BILLING_TOKEN}" \
-H 'Content-Type: application/json' \
-d '{
"type": 3,
"startTime": 1791561600,
"endTime": 1792511999
}' \
--output "$response_file" \
--write-out '%{http_code}\n%{content_type}')
http_status=${response_meta%%$'\n'*}
content_type=${response_meta#*$'\n'}
if [[ "$http_status" != 200 || "${content_type%%;*}" != application/vnd.openxmlformats-officedocument.spreadsheetml.sheet || ! -s "$response_file" ]]; then
printf 'Export failed: HTTP %s (%s)\n' "$http_status" "$content_type" >&2
if [[ "${content_type%%;*}" == application/json ]]; then
jq '{code, message}' "$response_file" >&2
fi
exit 1
fi
if [[ -e bill_export.xlsx || -L bill_export.xlsx ]]; then
printf 'bill_export.xlsx already exists; choose another filename.\n' >&2
exit 1
fi
mv -n -- "$response_file" bill_export.xlsx
if [[ -e "$response_file" ]]; then
printf 'bill_export.xlsx already exists; choose another filename.\n' >&2
exit 1
fi
printf 'Saved bill_export.xlsx\n' 200
Excel file (.xlsx) Save as .xlsx, not JSON. cURL can save it using --output bill_export.xlsx.