Skip to content

Add Zcode provider: local usage tracking from ~/.zcode/cli/db/db.sqlite #1240

Description

@Alenryuichi

Provider Name

Zcode

Provider Website

https://zcode.z.ai

What usage data does this provider expose?

  • Per-request token breakdown: input / output / cache read / cache write
  • Source: local SQLite at ~/.zcode/cli/db/db.sqlite, table model_usage (one row per model request, with started_at, model_id, and the full token breakdown)
  • Auth method: none — no login, no API key, no network call. OpenUsage opens the database read-only.
  • ZCODE_HOME is honored; every *.sqlite under <home>/cli/db is read, so a future sharded store works without an update.

This would measure one thing: how much did this machine actually run through Zcode? It is a local traffic report, not a subscription balance, so it complements the existing Z.ai card (which covers plan quotas) rather than overlapping it.

Will you build the provider?

Yes, I will submit a PR

Additional Context

The implementation is already finished on my fork branch Alenryuichi/openusage@feat/zcode-provider (1 commit, 18 files, +821/-11), ready to go as soon as this is approved:

  • New module Sources/OpenUsage/Providers/Zcode/ following the OpenCode local-SQLite pattern (ZcodePaths, ZcodeUsageScanner, ZcodeProvider, ZcodeUsageError), registered in the provider catalog and default layout.
  • 21 new unit tests; full suite passes (TZ=UTC swift test, 1334 tests).
  • docs/providers/zcode.md, plus updates to the docs pages that enumerate providers.

One finding worth flagging because it affects correctness: Zcode's input_tokens already includes cache-read and cache-write tokens. I verified this against the raw providerMetadata.anthropic.usage object in Zcode's own rollout logs. Pricing that column as-is double-charges cached tokens — on my machine today that is 12,250,372 tokens naive vs. 6,470,340 correct (~$0.98). The scanner deducts the cache buckets before billing the remainder at the input rate.

Happy to adjust scope or naming to match the project's conventions. If this fits, could you please label it approved and assign it to me?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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