Skip to content

Commit ab5ee5b

Browse files
Justin Torreclaude
authored andcommitted
fix: PTB with free tier exceeded skips S3 only if usage extraction succeeded
- PTB + got usage: skip S3 bodies (we have what we need for billing) - PTB + failed to get usage: store S3 bodies (Jawn needs to extract) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 71d7557 commit ab5ee5b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

worker/src/lib/dbLogger/DBLoggable.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,13 @@ export class DBLoggable {
836836
}
837837

838838
// Skip S3 storage if:
839-
// 1. Free tier limit exceeded AND not PTB (metadata still logged, just no bodies)
840-
// 2. Both omit headers are set
841-
// IMPORTANT: For PTB, if we failed to get usage, always store to S3 so Jawn can extract it for billing
842-
const skipS3ForFreeTier = freeLimitExceeded && !isPassthroughBilling;
839+
// 1. Free tier limit exceeded AND (not PTB OR we got usage successfully)
840+
// - Non-PTB: always skip bodies
841+
// - PTB with usage: skip bodies (we have what we need for billing)
842+
// - PTB without usage: store bodies (Jawn needs to extract for billing)
843+
// 2. Both omit headers are set (but not if PTB failed to get usage)
844+
const skipS3ForFreeTier =
845+
freeLimitExceeded && (!isPassthroughBilling || !failedToGetUsage);
843846
const skipS3ForOmitHeaders =
844847
!(isPassthroughBilling && failedToGetUsage) &&
845848
requestHeaders?.omitHeaders?.omitRequest === true &&

0 commit comments

Comments
 (0)