Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/providers/__tests__/groq.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("GroqHandler", () => {
expect(firstChunk.done).toBe(false)
expect(firstChunk.value).toMatchObject({
type: "usage",
inputTokens: 70, // 100 total - 30 cached
inputTokens: 100,
outputTokens: 50,
cacheWriteTokens: 0,
cacheReadTokens: 30,
Expand Down
13 changes: 1 addition & 12 deletions src/api/providers/groq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,9 @@ export class GroqHandler extends BaseOpenAiCompatibleProvider<GroqModelId> {
// Calculate cost using OpenAI-compatible cost calculation
const totalCost = calculateApiCostOpenAI(info, inputTokens, outputTokens, cacheWriteTokens, cacheReadTokens)

// Calculate non-cached input tokens for proper reporting
const nonCachedInputTokens = Math.max(0, inputTokens - cacheReadTokens - cacheWriteTokens)

console.log("usage", {
inputTokens: nonCachedInputTokens,
outputTokens,
cacheWriteTokens,
cacheReadTokens,
totalCost,
})

yield {
type: "usage",
inputTokens: nonCachedInputTokens,
inputTokens,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see the test was updated to match this change! However, could you clarify what specific issue this fixes? The PR title mentions "Fix Groq context window display" but it's not clear what was broken.

Also, is this token reporting approach intentional? This makes Groq's behavior different from how it previously worked (subtracting cached tokens from input tokens). The base OpenAI provider reports total tokens, but some other providers handle cached tokens differently. Could you explain the reasoning behind this change?

outputTokens,
cacheWriteTokens,
cacheReadTokens,
Expand Down
Loading