mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-22 21:09:08 +00:00
fix(hermes): stop counting reasoning tokens twice
Hermes stores output tokens as the API reports them, reasoning included, so the calculated cost and every output total added reasoning on top. Hermes joins the providers whose output already holds reasoning, and the calculated basis prices output alone.
This commit is contained in:
parent
c0b9f421f5
commit
aef349747b
3 changed files with 7 additions and 4 deletions
|
|
@ -60,7 +60,8 @@ export type LongContextTier = {
|
|||
/// top bills it twice.
|
||||
/// DSH TokenUsage includes reasoning in output too; see the pinned contract:
|
||||
/// https://github.com/deepseek-ai/deepseek-harness/blob/c291e7961a515f6d7af9304e7fd1d257929aef26/docs/subsystems/llm-streaming.md#tokenusage
|
||||
const REASONING_INCLUDED_IN_OUTPUT = new Set(['claude', 'codex', 'copilot', 'dsh'])
|
||||
/// Hermes stores completion/output tokens as the API reports them, reasoning inside.
|
||||
const REASONING_INCLUDED_IN_OUTPUT = new Set(['claude', 'codex', 'copilot', 'dsh', 'hermes'])
|
||||
|
||||
/// Output tokens to bill and display for one call. Single source of truth so
|
||||
/// the pricing sites and the display sums can never disagree about whether a
|
||||
|
|
|
|||
|
|
@ -450,7 +450,7 @@ function resolveHermesCost(
|
|||
const calculatedCost = calculateCost(
|
||||
model,
|
||||
tokens.inputTokens,
|
||||
tokens.outputTokens + tokens.reasoningTokens,
|
||||
tokens.outputTokens,
|
||||
tokens.cacheWriteTokens,
|
||||
tokens.cacheReadTokens,
|
||||
0,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { tmpdir, homedir } from 'os'
|
|||
import { createRequire } from 'node:module'
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { calculateCost } from '../../src/models.js'
|
||||
import { billableOutputTokens, calculateCost } from '../../src/models.js'
|
||||
import { createHermesProvider } from '../../src/providers/hermes.js'
|
||||
import { isSqliteAvailable } from '../../src/sqlite.js'
|
||||
import { aggregateProjectsIntoDays } from '../../src/day-aggregator.js'
|
||||
|
|
@ -541,8 +541,10 @@ skipUnlessSqlite('hermes provider', () => {
|
|||
|
||||
const calls = await collectCalls(tmpDir, `${dbPath}#hermes-session=no-cost-session`)
|
||||
expect(calls).toHaveLength(1)
|
||||
expect(calls[0]!.costUSD).toBe(calculateCost('claude-sonnet-4-20250514', 1000, 250, 0, 0, 0))
|
||||
// Output already includes the reasoning tokens.
|
||||
expect(calls[0]!.costUSD).toBe(calculateCost('claude-sonnet-4-20250514', 1000, 200, 0, 0, 0))
|
||||
expect(calls[0]!.reasoningTokens).toBe(50)
|
||||
expect(billableOutputTokens('hermes', calls[0]!.outputTokens, calls[0]!.reasoningTokens)).toBe(200)
|
||||
})
|
||||
|
||||
it('carries the billing route the session recorded, and stays silent for every other door', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue