Skip to content

feat(providers): add ZCode (z.ai GLM-5.2) usage provider#537

Merged
iamtoruk merged 1 commit into
mainfrom
feat/zcode-provider
Jun 20, 2026
Merged

feat(providers): add ZCode (z.ai GLM-5.2) usage provider#537
iamtoruk merged 1 commit into
mainfrom
feat/zcode-provider

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

What

Adds CodeBurn support for ZCode, the z.ai CLI coding agent (GLM-5.2).

Where the data comes from

ZCode writes a single SQLite db at ~/.zcode/cli/db/db.sqlite. The model_usage table carries exact per-request token counts (input, output, reasoning, cache read/creation), model id, status, and timestamps. The JSONL activity log redacts token counts and the desktop app dir holds only Electron state, so the db is the only usable source.

No source records a dollar cost: GLM-5.2 runs on the z.ai start-plan subscription, so ZCode logs tokens only. Cost is computed from the pricing table, the same notional approach used for a Claude Max plan.

Notable details

  • Cached tokens are folded into input_tokens (OpenAI-style). The parser subtracts cache read and creation so fresh input bills at the input rate and cached at the cache-read rate. Verified against the nested Anthropic usage in provider_metadata_json (100 input = 36 fresh + 64 cached).
  • Tools come from tool_usage, which links to a turn rather than a specific request, so each turn's tools attach to one request to avoid double-counting. Bash command text is not stored, so bashCommands is empty.
  • GLM-5.2 is not in LiteLLM yet, so it is aliased to glm-5p1 (GLM-5.1 rate) in BUILTIN_ALIASES. Reports show it as glm-5p1, consistent with how every aliased model displays. Drop the alias once LiteLLM lists GLM-5.2.
  • Registered as a lazy provider (SQLite via node:sqlite), matching crush, cursor, and opencode.

Tests

  • New tests/providers/zcode.test.ts: discovery, token normalization plus pricing, and dedup.
  • Full suite green (1272 passing); typecheck clean.
  • Verified on a real ZCode session: 14 calls, 239,515 tokens, $0.104, hand-checked against the GLM-5.1 rate.

Files

  • src/providers/zcode.ts (new)
  • src/providers/index.ts (register lazy provider)
  • src/models.ts (GLM-5.2 pricing alias)
  • tests/providers/zcode.test.ts (new)
  • docs/providers/zcode.md (new) and docs/providers/README.md (index row)

Reads ZCode CLI usage from ~/.zcode/cli/db/db.sqlite. The model_usage
table has exact per-request tokens; cost is computed from the pricing
table since ZCode stores none (GLM-5.2 runs on the z.ai start-plan
subscription).

- Split cached tokens out of input_tokens (OpenAI-style) so fresh input
  and cache reads price correctly
- Attach each turn's tool calls to one request to avoid double-counting
- Map GLM-5.2 to glm-5p1 (GLM-5.1 rate) until LiteLLM lists it
- Register as a lazy SQLite provider; add test and provider doc
@iamtoruk iamtoruk merged commit 9ce6498 into main Jun 20, 2026
3 checks passed
@iamtoruk iamtoruk deleted the feat/zcode-provider branch June 20, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant