diff options
| author | Frank <[email protected]> | 2025-11-14 18:46:40 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-11-14 18:46:43 -0500 |
| commit | f5230d1f02963fa61408fc2c72ca1fb5877526c6 (patch) | |
| tree | 7feda3e206de50661718d139a950e26c0579667a /packages | |
| parent | 078111bd961c417725c04658ffd8e5e3fd7b01b8 (diff) | |
| download | opencode-f5230d1f02963fa61408fc2c72ca1fb5877526c6.tar.gz opencode-f5230d1f02963fa61408fc2c72ca1fb5877526c6.zip | |
fix: incorrect sonnet price calculation
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/provider/models.ts | 8 | ||||
| -rw-r--r-- | packages/opencode/src/session/index.ts | 15 |
2 files changed, 18 insertions, 5 deletions
diff --git a/packages/opencode/src/provider/models.ts b/packages/opencode/src/provider/models.ts index 57555c544..676837e15 100644 --- a/packages/opencode/src/provider/models.ts +++ b/packages/opencode/src/provider/models.ts @@ -23,6 +23,14 @@ export namespace ModelsDev { output: z.number(), cache_read: z.number().optional(), cache_write: z.number().optional(), + context_over_200k: z + .object({ + input: z.number(), + output: z.number(), + cache_read: z.number().optional(), + cache_write: z.number().optional(), + }) + .optional(), }), limit: z.object({ context: z.number(), diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index b920ca23c..395014ff4 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -396,15 +396,20 @@ export namespace Session { read: cachedInputTokens, }, } + + const costInfo = + input.model.cost?.context_over_200k && tokens.input + tokens.cache.read > 200_000 + ? input.model.cost.context_over_200k + : input.model.cost return { cost: new Decimal(0) - .add(new Decimal(tokens.input).mul(input.model.cost?.input ?? 0).div(1_000_000)) - .add(new Decimal(tokens.output).mul(input.model.cost?.output ?? 0).div(1_000_000)) - .add(new Decimal(tokens.cache.read).mul(input.model.cost?.cache_read ?? 0).div(1_000_000)) - .add(new Decimal(tokens.cache.write).mul(input.model.cost?.cache_write ?? 0).div(1_000_000)) + .add(new Decimal(tokens.input).mul(costInfo?.input ?? 0).div(1_000_000)) + .add(new Decimal(tokens.output).mul(costInfo?.output ?? 0).div(1_000_000)) + .add(new Decimal(tokens.cache.read).mul(costInfo?.cache_read ?? 0).div(1_000_000)) + .add(new Decimal(tokens.cache.write).mul(costInfo?.cache_write ?? 0).div(1_000_000)) // TODO: update models.dev to have better pricing model, for now: // charge reasoning tokens at the same rate as output tokens - .add(new Decimal(tokens.reasoning).mul(input.model.cost?.output ?? 0).div(1_000_000)) + .add(new Decimal(tokens.reasoning).mul(costInfo?.output ?? 0).div(1_000_000)) .toNumber(), tokens, } |
