Skip to content

Commit 6e88530

Browse files
committed
fix(providers): expect per-call metering in settled Z.ai streams and keep meter types local
1 parent e195299 commit 6e88530

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎apps/sim/providers/openai-compat/usage-meter.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { getChatCompletionConversationUsage } from '@/providers/openai-compat/co
44
import type { ModelPricing } from '@/providers/types'
55

66
/** Token counts a meter has accumulated; `input` excludes the cache hits counted in `cacheRead`. */
7-
export interface ChatCompletionMeteredTokens {
7+
interface ChatCompletionMeteredTokens {
88
input: number
99
output: number
1010
cacheRead: number
1111
total: number
1212
}
1313

1414
/** List-price cost of everything a meter has recorded, plus any tool cost passed in. */
15-
export interface ChatCompletionMeteredCost {
15+
interface ChatCompletionMeteredCost {
1616
input: number
1717
output: number
1818
total: number

‎apps/sim/providers/settled-tool-streams.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ const STRUCTURED_OUTPUT_PROVIDERS = [
236236
},
237237
] as const
238238

239+
/**
240+
* The mocked model cost of a three-call settled run: Z.ai meters each call (cache-aware), the other
241+
* providers here price the summed usage once. Tool cost is the mocked 4 either way.
242+
*/
243+
function settledRunCost(provider: ProviderConfig) {
244+
const pricedCalls = provider === zaiProvider ? 3 : 1
245+
return { input: pricedCalls, output: 2 * pricedCalls, toolCost: 4, total: 3 * pricedCalls + 4 }
246+
}
247+
239248
function toolCall(id: string, argumentsJson = '{}'): ToolCall {
240249
return {
241250
id,
@@ -400,7 +409,7 @@ describe('settled provider tool streams', () => {
400409
expect(result.execution.output).toMatchObject({
401410
content: '{"value":"found"}',
402411
tokens: { input: 15, output: 9, total: 24 },
403-
cost: { input: 1, output: 2, toolCost: 4, total: 7 },
412+
cost: settledRunCost(provider),
404413
toolCalls: { count: 1 },
405414
})
406415
expectModelIterations(result, 3)
@@ -427,7 +436,7 @@ describe('settled provider tool streams', () => {
427436
expect(result.execution.output).toMatchObject({
428437
content: '{"value":"capped"}',
429438
tokens: { input: 15, output: 9, total: 24 },
430-
cost: { input: 1, output: 2, toolCost: 4, total: 7 },
439+
cost: settledRunCost(provider),
431440
})
432441
expectModelIterations(result, 3)
433442
}

0 commit comments

Comments
 (0)