Skip to content

Commit 282ee30

Browse files
committed
test(openai-native): cover the 12h rate under each service tier
What: - Add a per-tier case asserting the 12h write rate follows the tier's own input price (default 25.0, flex 12.5, priority 50.0 for gpt-6-astra). Why: The service-tier seam was changed to derive the TTL rates from the tier input price, but nothing pinned that behaviour. Without a test, a future edit could revert to the standard-tier 12h rate and a flex/priority 12h write would be mis-billed by 2x in either direction. Impact: Test only. Fails without the tier derivation (flex bills 2.5 instead of 1.25, priority 2.5 instead of 5.0).
1 parent 025ff9c commit 282ee30

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/api/providers/__tests__/openai-native-usage.spec.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,35 @@ describe("OpenAiNativeHandler - normalizeUsage", () => {
528528
expect(result.totalCost).toBeCloseTo(expectedCost, 6)
529529
})
530530

531+
it.each([
532+
// gpt-6-astra: default input 10.0 / 12h 25.0; flex input 5.0; priority input 20.0.
533+
// The 12h rate must follow the tier's own input price (2.5x), not the
534+
// standard-tier 12h rate, or a flex/priority 12h write is mis-billed.
535+
{ tier: OpenAiServiceTier.Default, expectedCost: 2.5 },
536+
{ tier: OpenAiServiceTier.Flex, expectedCost: 1.25 },
537+
{ tier: OpenAiServiceTier.Priority, expectedCost: 5.0 },
538+
])("derives the 12h rate from the $tier tier's own input price", ({ tier, expectedCost }) => {
539+
handler = new OpenAiNativeHandler({
540+
openAiNativeApiKey: "test-key",
541+
openAiNativeServiceTier: tier,
542+
})
543+
const result = handler["normalizeUsage"](
544+
{
545+
input_tokens: 100_000,
546+
output_tokens: 0,
547+
input_tokens_details: {
548+
cache_write_tokens: 100_000,
549+
cache_write_tokens_details: { ttl_12h_tokens: 100_000 },
550+
},
551+
},
552+
getGpt6AstraModel(),
553+
)
554+
555+
if (!result) throw new Error("Expected usage")
556+
// All input is consumed by the write, so the whole cost is the 12h class.
557+
expect(result.totalCost).toBeCloseTo(expectedCost, 6)
558+
})
559+
531560
it("should pass total input tokens to calculateApiCostOpenAI", () => {
532561
const usage = {
533562
input_tokens: 100,

0 commit comments

Comments
 (0)