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(quota): generate quotaShared-* combos for CLI/OAuth providers (use REGISTRY not PROVIDER_MODELS)

diegosouzapw99f615c7e075
diff --git a/src/lib/quota/quotaCombos.ts b/src/lib/quota/quotaCombos.ts
index 5001250d02..52f0b508dd 100644
--- a/src/lib/quota/quotaCombos.ts
+++ b/src/lib/quota/quotaCombos.ts
@@ -19,7 +19,7 @@ import {
getComboByName,
updateCombo,
} from "@/lib/db/combos";
-import { PROVIDER_MODELS } from "@omniroute/open-sse/config/providerModels";
+import { REGISTRY } from "@omniroute/open-sse/config/providerRegistry";
import { quotaModelName, parseQuotaModelName, isQuotaModelName, quotaPoolSlug } from "./quotaModelNaming";
import { createLogger } from "@/shared/utils/logger";
@@ -51,12 +51,16 @@ async function resolvePoolForSync(poolId: string): Promise<{
}
/**
- * Return the list of model IDs for a provider from the static registry.
+ * Return the list of model IDs for a provider from the provider REGISTRY — the
+ * SAME source `/v1/models` uses. PROVIDER_MODELS only covers plain API providers
+ * and is empty for CLI/OAuth providers (codex, kimi, claude, …), which silently
+ * produced ZERO quotaShared-* combos. REGISTRY has all of them.
* Empty array when the provider is unknown or has no registered models.
*/
function getProviderModelIds(provider: string): string[] {
- const models = PROVIDER_MODELS[provider];
- if (!Array.isArray(models) || models.length === 0) return [];
+ const entry = REGISTRY[provider as keyof typeof REGISTRY] as { models?: unknown } | undefined;
+ const models = entry && Array.isArray(entry.models) ? entry.models : [];
+ if (models.length === 0) return [];
return models
.map((m) => (typeof m === "object" && m !== null && typeof (m as { id?: unknown }).id === "string" ? (m as { id: string }).id : null))
.filter((id): id is string => id !== null && id.length > 0);
diff --git a/tests/unit/quota-combo-cli-providers.test.ts b/tests/unit/quota-combo-cli-providers.test.ts
new file mode 100644
index 0000000000..53c37f732a
--- /dev/null
+++ b/tests/unit/quota-combo-cli-providers.test.ts
@@ -0,0 +1,76 @@
+/**
+ * tests/unit/quota-combo-cli-providers.test.ts
+ *
+ * Regression: quotaShared-* combos were generated from PROVIDER_MODELS, which is
+ * EMPTY for CLI/OAuth providers (codex, kimi, claude, …). A pool built from those
+ * providers produced ZERO combos → the quota key saw no models. The fix reads the
+ * provider REGISTRY (same source /v1/models uses), which has those providers.
+ *
+ * This test creates a "codex" pool and asserts syncQuotaCombos produces combos
+ * (it would have produced none before the fix).
+ */
+
+import test from "node:test";
+import assert from "node:assert/strict";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+
+const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-quota-combo-cli-"));
+process.env.DATA_DIR = TEST_DATA_DIR;
+
+const core = await import("../../src/lib/db/core.ts");
+const poolsDb = await import("../../src/lib/db/quotaPools.ts");
+const providersDb = await import("../../src/lib/db/providers.ts");
+const { syncQuotaCombos } = await import("../../src/lib/quota/quotaCombos.ts");
+const { quotaModelName } = await import("../../src/lib/quota/quotaModelNaming.ts");
+const combosDb = await import("../../src/lib/db/combos.ts");
+const { REGISTRY } = await import("../../open-sse/config/providerRegistry.ts");
+
+async function resetStorage() {
+ core.resetDbInstance();
+ if (fs.existsSync(TEST_DATA_DIR)) fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
+ fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
+}
+
+test.beforeEach(async () => {
+ await resetStorage();
+});
+
+test.after(async () => {
+ core.resetDbInstance();
+ fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
+});
+
+const CLI_PROVIDER = "codex"; // absent from PROVIDER_MODELS, present in REGISTRY
+
+test("syncQuotaCombos generates quotaShared-* combos for a CLI provider (codex) via REGISTRY", async () => {
+ // Sanity: codex must be a REGISTRY provider with models (the fix's premise).
+ const regModels = (REGISTRY as Record<string, { models?: Array<{ id?: string }> }>)[CLI_PROVIDER]
+ ?.models;
+ assert.ok(Array.isArray(regModels) && regModels.length > 0, "codex must have REGISTRY models");
+ const firstModelId = regModels.find((m) => typeof m.id === "string")?.id as string;
+ assert.ok(firstModelId, "codex must have at least one model id");
+
+ const conn = await providersDb.createProviderConnection({
+ provider: CLI_PROVIDER,
+ authType: "apikey",
+ name: "codex-cli",
+ apiKey: "sk-codex",
+ });
+ const connId = (conn as Record<string, unknown>).id as string;
+ const pool = poolsDb.createPool({ connectionId: connId, name: "Codex Quota" });
+
+ await syncQuotaCombos(pool.id);
+
+ // Before the fix this was 0. Now there must be one combo per codex model.
+ const all = await combosDb.getCombos();
+ const quotaCombos = all.filter(
+ (c) => typeof c.name === "string" && (c.name as string).startsWith("quotaShared-")
+ );
+ assert.ok(quotaCombos.length > 0, "codex pool must produce quotaShared-* combos (was 0 before fix)");
+
+ const expectedName = quotaModelName(pool.name, CLI_PROVIDER, firstModelId);
+ const combo = await combosDb.getComboByName(expectedName);
+ assert.ok(combo, `combo "${expectedName}" must exist for the codex pool`);
+});