7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(apinex): enforce the shared 5 RPM free-tier cap across all models (#1584)
Tashfeen0c456ea4df99
diff --git a/server/src/__tests__/services/provider-minute-cap.test.ts b/server/src/__tests__/services/provider-minute-cap.test.tsindex 0bb1b4fb..053d9d19 100644--- a/server/src/__tests__/services/provider-minute-cap.test.ts+++ b/server/src/__tests__/services/provider-minute-cap.test.ts@@ -31,6 +31,7 @@ describe('provider-wide per-minute request cap', () => {afterEach(() => {delete process.env.PROVIDER_MINUTE_REQUEST_CAP_NVIDIA;delete process.env.PROVIDER_MINUTE_REQUEST_CAP_GROQ;+ delete process.env.PROVIDER_MINUTE_REQUEST_CAP_APINEX;});it('ships a default cap for nvidia and none for a provider without one', () => {@@ -38,6 +39,17 @@ describe('provider-wide per-minute request cap', () => {expect(getProviderMinuteRequestCap('groq')).toBeNull();});+ it('applies the APINex 5 RPM cap across different free models, per key', () => {+ const now = Date.now();+ expect(getProviderMinuteRequestCap('apinex')).toBe(5);+ seedRequests('apinex', 'free/deepseek-v4.1-flash', keyId, 3, now - 20_000);+ seedRequests('apinex', 'free/gpt-6-luna', keyId, 2, now - 10_000);+ expect(providerMinuteRequestCount('apinex', keyId, now)).toBe(5);+ expect(canUseProviderMinute('apinex', keyId, now)).toBe(false);+ expect(canUseProviderMinute('apinex', keyId + 1, now)).toBe(true);+ expect(canUseProviderMinute('apinex', keyId, now + 61_000)).toBe(true);+ });+it('honours an env override and treats 0 as disabled', () => {process.env.PROVIDER_MINUTE_REQUEST_CAP_NVIDIA = '5';expect(getProviderMinuteRequestCap('nvidia')).toBe(5);diff --git a/server/src/services/ratelimit.ts b/server/src/services/ratelimit.tsindex 06dc5156..51f40c3b 100644--- a/server/src/services/ratelimit.ts+++ b/server/src/services/ratelimit.ts@@ -587,6 +587,9 @@ const DEFAULT_PROVIDER_DAILY_TOKEN_CAPS: Record<string, number> = {// entirely — so it keeps dispatching and eats real 429s.const DEFAULT_PROVIDER_MINUTE_REQUEST_CAPS: Record<string, number> = {nvidia: 40,+ // APINex Free: 5 requests/minute per key shared across every model+ // (apinex.bond/api/public/rate-limits `rpmFree`), not 5 per model.+ apinex: 5,};export function getProviderDailyRequestCap(platform: string): number | null {