Skip to content

Extension crashes on Z.ai lite plans: weekly TOKENS_LIMIT (unit 6) not present #53

Description

@recurut001

Bug

The extension throws UsageError: Required TOKENS_LIMIT entries (5h + weekly) not found in API response when using a Z.ai lite plan.

Cause

Lite plans (level: "lite") only return two quota buckets:

  • TOKENS_LIMIT unit 3 (5-hour)
  • TIME_LIMIT unit 5 (monthly)

There is no weekly TOKENS_LIMIT (unit 6). The code in dist/api.js requires both:

if (!fiveHourLimit || !weeklyLimit) {
    throw new UsageError("Required TOKENS_LIMIT entries (5h + weekly) not found in API response", "nolimit");
}

API response (lite plan)

{
  "data": {
    "limits": [
      { "type": "TIME_LIMIT", "unit": 5, "percentage": 0 },
      { "type": "TOKENS_LIMIT", "unit": 3, "percentage": 11 }
    ],
    "level": "lite"
  }
}

Fix

Make weeklyLimit optional — same as monthlyLimit already is:

if (!fiveHourLimit) {
    throw new UsageError("Required TOKENS_LIMIT entry (5h) not found in API response", "nolimit");
}

And guard the weekly render block in dist/index.js:

if (data.weekly) { ... }

Environment

  • Extension version: 0.3.6 / 0.3.7
  • Plan: ZAI Coding Plan (Global), level: lite
  • Models: glm-4.5-air, glm-5v-turbo (all via zai provider)

Fork with fix: https://github.com/recurut001/pi-zai-usage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions