Skip to content

Commit 2584bb8

Browse files
author
Theodore Li
committed
Address comments, skip tokenization billing fallback
1 parent 582b262 commit 2584bb8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

apps/sim/lib/tokenization/streaming.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export function processStreamingBlockLog(log: BlockLog, streamedContent: string)
3030
return false
3131
}
3232

33+
// Skip recalculation if cost was explicitly set by the billing layer (e.g. BYOK zero cost)
34+
if (log.output?.cost?.pricing) {
35+
return false
36+
}
37+
3338
// Check if we have content to tokenize
3439
if (!streamedContent?.trim()) {
3540
return false

apps/sim/providers/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const ZERO_COST = Object.freeze({
5858
input: 0,
5959
output: 0,
6060
total: 0,
61-
pricing: Object.freeze({ input: 0, output: 0, updatedAt: '' }),
61+
pricing: Object.freeze({ input: 0, output: 0, updatedAt: new Date(0).toISOString() }),
6262
})
6363

6464
/**
@@ -68,7 +68,10 @@ const ZERO_COST = Object.freeze({
6868
*/
6969
function zeroCostForBYOK(response: StreamingExecution): void {
7070
const output = response.execution?.output
71-
if (!output || typeof output !== 'object') return
71+
if (!output || typeof output !== 'object') {
72+
logger.warn('zeroCostForBYOK: output not available at intercept time; cost may not be zeroed')
73+
return
74+
}
7275

7376
Object.defineProperty(output, 'cost', {
7477
get: () => ZERO_COST,

0 commit comments

Comments
 (0)