File tree Expand file tree Collapse file tree 4 files changed +20
-4
lines changed
Expand file tree Collapse file tree 4 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,13 @@ export async function handler(
9999 const dataDumper = createDataDumper ( sessionId , requestId , projectId )
100100 const trialLimiter = createTrialLimiter ( modelInfo . trialProvider , ip )
101101 const trialProvider = await trialLimiter ?. check ( )
102- const rateLimiter = createRateLimiter ( modelInfo . allowAnonymous , ip , input . request )
102+ const rateLimiter = createRateLimiter (
103+ modelInfo . id ,
104+ modelInfo . allowAnonymous ,
105+ modelInfo . rateLimit ,
106+ ip ,
107+ input . request ,
108+ )
103109 await rateLimiter ?. check ( )
104110 const stickyTracker = createStickyTracker ( modelInfo . stickyProvider , sessionId )
105111 const stickyProvider = await stickyTracker ?. get ( )
Original file line number Diff line number Diff line change @@ -6,17 +6,25 @@ import { i18n } from "~/i18n"
66import { localeFromRequest } from "~/lib/language"
77import { Subscription } from "@opencode-ai/console-core/subscription.js"
88
9- export function createRateLimiter ( allowAnonymous : boolean | undefined , rawIp : string , request : Request ) {
9+ export function createRateLimiter (
10+ modelId : string ,
11+ allowAnonymous : boolean | undefined ,
12+ rateLimit : number | undefined ,
13+ rawIp : string ,
14+ request : Request ,
15+ ) {
1016 if ( ! allowAnonymous ) return
1117 const dict = i18n ( localeFromRequest ( request ) )
1218
1319 const limits = Subscription . getFreeLimits ( )
1420 const limitValue =
15- limits . checkHeader && ! request . headers . get ( limits . checkHeader ) ? limits . fallbackValue : limits . dailyRequests
21+ limits . checkHeader && ! request . headers . get ( limits . checkHeader )
22+ ? limits . fallbackValue
23+ : ( rateLimit ?? limits . dailyRequests )
1624
1725 const ip = ! rawIp . length ? "unknown" : rawIp
1826 const now = Date . now ( )
19- const interval = buildYYYYMMDD ( now )
27+ const interval = rateLimit ? ` ${ buildYYYYMMDD ( now ) } ${ modelId . substring ( 0 , 2 ) } ` : buildYYYYMMDD ( now )
2028
2129 return {
2230 track : async ( ) => {
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export namespace ZenData {
2828 stickyProvider : z . enum ( [ "strict" , "prefer" ] ) . optional ( ) ,
2929 trialProvider : z . string ( ) . optional ( ) ,
3030 fallbackProvider : z . string ( ) . optional ( ) ,
31+ rateLimit : z . number ( ) . optional ( ) ,
3132 providers : z . array (
3233 z . object ( {
3334 id : z . string ( ) ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export namespace Subscription {
88 const LimitsSchema = z . object ( {
99 free : z . object ( {
1010 promoTokens : z . number ( ) . int ( ) ,
11+ newDailyRequests : z . number ( ) . int ( ) ,
1112 dailyRequests : z . number ( ) . int ( ) ,
1213 checkHeader : z . string ( ) ,
1314 fallbackValue : z . number ( ) . int ( ) ,
You can’t perform that action at this time.
0 commit comments