-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix openai cache tracking and cost estimates #2616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Set correct cacheReadsPrice (cached input price) for gpt-4.1, gpt-4.1 mini, and gpt-4.1 nano based on official OpenAI pricing. No changes to cacheWritesPrice as per current OpenAI documentation. This ensures prompt caching costs are accurately reflected for these models in cost calculations.
|
| // Check usage data fields but use toBeCloseTo for floating point comparison | ||
| expect(results[1].type).toBe("usage") | ||
| // Use type assertion to avoid TypeScript errors | ||
| expect((results[1] as any).inputTokens).toBe(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider defining proper result types to eliminate repeated 'as any' assertions, enhancing maintainability.
| // Check usage data fields but use toBeCloseTo for floating point comparison | ||
| expect(results[3].type).toBe("usage") | ||
| // Use type assertion to avoid TypeScript errors | ||
| expect((results[3] as any).inputTokens).toBe(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing the any cast with a more specific type or unknown to improve type safety in these assertions.
| // Check usage data fields but use toBeCloseTo for floating point comparison | ||
| expect(results[1].type).toBe("usage") | ||
| // Use type assertion to avoid TypeScript errors | ||
| expect((results[1] as any).inputTokens).toBe(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated type assertions for usage properties appear in multiple tests. Consider extracting these assertions into a helper function to reduce duplication and improve maintainability.
Important
Enhances OpenAI cache tracking and cost estimation by updating model handling and tests in
openai-native.tsandopenai-native.test.ts.OpenAiNativeHandlerinopenai-native.tsto include cache read tokens in cost calculation usingcalculateApiCostOpenAI.cacheReadsPricetoopenAiNativeModelsinapi.tsfor cost estimation.openai-native.test.tsto verify individual response fields and usage data, includingtotalCost.handleStreamResponseand related functions inopenai-native.tsto pass model information for accurate cost calculation.This description was created by
for 1c814a9. It will automatically update as commits are pushed.