1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! # 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
//!
//! ```rust,no_run
//! use zai_rs::client::ZaiClient;
//! use zai_rs::usage::CodingPlanUsageRequest;
//!
//! # async fn go(client: ZaiClient) -> zai_rs::ZaiResult<()> {
//! 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
//! );
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Switching to the international endpoint
//!
//! Override the monitor family base on the [`ZaiClient`] builder:
//!
//! ```rust,no_run
//! use zai_rs::client::{ApiFamily, ZaiClient};
//! use zai_rs::usage::CodingPlanUsageRequest;
//!
//! # async fn go() -> zai_rs::ZaiResult<()> {
//! 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?;
//! # Ok(())
//! # }
//! ```
pub use ;
use crate::;
/// Query the Coding Plan usage endpoint via `client` and return the typed raw
/// response.
pub async
/// Query the Coding Plan usage endpoint via `client` and return a normalized
/// summary.
pub async