[PR #4222] Fix usage & billing for custom model aliases and cached/reasoning tokens #10904

Closed
opened 2026-02-16 18:15:39 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4222

State: closed
Merged: Yes


Summary:

  • Ensure custom model aliases inherit the real model metadata so context/limits and cost are computed from the actual model.
  • Correct usage/cost calculation: bill cached/uncached input tokens separately, include cache-write tokens, and bill reasoning tokens at the same rate as output tokens.

Changed files:

  • packages/opencode/src/provider/provider.ts — fallback to lookup parsed.models[model.id] for aliases.
  • packages/opencode/src/session/index.ts — getUsage: compute uncachedInput = inputTokens - cachedInputTokens, bill cached/uncached input separately, include cache.write, and charge reasoning tokens at output rate.

Tests: ran session tests locally (2 passed).

Fixes #4162

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4222 **State:** closed **Merged:** Yes --- Summary: - Ensure custom model aliases inherit the real model metadata so context/limits and cost are computed from the actual model. - Correct usage/cost calculation: bill cached/uncached input tokens separately, include cache-write tokens, and bill reasoning tokens at the same rate as output tokens. Changed files: - packages/opencode/src/provider/provider.ts — fallback to lookup `parsed.models[model.id]` for aliases. - packages/opencode/src/session/index.ts — `getUsage`: compute `uncachedInput = inputTokens - cachedInputTokens`, bill cached/uncached input separately, include cache.write, and charge reasoning tokens at output rate. Tests: ran session tests locally (2 passed). Fixes #4162
yindo added the pull-request label 2026-02-16 18:15:39 -05:00
yindo closed this issue 2026-02-16 18:15:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10904