Skip to main content

Module usage

Module usage 

Source
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 five-hour time window (TIME_LIMIT) and a weekly token 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::client::ZaiClient;
use zai_rs::usage::CodingPlanUsageRequest;

let resp = CodingPlanUsageRequest::new().send_via(&client).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

Override the monitor family base on the ZaiClient builder:

use zai_rs::client::{ApiFamily, ZaiClient};
use zai_rs::usage::CodingPlanUsageRequest;

static INTL: &str = "https://api.z.ai/api/monitor";
let client = ZaiClient::builder("your-api-key")
    .endpoint(ApiFamily::Monitor, INTL)
    .build()?;
let resp = CodingPlanUsageRequest::new().send_via(&client).await?;

Structs§

CodingPlanQuotaLimit
One quota window reported by the monitor endpoint.
CodingPlanQuotaSummary
Easy-to-use quota-window view derived from CodingPlanQuotaLimit.
CodingPlanUsageData
data payload returned by the quota-limit endpoint.
CodingPlanUsageDetail
Per-model usage breakdown returned for some quota windows.
CodingPlanUsageRequest
Coding Plan usage / quota query request (GET /api/monitor/usage/quota/limit).
CodingPlanUsageResponse
Standard {code, msg, success, data} envelope used by the monitor API.
CodingPlanUsageSummary
Easy-to-use Coding Plan usage view.

Enums§

CodingPlanQuotaKind
Normalized quota-window kind.

Functions§

query
Query the Coding Plan usage endpoint via client and return the typed raw response.
query_summary
Query the Coding Plan usage endpoint via client and return a normalized summary.