Skip to content

Commit 6139a9d

Browse files
committed
Allow freemode requests
1 parent fce31b8 commit 6139a9d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

web/src/app/api/v1/chat/completions/__tests__/completions.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,39 @@ describe('/api/v1/chat/completions POST endpoint', () => {
522522
expect(response.status).toBe(200)
523523
})
524524

525+
it('lets a freebuff/free-mode request through even for a brand-new unpaid account', async () => {
526+
const req = new NextRequest(
527+
'http://localhost:3000/api/v1/chat/completions',
528+
{
529+
method: 'POST',
530+
headers: { Authorization: 'Bearer test-api-key-new-free' },
531+
body: JSON.stringify({
532+
model: 'test/test-model',
533+
stream: false,
534+
codebuff_metadata: {
535+
run_id: 'run-123',
536+
client_id: 'test-client-id-123',
537+
cost_mode: 'free',
538+
},
539+
}),
540+
},
541+
)
542+
543+
const response = await postChatCompletions({
544+
req,
545+
getUserInfoFromApiKey: mockGetUserInfoFromApiKey,
546+
logger: mockLogger,
547+
trackEvent: mockTrackEvent,
548+
getUserUsageData: mockGetUserUsageData,
549+
getAgentRunFromId: mockGetAgentRunFromId,
550+
fetch: mockFetch,
551+
insertMessageBigquery: mockInsertMessageBigquery,
552+
loggerWithContext: mockLoggerWithContext,
553+
})
554+
555+
expect(response.status).toBe(200)
556+
})
557+
525558
it('skips credit check when in FREE mode even with 0 credits', async () => {
526559
const req = new NextRequest(
527560
'http://localhost:3000/api/v1/chat/completions',

web/src/app/api/v1/chat/completions/_post.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,11 @@ export async function postChatCompletions(params: {
459459
? Date.now() - new Date(userInfo.created_at).getTime()
460460
: 0
461461
const accountIsTooNew = accountAgeMs < MIN_ACCOUNT_AGE_FOR_PAID_MS
462-
if (!openrouterApiKeyHeader && (!hasPaidRelationship || accountIsTooNew)) {
462+
if (
463+
!isFreeModeRequest &&
464+
!openrouterApiKeyHeader &&
465+
(!hasPaidRelationship || accountIsTooNew)
466+
) {
463467
trackEvent({
464468
event: AnalyticsEvent.CHAT_COMPLETIONS_VALIDATION_ERROR,
465469
userId,

0 commit comments

Comments
 (0)