Skip to main content

Admin Billing — Python SDK

Admin-scope billing reports: Customer, Provider, and RS (Resource Service).

Overview​

The admin Billing resource exposes three billing report families, each with a paginated list and an aggregate total:

  • Customer Billing — spend rolled up by end-customer (bizUser)
  • Provider Billing — spend rolled up by upstream model provider
  • RS Billing — spend rolled up by resource service (fine-grained)

Customer and Provider Billing use full timestamps (start_time / end_time, YYYY-MM-DD HH:mm:ss); RS Billing uses date-only (start_date / end_date, YYYY-MM-DD).

Accessed via admin.billing.

Available Operations​

MethodDescription
customer_list()Customer Billing rows (paginated)
customer_total()Customer Billing aggregate total
provider_list()Provider Billing rows (paginated)
provider_total()Provider Billing aggregate total
rs_list()RS Billing rows (paginated)
rs_total()RS Billing aggregate total

customer_list​

Paginated Customer Billing rows for a time window.

Example Usage​

result = admin.billing.customer_list(
start_time="2026-06-01 00:00:00",
end_time="2026-06-30 23:59:59",
page_num=1,
page_size=20,
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_timestrYes--Window start, YYYY-MM-DD HH:mm:ss
end_timestrYes--Window end, YYYY-MM-DD HH:mm:ss
page_numintNo1Page number, starting from 1
page_sizeintNo10Items per page
user_idintNo--Filter to a single customer user id
user_namestrNo--Fuzzy filter by customer userName

Response​

Returns a dict with total, list, totalPages, currentPage, pageSize. Each row aggregates a customer's spend over the window.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid time-window or pagination
2007PermissionErrorAdmin lacks Billing permission
3001AuthenticationErrorSession expired and refresh failed

customer_total​

Aggregate Customer Billing total for a time window.

Example Usage​

total = admin.billing.customer_total(
start_time="2026-06-01 00:00:00",
end_time="2026-06-30 23:59:59",
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_timestrYes--Window start, YYYY-MM-DD HH:mm:ss
end_timestrYes--Window end, YYYY-MM-DD HH:mm:ss
user_idintNo--Filter to a single customer user id
user_namestrNo--Fuzzy filter by customer userName

Response​

Returns a dict with aggregate totals (pretaxAmount, afterDiscountAmount, currency, ...).

Errors​

Same as customer_list.

provider_list​

Paginated Provider Billing rows for a time window.

Example Usage​

result = admin.billing.provider_list(
start_time="2026-06-01 00:00:00",
end_time="2026-06-30 23:59:59",
page_num=1,
page_size=20,
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_timestrYes--Window start, YYYY-MM-DD HH:mm:ss
end_timestrYes--Window end, YYYY-MM-DD HH:mm:ss
page_numintNo1Page number, starting from 1
page_sizeintNo10Items per page
providerstrNo--Filter by provider id (e.g. dashscope)

Response​

Returns a dict with total, list, and pagination fields. Each row aggregates one provider's spend over the window.

Errors​

Same as customer_list.

provider_total​

Aggregate Provider Billing total for a time window.

Example Usage​

total = admin.billing.provider_total(
start_time="2026-06-01 00:00:00",
end_time="2026-06-30 23:59:59",
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_timestrYes--Window start, YYYY-MM-DD HH:mm:ss
end_timestrYes--Window end, YYYY-MM-DD HH:mm:ss
providerstrNo--Filter by provider id

Response​

Returns a dict with aggregate totals.

Errors​

Same as customer_list.

rs_list​

Paginated RS (Resource Service) Billing rows for a date range.

Example Usage​

result = admin.billing.rs_list(
start_date="2026-06-01",
end_date="2026-06-30",
page_num=1,
page_size=20,
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_datestrYes--Window start, YYYY-MM-DD
end_datestrYes--Window end, YYYY-MM-DD
page_numintNo1Page number, starting from 1
page_sizeintNo10Items per page
model_idstrNo--Filter by model id

Response​

Returns a dict with total, list, and pagination fields. Each row aggregates one resource-service's spend over the date range.

Errors​

Same as customer_list.

rs_total​

Aggregate RS Billing total for a date range.

Example Usage​

total = admin.billing.rs_total(
start_date="2026-06-01",
end_date="2026-06-30",
)

Parameters​

ParameterTypeRequiredDefaultDescription
start_datestrYes--Window start, YYYY-MM-DD
end_datestrYes--Window end, YYYY-MM-DD
model_idstrNo--Filter by model id

Response​

Returns a dict with aggregate totals.

Errors​

Same as customer_list.