Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: per-model rate limiting for GitHub Copilot provider (#1624)

diegosouzapwaccb58f5b255
diff --git a/open-sse/services/accountFallback.ts b/open-sse/services/accountFallback.ts
index d8431067af..74bc593f6c 100644
--- a/open-sse/services/accountFallback.ts
+++ b/open-sse/services/accountFallback.ts
@@ -407,7 +407,7 @@ export function hasPerModelQuota(
return connectionPassthroughModels;
}
if (!provider) return false;
- if (provider === "gemini") return true;
+ if (provider === "gemini" || provider === "github") return true;
if (getPassthroughProviders().has(provider)) return true;
if (isCompatibleProvider(provider)) return true;
return false;
diff --git a/open-sse/services/rateLimitManager.ts b/open-sse/services/rateLimitManager.ts
index e1ec39dd4c..b95916ade0 100644
--- a/open-sse/services/rateLimitManager.ts
+++ b/open-sse/services/rateLimitManager.ts
@@ -236,9 +236,9 @@ function getLimiterKey(provider, connectionId, model = null) {
if (provider === "codex" && model) {
return `${provider}:${getCodexRateLimitKey(connectionId, model)}`;
}
- // Gemini AI Studio has per-model quotas — use model-scoped limiter keys
- // so a 429 on one model doesn't pause requests for other models.
- if (provider === "gemini" && model) {
+ // Gemini AI Studio and GitHub Copilot have per-model quotas — use model-scoped
+ // limiter keys so a 429 on one model doesn't pause requests for other models.
+ if ((provider === "gemini" || provider === "github") && model) {
return `${provider}:${connectionId}:${model}`;
}
return `${provider}:${connectionId}`;
diff --git a/tests/unit/account-fallback-service.test.ts b/tests/unit/account-fallback-service.test.ts
index 63b473e926..8e49cdd6d2 100644
--- a/tests/unit/account-fallback-service.test.ts
+++ b/tests/unit/account-fallback-service.test.ts
@@ -293,6 +293,39 @@ test("shouldMarkAccountExhaustedFrom429 skips connection poisoning for compatibl
assert.equal(shouldMarkAccountExhaustedFrom429("openai", "gpt-4o-mini"), true);
});
+test("hasPerModelQuota returns true for GitHub Copilot provider (#1624)", () => {
+ assert.equal(hasPerModelQuota("github"), true);
+ assert.equal(hasPerModelQuota("github", "gpt-5.1-codex-max"), true);
+ assert.equal(hasPerModelQuota("github", "gpt-5-mini"), true);
+});
+
+test("shouldMarkAccountExhaustedFrom429 skips connection-wide lockout for GitHub (#1624)", () => {
+ assert.equal(shouldMarkAccountExhaustedFrom429("github", "gpt-5.1-codex-max"), false);
+ assert.equal(shouldMarkAccountExhaustedFrom429("github", "gpt-5-mini"), false);
+ assert.equal(shouldMarkAccountExhaustedFrom429("github", "claude-haiku-4.5"), false);
+});
+
+test("lockModelIfPerModelQuota locks individual GitHub models without poisoning the connection (#1624)", () => {
+ const connectionId = `github-${Date.now()}`;
+
+ // A 429 on a high-PRU model should lock ONLY that model
+ assert.equal(
+ lockModelIfPerModelQuota(
+ "github",
+ connectionId,
+ "gpt-5.1-codex-max",
+ RateLimitReason.RATE_LIMIT_EXCEEDED,
+ 30_000
+ ),
+ true
+ );
+ assert.equal(isModelLocked("github", connectionId, "gpt-5.1-codex-max"), true);
+
+ // Other models on the same connection should remain unlocked
+ assert.equal(isModelLocked("github", connectionId, "gpt-5-mini"), false);
+ assert.equal(isModelLocked("github", connectionId, "claude-haiku-4.5"), false);
+});
+
test("recordModelLockoutFailure uses provider profile cooldowns, backoff, and reset window", () => {
const originalNow = Date.now;
let now = 1_700_000_000_000;
diff --git a/tests/unit/rate-limit-manager.test.ts b/tests/unit/rate-limit-manager.test.ts
index be11a34fce..d505a49add 100644
--- a/tests/unit/rate-limit-manager.test.ts
+++ b/tests/unit/rate-limit-manager.test.ts
@@ -144,6 +144,36 @@ test("rate limit manager handles 429 limiter teardown and disable cleanup", asyn
assert.equal(rateLimitManager.getRateLimitStatus("gemini", "conn-disable").active, false);
});
+test("rate limit manager uses model-scoped limiter keys for GitHub Copilot (#1624)", async () => {
+ rateLimitManager.enableRateLimitProtection("conn-github");
+ rateLimitManager.updateFromHeaders(
+ "github",
+ "conn-github",
+ {
+ "x-ratelimit-limit-requests": "50",
+ "x-ratelimit-remaining-requests": "3",
+ "x-ratelimit-reset-requests": "15s",
+ },
+ 200,
+ "gpt-5.1-codex-max"
+ );
+ await rateLimitManager.__flushLearnedLimitsForTests();
+
+ // GitHub should use model-scoped key: github:conn-github:gpt-5.1-codex-max
+ const allStatuses = rateLimitManager.getAllRateLimitStatus();
+ assert.ok(
+ allStatuses["github:conn-github:gpt-5.1-codex-max"],
+ "GitHub limiter key should be model-scoped (github:conn:model)"
+ );
+ // Verify the limiter state is model-scoped via test helper
+ const limiterState = await rateLimitManager.__getLimiterStateForTests(
+ "github",
+ "conn-github",
+ "gpt-5.1-codex-max"
+ );
+ assert.equal(limiterState?.key, "github:conn-github:gpt-5.1-codex-max");
+});
+
test("rate limit manager parses retry hints from response bodies and locks models", async () => {
rateLimitManager.enableRateLimitProtection("conn-body");
rateLimitManager.updateFromResponseBody(