Expand description
§Coding Plan Usage / Quota Query
Query the remaining quota and consumption statistics for the GLM Coding
Plan via the monitor API GET /api/monitor/usage/quota/limit.
The Coding Plan applies two quota windows — a per-5-hour time window
(TIME_LIMIT) and a weekly tokens window (TOKENS_LIMIT) — and reports the
configured cap, consumed percentage, and next reset time for each. This
module surfaces them as strongly-typed CodingPlanUsageResponse.
Verified against the official glm-plan-usage plugin
(https://docs.bigmodel.cn/cn/coding-plan/extension/usage-query-plugin)
and the community CLI https://github.com/JinHanAI/coding-plan-monitor.
§Quick start
use zai_rs::usage::CodingPlanUsageRequest;
let resp = CodingPlanUsageRequest::new(key).send().await?;
let usage = resp.summary();
if let Some(five_hour) = usage.time_limit() {
tracing::info!(
"5h window: {}/{} used ({} remaining, {}%), resets at {}",
five_hour.used,
five_hour.quota,
five_hour.remaining,
five_hour.percentage,
five_hour
.next_reset_at
.as_ref()
.map_or_else(|| "?".to_string(), |datetime| datetime.to_rfc3339())
);
}
if let Some(weekly) = usage.tokens_limit() {
tracing::info!(
"weekly tokens: {} remaining of {}",
weekly.remaining,
weekly.quota
);
}§Switching to the international endpoint
use zai_rs::usage::CodingPlanUsageRequest;
let resp = CodingPlanUsageRequest::new(key)
.with_monitor_base("https://api.z.ai/api/monitor")
.send()
.await?;Re-exports§
pub use data::CodingPlanQuotaKind;pub use data::CodingPlanQuotaLimit;pub use data::CodingPlanQuotaSummary;pub use data::CodingPlanUsageData;pub use data::CodingPlanUsageDetail;pub use data::CodingPlanUsageRequest;pub use data::CodingPlanUsageResponse;pub use data::CodingPlanUsageSummary;
Modules§
- data
- Coding Plan usage / quota query client.
Functions§
- query
- Query the Coding Plan usage endpoint and return the typed raw response.
- query_
summary - Query the Coding Plan usage endpoint and return a normalized summary.