Skip to main content

Module zai

Module zai 

Source
Expand description

The Zai backend: the GLM coding plan’s monitor probe against {host_root}/api/monitor/usage/quota/limit, authenticated by the account’s flat token stamped onto ANTHROPIC_AUTH_TOKEN (no Bearer prefix). The configured base url carries the /api/anthropic chat prefix, so the monitor URL derives from the scheme+host alone. Every Z.ai monitor endpoint answers HTTP 200 regardless of outcome - a wrong key and a wrong path share the status with a healthy response - so the verdict lives inside the {success, code, msg} envelope.

Re-exports§

use std::time::SystemTime; 🔒
use async_trait::async_trait; 🔒
use reqwest::header::ACCEPT; 🔒
use reqwest::header::AUTHORIZATION; 🔒
use reqwest::header::HeaderMap; 🔒
use reqwest::header::HeaderValue; 🔒
use forge_primitives::usage::oauth::OauthUsageError; 🔒
use forge_primitives::usage::zai::QuotaLimitData; 🔒
use forge_primitives::usage::zai::QuotaLimitEntry; 🔒
use forge_primitives::usage::zai::QuotaLimitResponse; 🔒
use forge_primitives::usage::UsageSnapshot; 🔒
use forge_primitives::usage::UsageSourceKind; 🔒
use forge_primitives::usage::UsageWindow; 🔒
use crate::helpers::BaseUrlCredential; 🔒
use crate::helpers::MissingBase; 🔒
use crate::helpers::OAUTH_TIMEOUT; 🔒
use crate::helpers::base_url_credential; 🔒
use crate::helpers::redacted_body; 🔒
use crate::helpers::redacted_message; 🔒
use crate::helpers::system_time_from_epoch; 🔒
use crate::AccountEnv; 🔒
use crate::BillingModel; 🔒
use crate::ProbeError; 🔒
use crate::Provider; 🔒
use crate::ProviderBackend; 🔒
use crate::ProviderHost; 🔒

Structs§

Zai
The Zai [[accounts]] provider token.

Enums§

Mapper 🔒

Functions§

choose_mapper 🔒
The mapper the account’s env earns, paired with the credential that earns it: the base-url pair earns the monitor mapper, and a missing base url carries its error to the probe’s Unmappable surface. Pure so the routing stays unit-pinned - the probe cannot be driven against the network offline.
monitor_headers 🔒
monitor_host 🔒
The scheme+host of an account’s ANTHROPIC_BASE_URL - everything before the first path segment. The Z.ai monitor paths live off the site root (https://api.z.ai), never under the /api/anthropic chat prefix the base carries.
monitor_probe 🔒
One round-trip against {host_root}/api/monitor/usage/quota/limit for a Z.ai GLM coding plan account. Shares OauthUsageError with the window probes so the loader and poller classify failures the same way regardless of provider.
monitor_url 🔒
quota_from_body 🔒
Parse a Z.ai monitor body. The HTTP layer carries no verdict - a wrong key and a wrong path arrive as HTTP 200 - so the envelope is decoded unconditionally and keyed on success/code. A body-level 401 (wrong key) surfaces as OauthUsageError::Unauthorized so it bails the boot probe like a real auth rejection; every other failure keeps the envelope’s msg.
snapshot_from_zai_quota 🔒
Map a Z.ai quota-limit payload into a forge_primitives::usage::UsageSnapshot.
window_from_entry 🔒