Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(usage): add OpenCode provider priced from models.dev #6014

ClosedSkyVence(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromrefs/pull/6014/headopened View on GitHub

Problem

The usage page only scanned Claude Code and Codex transcripts, so sessions driven through OpenCode never showed up — no tokens, no cost, and no visibility into what the go/zen subscriptions are actually being billed.

Fix

  • Read OpenCode's SQLite session store (~/.local/share/opencode/opencode.db) with node:sqlite and fold its assistant messages into the daily usage scan (provider: "opencode").
  • Price go/zen models from models.dev (merged over the LiteLLM table). OpenCode messages carry the real billed cost, so buckets use providerReported cost; the models.dev go/zen rates back the fallback and cache-savings figures.
  • Model names stay qualified as providerID/modelID, so the go and zen subscriptions never collapse — e.g. deepseek-v4-flash is $0.07 vs $0.14 per 1M tokens across the two tiers.
  • Add OpenCode to the provider rows, chart legend, and day table on web and mobile.
  • USAGE_CONTRACT_VERSION bumped to 4; the scan cache gained a WAL sidecar identity so a live OpenCode session is never served stale.

Screenshots

Before/after images of the usage page (no OpenCode usage → OpenCode provider with go/zen models) usage-before

usage-after

Done by opencode (deepseek-v4-flash) on the T3 Code worktree.

Note

Add OpenCode as a usage provider with pricing from models.dev

  • Adds opencode as a new provider kind in the contract, UI, and server, reading usage from OpenCode's SQLite store (opencode.db) instead of JSONL files.
  • Fetches and caches OpenCode model pricing from models.dev via a new ensureOpenCodeRates function, merging it with existing LiteLLM rates via mergeRateTables.
  • Resolves OpenCode's data directory from OPENCODE_DATA_DIR, XDG_DATA_HOME, or platform-specific defaults, and includes WAL sidecar identity in the scan cache to avoid stale reads.
  • Displays OpenCode usage in violet (#a78bfa) with the OpenCodeIcon mark in both web and mobile usage charts.
  • Risk: bumps scan cache version from 2 to 3, invalidating existing v2 caches on first run.
Macroscope summarized c88952e.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: ee04446b-efa0-4fc2-8d51-9bcc27decb04

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. One convention issue found in the new server test: the UsageService module is imported with an aliased named import instead of a module namespace. Everything else in the diff (dependency acquisition via HostProcessEnvironment/HostProcessPlatform, make/layer shape, test-only provideService seams) follows the service conventions.

      Posted via Macroscope — Effect Service Conventions
    4. You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR adds OpenCode as a new usage provider, introducing substantial new capability including external API integration (models.dev), SQLite database reading for OpenCode's session store, new parsing logic, and UI changes. New features with this scope warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. One finding in apps/server/src/usage/UsageService.ts: the rate-table rename left a stale rates shorthand in the UsageAggregator construction. No Effect service convention violations found in the rest of the changed scope (namespace imports, service tag/make/layer order, dependency acquisition, and test seams all look consistent with the conventions).

      Posted via Macroscope — Effect Service Conventions
      @@ -340,7 +465,13 @@
      340465 const windowStartMs =
      341466 (hourlyWindow?.sinceTimeMs ?? DateTime.toEpochMillis(windowStart.value)) - MTIME_SLACK_MS;
      342467
      468+ // Always re-compose the served table, regardless of which source refreshed
      469+ // this pass: a LiteLLM refresh on its own clock must not drop the still
      470+ // valid OpenCode go/zen overlay (and vice versa).
      471+ const servedRates = mergeRateTables(litellmRates, openCodeRates);
      472+
      343473 const aggregator = new UsageAggregator({
      344474 timeZone: input.timeZone,
      345475 sinceDay: input.sinceDay,
      346476 untilDay: input.untilDay,
      477+ rates: servedRates,
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      rates was renamed to litellmRates in this PR, but the aggregator options still carry the old rates shorthand a few lines below, next to this new rates: servedRates. That is both a duplicate property and a reference to an identifier that no longer exists, so the module will not type-check. Consider dropping the stale entry.

             ...hourlyWindow,
      -      rates,
           });
      Posted via Macroscope — Effect Service Conventions
    7. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Closing this PR after an automated pass over open pull requests. Duplicates another usage-reporting proposal while adding a broad client, contract, or provider integration.

Sign in to join this conversation.