cost: sidebar session cost inflated ~10⁶× for cortecs/glm-5.2 (catalog rates treated as $/token instead of $/M tokens)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 72/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- typescript
- Domaine
- backend
Piste de recherche
Recherchez dans le code de suivi des coûts les utilisations de catalog cost[].input et cost[].output, puis suivez la façon dont les nombres de tokens sont multipliés par ces tarifs. Vérifiez l’énoncé du schéma du catalogue selon lequel les prix sont en USD par million de tokens, puis comparez le résultat de l’accumulateur avec l’exemple détaillé de l’issue. Le travail est terminé lorsque le calcul produit environ $9.14 pour 8M tokens en entrée et 600K tokens en sortie, aux tarifs indiqués.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
The TUI sidebar cost accumulator produces an absurdly inflated session cost (~$8.3M) for a cortecs/glm-5.2 session, consistent with treating the model catalog's cost[].input / cost[].output values as USD per token instead of USD per million tokens as the schema declares. The displayed figure is off by ~10⁶ from the real cost.
Environment
- opencode version: v2.2.0
- OS: Linux 6.12.113+deb13-amd64 (linux x64)
- Terminal: TERM=xterm-256color, COLORTERM=truecolor
- Shell: /usr/bin/bash
- Install/channel: latest
- Active plugins: None found in config
- Provider/model:
cortecs/glm-5.2(variant in use: default)
Reproduction
- Configure the
cortecsprovider and usecortecs/glm-5.2as the model. - Run a heavy session — file reads, PDF conversions, long doc drafting — such that several million input tokens and a few hundred thousand output tokens accumulate (this session had ~8M input / ~600k output).
- Observe the sidebar/session cost figure: it shows $8,386,053.00.
Expected Behavior
The cost accumulator should treat catalog cost[].input and cost[].output as USD per million tokens (per the schema documentation: "Pricing in USD per million tokens"). For a session of ~8M input + ~600k output tokens at the reported rates (input=0.9, output=3.24), the correct cost is roughly $9.14, i.e. (8_000_000 × 0.9 + 600_000 × 3.24) / 1_000_000.
Actual Behavior
The accumulator appears to use the catalog values directly as USD per token, producing (8_000_000 × 0.9 + 600_000 × 3.24) = $9,144,000 — matching the order of magnitude of the displayed $8,386,053.00. The figure is off by a factor of ~1,000,000 from the real cost on a €50/month plan, where such a spend would be impossible.
Additional Context
Catalog evidence
The models tool returns the following for cortecs/glm-5.2:
{
"id": "cortecs/glm-5.2",
"name": "GLM-5.2",
"cost": [
{
"input": 0.9,
"output": 3.24,
"cache": { "read": 0.189, "write": 0 }
}
],
"status": "active"
}
The schema (per https://opencode.ai/config.json) documents cost[].input and cost[].output as "Pricing in USD per million tokens." The values themselves ($0.9/M input, $3.24/M output) are normal, plausible LLM prices — they only become absurd when interpreted as per-token.
Worked example of the off-by-10⁶ hypothesis
| Scenario | Tokens in | Tokens out | If $/M tokens (correct) | If $/token (buggy) |
|---|---|---|---|---|
| low | 2,000,000 | 200,000 | $2.45 | $2,448,000 |
| high | 8,000,000 | 600,000 | $9.14 | $9,144,000 |
The reported $8,386,053.00 sits squarely in the "high" buggy range, consistent with a long heavy session.
Why this matters
- The displayed number is OpenCode's local accumulator, not a bill from the gateway (Cortecs here). Users on capped plans (e.g. €50/month) see a meaningless eight-figure "spend" that obscures the real, useful signal of how much of their budget a session consumed.
- It is the opposite failure mode of recent issues #59634 / #59627 (cost stays at 0) and #59671 (6× undercount for Copilot tiered pricing), so it does not appear to duplicate them.
Likely fix location
Wherever the cost accumulator multiplies token counts by catalog cost[].input / cost[].output, it should divide by 1,000,000 (or the rates should be pre-converted to per-token) before multiplication. A grep for cost.input / cost.output in the cost-tracking code path should locate it quickly.
Notes
- The reported figure ($8,386,053.00) is taken from the TUI sidebar at the end of a long session; I have not captured a token-by-token log, but the order of magnitude is the diagnostic, not the exact cents.
- I have not redacted the provider name or model id as these are needed to reproduce.
- Langage dominant
- TypeScript
- Étoiles
- 224k
- Forks
- 30k
- Merge moyen
- 7 h 30 min
- PR mergées (30 j)
- 489
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de anomalyco/opencode
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
anomalyco/opencode#60584 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
core: OpenRouter BYOK sessions record cost = 0 since v2.2.0 (ignores cost_details.upstream_inference_cost)Peut-être pris @tneemo l’a pris il y a 2 jours. Ouvertereproduced
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
anomalyco/opencode#60558 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
anomalyco/opencode#60541 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
anomalyco/opencode#60529 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
anomalyco/opencode#60469 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de anomalyco/opencode
Issues similaires
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster no-stale P1
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
steipete/oracle#614 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Koenkk/zigbee-herdsman-converters#13656 ·
Les mainteneurs répondent en général sous 2 jours
-
Report: Mooz Dance SDOuvertecheck:passed streams:remove
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
bug needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
actions/setup-node#1659 ·
Les mainteneurs répondent en général sous 1 jour