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

feat(quota): qtSd/<group>/<provider>/<model> model naming

diegosouzapwcb1a18fa1a02
diff --git a/src/lib/quota/quotaCombos.ts b/src/lib/quota/quotaCombos.ts
index 52f0b508dd..61a46c65a1 100644
--- a/src/lib/quota/quotaCombos.ts
+++ b/src/lib/quota/quotaCombos.ts
@@ -174,7 +174,7 @@ export async function syncQuotaCombos(poolId: string): Promise<void> {
const parsed = parseQuotaModelName(name);
if (!parsed) continue;
- if (parsed.poolSlug !== poolSlug) continue;
+ if (parsed.groupSlug !== poolSlug) continue;
// Belongs to this pool slug but not produced by any current connection → prune.
if (!desiredNames.has(name)) {
@@ -210,7 +210,7 @@ export function filterModelsToQuotaPools<T extends { id: string }>(
return models.filter((m) => {
if (!isQuotaModelName(m.id)) return false;
const parsed = parseQuotaModelName(m.id);
- return parsed !== null && slugSet.has(parsed.poolSlug);
+ return parsed !== null && slugSet.has(parsed.groupSlug);
});
}
@@ -244,7 +244,7 @@ export async function removeQuotaCombosForPool(poolId: string): Promise<void> {
if (!parsed) continue;
// Match by slug when we have a pool name; otherwise no match possible
- if (slug !== null && parsed.poolSlug !== slug) continue;
+ if (slug !== null && parsed.groupSlug !== slug) continue;
try {
await deleteComboByName(name);
diff --git a/src/lib/quota/quotaModelNaming.ts b/src/lib/quota/quotaModelNaming.ts
index 95ecbfb623..1e81cf5952 100644
--- a/src/lib/quota/quotaModelNaming.ts
+++ b/src/lib/quota/quotaModelNaming.ts
@@ -1,70 +1,79 @@
/**
- * Deterministic naming helpers for quota virtual models (Phase B1).
+ * Deterministic naming helpers for quota virtual models (Phase B3).
*
- * FORMAT: `quotaShared-<poolSlug>-<provider>/<model>`
+ * FORMAT: `qtSd/<groupSlug>/<provider>/<model>`
*
- * The poolSlug is pure alphanumeric (no "-", no "/"), which makes the first
- * "-" after the prefix and the first "/" unambiguous delimiters that allow
- * round-trip parsing even when provider contains "-" or model contains "/".
+ * The groupSlug is pure alphanumeric (no "-", no "/"), and the segments are
+ * separated by "/" which makes parsing unambiguous: split on "/", take the
+ * first 3 segments (prefix literal "qtSd", groupSlug, provider) and join the
+ * remainder as the model id (model ids may contain "/" for namespaced models).
*/
-export const QUOTA_MODEL_PREFIX = "quotaShared-";
+export const QUOTA_MODEL_PREFIX = "qtSd/";
/**
- * Convert an arbitrary pool name into a safe, alphanumeric slug.
+ * Convert an arbitrary group name into a safe, alphanumeric slug.
* Lowercases the name then strips every character that is not [a-z0-9].
* Falls back to "pool" when the result would be empty.
*/
-export function quotaPoolSlug(poolName: string): string {
- const slug = poolName.toLowerCase().replace(/[^a-z0-9]/g, "");
+export function quotaGroupSlug(name: string): string {
+ const slug = name.toLowerCase().replace(/[^a-z0-9]/g, "");
return slug.length > 0 ? slug : "pool";
}
+/**
+ * Backward-compat alias: quotaPoolSlug delegates to quotaGroupSlug.
+ * Callers in quotaKey.ts and quotaCombos.ts that import quotaPoolSlug
+ * continue to work without changes until B4 updates them.
+ */
+export function quotaPoolSlug(poolName: string): string {
+ return quotaGroupSlug(poolName);
+}
+
/**
* Build the canonical virtual model name for a quota-shared target.
- * Provider and model are kept verbatim (not slugged).
+ * The first argument is the GROUP name (phase B3+). Provider and model
+ * are kept verbatim (not slugged).
+ *
+ * Example: quotaModelName("Pool Principal", "codex", "gpt-5.5")
+ * → "qtSd/poolprincipal/codex/gpt-5.5"
*/
-export function quotaModelName(poolName: string, provider: string, model: string): string {
- return `${QUOTA_MODEL_PREFIX}${quotaPoolSlug(poolName)}-${provider}/${model}`;
+export function quotaModelName(groupName: string, provider: string, model: string): string {
+ return `${QUOTA_MODEL_PREFIX}${quotaGroupSlug(groupName)}/${provider}/${model}`;
}
/**
* Parse a quota virtual model name back into its components.
* Returns null when the name is not a valid quota model name.
+ *
+ * Segments: ["qtSd", groupSlug, provider, ...modelParts]
+ * Requires at least 4 segments. Model is the remainder joined by "/".
*/
export function parseQuotaModelName(
name: string,
-): { poolSlug: string; provider: string; model: string } | null {
+): { groupSlug: string; provider: string; model: string } | null {
if (!name.startsWith(QUOTA_MODEL_PREFIX)) {
return null;
}
- // rest = "<poolSlug>-<provider>/<model>"
+ // rest = "<groupSlug>/<provider>/<model>" (after "qtSd/")
const rest = name.slice(QUOTA_MODEL_PREFIX.length);
+ const parts = rest.split("/");
- // poolSlug has no "-" by construction → first "-" is the delimiter
- const dashIdx = rest.indexOf("-");
- if (dashIdx === -1) {
- return null;
- }
-
- const poolSlug = rest.slice(0, dashIdx);
- const tail = rest.slice(dashIdx + 1); // "<provider>/<model>"
-
- // first "/" separates provider from model; model may contain additional "/"
- const slashIdx = tail.indexOf("/");
- if (slashIdx === -1) {
+ // Need at least: groupSlug, provider, model → 3 parts in rest
+ if (parts.length < 3) {
return null;
}
- const provider = tail.slice(0, slashIdx);
- const model = tail.slice(slashIdx + 1);
+ const groupSlug = parts[0];
+ const provider = parts[1];
+ const model = parts.slice(2).join("/");
- if (provider.length === 0 || model.length === 0) {
+ if (groupSlug.length === 0 || provider.length === 0 || model.length === 0) {
return null;
}
- return { poolSlug, provider, model };
+ return { groupSlug, provider, model };
}
/**
diff --git a/src/shared/utils/apiKeyPolicy.ts b/src/shared/utils/apiKeyPolicy.ts
index feb07cb100..69eedb0bbc 100644
--- a/src/shared/utils/apiKeyPolicy.ts
+++ b/src/shared/utils/apiKeyPolicy.ts
@@ -337,7 +337,7 @@ export async function enforceApiKeyPolicy(
const allowed =
parsed !== null &&
scope.poolSlugs.length > 0 &&
- scope.poolSlugs.includes(parsed.poolSlug) &&
+ scope.poolSlugs.includes(parsed.groupSlug) &&
scope.providers.includes(parsed.provider);
if (!allowed) {
quotaRejectionMsg = `Model "${modelStr}" is not in this key's quota pools`;
diff --git a/tests/unit/apikeypolicy-quota-only.test.ts b/tests/unit/apikeypolicy-quota-only.test.ts
index 65fd8e81d7..031a7a3e69 100644
--- a/tests/unit/apikeypolicy-quota-only.test.ts
+++ b/tests/unit/apikeypolicy-quota-only.test.ts
@@ -119,9 +119,9 @@ test("quota-only key requesting its quotaShared-* virtual model is allowed", asy
// Build the canonical virtual model name using the same helper the B4 implementation uses.
// Pool "Times" → slug "times"; provider "codex" (canonical, not alias "cx"); model "gpt-5.5"
- // → quotaShared-times-codex/gpt-5.5
+ // → qtSd/times/codex/gpt-5.5 (new format after B3)
const virtualModel = quotaModelName("Times", "codex", "gpt-5.5");
- assert.equal(virtualModel, "quotaShared-times-codex/gpt-5.5");
+ assert.equal(virtualModel, "qtSd/times/codex/gpt-5.5");
const result = await policy.enforceApiKeyPolicy(makeRequest(created.key), virtualModel);
assert.equal(
@@ -181,9 +181,9 @@ test("quota-only key requesting a quotaShared-* model from a different pool is r
const policy = await loadPolicy("b4-quota-otherpool-rejected");
- // quotaShared-* for a DIFFERENT pool slug ("otherpool") — must be rejected
+ // qtSd/ for a DIFFERENT pool slug ("otherpool") — must be rejected
const otherPoolVirtualModel = quotaModelName("OtherPool", "codex", "gpt-5.5");
- assert.equal(otherPoolVirtualModel, "quotaShared-otherpool-codex/gpt-5.5");
+ assert.equal(otherPoolVirtualModel, "qtSd/otherpool/codex/gpt-5.5");
const result = await policy.enforceApiKeyPolicy(makeRequest(created.key), otherPoolVirtualModel);
diff --git a/tests/unit/quota-combo-cli-providers.test.ts b/tests/unit/quota-combo-cli-providers.test.ts
index 53c37f732a..6dce83f0bf 100644
--- a/tests/unit/quota-combo-cli-providers.test.ts
+++ b/tests/unit/quota-combo-cli-providers.test.ts
@@ -1,7 +1,7 @@
/**
* tests/unit/quota-combo-cli-providers.test.ts
*
- * Regression: quotaShared-* combos were generated from PROVIDER_MODELS, which is
+ * Regression: qtSd/ 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.
@@ -44,7 +44,7 @@ test.after(async () => {
const CLI_PROVIDER = "codex"; // absent from PROVIDER_MODELS, present in REGISTRY
-test("syncQuotaCombos generates quotaShared-* combos for a CLI provider (codex) via REGISTRY", async () => {
+test("syncQuotaCombos generates qtSd/ 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;
@@ -65,10 +65,11 @@ test("syncQuotaCombos generates quotaShared-* combos for a CLI provider (codex)
// Before the fix this was 0. Now there must be one combo per codex model.
const all = await combosDb.getCombos();
+ const { QUOTA_MODEL_PREFIX: PREFIX } = await import("../../src/lib/quota/quotaModelNaming.ts");
const quotaCombos = all.filter(
- (c) => typeof c.name === "string" && (c.name as string).startsWith("quotaShared-")
+ (c) => typeof c.name === "string" && (c.name as string).startsWith(PREFIX)
);
- assert.ok(quotaCombos.length > 0, "codex pool must produce quotaShared-* combos (was 0 before fix)");
+ assert.ok(quotaCombos.length > 0, "codex pool must produce qtSd/ combos (was 0 before fix)");
const expectedName = quotaModelName(pool.name, CLI_PROVIDER, firstModelId);
const combo = await combosDb.getComboByName(expectedName);
diff --git a/tests/unit/quota-combos-sync.test.ts b/tests/unit/quota-combos-sync.test.ts
index a63db3d4ca..c022be8cd5 100644
--- a/tests/unit/quota-combos-sync.test.ts
+++ b/tests/unit/quota-combos-sync.test.ts
@@ -115,7 +115,7 @@ test("syncQuotaCombos: creates one combo per glm model with correct name and tar
for (const c of quotaCombos) {
const parsed = parseQuotaModelName(c.name);
assert.ok(parsed, `Could not parse quota model name: ${c.name}`);
- assert.equal(parsed?.poolSlug, quotaPoolSlug("TestGlmPool"));
+ assert.equal(parsed?.groupSlug, quotaPoolSlug("TestGlmPool"));
}
});
@@ -204,7 +204,8 @@ test("syncQuotaCombos: prunes stale combos for same pool slug", async () => {
assert.ok(initialCount > 0, "should have combos after initial sync");
// Manually insert a stale combo with the same pool slug but a nonexistent model
- const staleComboName = `quotaShared-${quotaPoolSlug("PrunePool")}-glm/fake-model-stale`;
+ // Use the new qtSd/ prefix so isQuotaModelName() recognises it as a quota combo to prune.
+ const staleComboName = `qtSd/${quotaPoolSlug("PrunePool")}/glm/fake-model-stale`;
await combosDb.createCombo({
name: staleComboName,
models: [{ kind: "model", model: "glm/fake-model-stale", providerId: "glm", weight: 100 }],
@@ -271,8 +272,8 @@ test("syncQuotaCombos: does not affect quota combos for a different pool slug",
const slugA = quotaPoolSlug("PoolAlpha");
const slugB = quotaPoolSlug("PoolBeta");
- const forA = all.filter((c) => parseQuotaModelName(c.name)?.poolSlug === slugA);
- const forB = all.filter((c) => parseQuotaModelName(c.name)?.poolSlug === slugB);
+ const forA = all.filter((c) => parseQuotaModelName(c.name)?.groupSlug === slugA);
+ const forB = all.filter((c) => parseQuotaModelName(c.name)?.groupSlug === slugB);
assert.ok(forA.length > 0, "PoolAlpha should have combos");
assert.ok(forB.length > 0, "PoolBeta should have combos");
@@ -281,8 +282,8 @@ test("syncQuotaCombos: does not affect quota combos for a different pool slug",
await removeQuotaCombosForPool(poolA.id);
const remaining = await listQuotaCombos();
- const remainingForA = remaining.filter((c) => parseQuotaModelName(c.name)?.poolSlug === slugA);
- const remainingForB = remaining.filter((c) => parseQuotaModelName(c.name)?.poolSlug === slugB);
+ const remainingForA = remaining.filter((c) => parseQuotaModelName(c.name)?.groupSlug === slugA);
+ const remainingForB = remaining.filter((c) => parseQuotaModelName(c.name)?.groupSlug === slugB);
assert.equal(remainingForA.length, 0, "PoolAlpha combos should all be removed");
assert.equal(remainingForB.length, forB.length, "PoolBeta combos should be untouched");
diff --git a/tests/unit/quota-model-naming.test.ts b/tests/unit/quota-model-naming.test.ts
index db5238f63c..bf89ab87fc 100644
--- a/tests/unit/quota-model-naming.test.ts
+++ b/tests/unit/quota-model-naming.test.ts
@@ -3,11 +3,56 @@ import assert from "node:assert/strict";
import {
QUOTA_MODEL_PREFIX,
quotaPoolSlug,
+ quotaGroupSlug,
quotaModelName,
parseQuotaModelName,
isQuotaModelName,
} from "../../src/lib/quota/quotaModelNaming.js";
+// ---------------------------------------------------------------------------
+// QUOTA_MODEL_PREFIX
+// ---------------------------------------------------------------------------
+
+describe("QUOTA_MODEL_PREFIX", () => {
+ it("is qtSd/", () => {
+ assert.equal(QUOTA_MODEL_PREFIX, "qtSd/");
+ });
+});
+
+// ---------------------------------------------------------------------------
+// quotaGroupSlug (new canonical helper)
+// ---------------------------------------------------------------------------
+
+describe("quotaGroupSlug", () => {
+ it("strips non-alphanumeric characters and lowercases", () => {
+ assert.equal(quotaGroupSlug("Pool Principal"), "poolprincipal");
+ });
+
+ it("handles simple lowercase names unchanged", () => {
+ assert.equal(quotaGroupSlug("times"), "times");
+ });
+
+ it("strips dots and slashes", () => {
+ assert.equal(quotaGroupSlug("my.pool/v2"), "mypoolv2");
+ });
+
+ it("falls back to 'pool' for empty result (all-symbol name)", () => {
+ assert.equal(quotaGroupSlug("---"), "pool");
+ });
+
+ it("falls back to 'pool' for empty string", () => {
+ assert.equal(quotaGroupSlug(""), "pool");
+ });
+
+ it("falls back to 'pool' for symbol-only name", () => {
+ assert.equal(quotaGroupSlug("!@#$%"), "pool");
+ });
+});
+
+// ---------------------------------------------------------------------------
+// quotaPoolSlug — backward-compat alias (delegates to quotaGroupSlug)
+// ---------------------------------------------------------------------------
+
describe("quotaPoolSlug", () => {
it("strips non-alphanumeric characters and lowercases", () => {
assert.equal(quotaPoolSlug("Time XPT-2"), "timexpt2");
@@ -34,9 +79,13 @@ describe("quotaPoolSlug", () => {
});
});
+// ---------------------------------------------------------------------------
+// quotaModelName — new qtSd/<group>/<provider>/<model> format
+// ---------------------------------------------------------------------------
+
describe("quotaModelName", () => {
- it("produces the canonical format", () => {
- assert.equal(quotaModelName("Times", "cx", "gpt-5.5"), "quotaShared-times-cx/gpt-5.5");
+ it("produces the new canonical format with group name", () => {
+ assert.equal(quotaModelName("Pool Principal", "codex", "gpt-5.5"), "qtSd/poolprincipal/codex/gpt-5.5");
});
it("uses the prefix constant", () => {
@@ -46,74 +95,89 @@ describe("quotaModelName", () => {
it("keeps provider and model verbatim (not slugged)", () => {
const name = quotaModelName("p", "openai", "org/model-x");
- assert.equal(name, "quotaShared-p-openai/org/model-x");
+ assert.equal(name, "qtSd/p/openai/org/model-x");
});
it("provider with dashes is kept verbatim", () => {
const name = quotaModelName("pool", "some-prov", "m");
- assert.equal(name, "quotaShared-pool-some-prov/m");
+ assert.equal(name, "qtSd/pool/some-prov/m");
+ });
+
+ it("slugs the group name in the prefix segment", () => {
+ assert.equal(quotaModelName("Times", "cx", "gpt-5.5"), "qtSd/times/cx/gpt-5.5");
});
});
+// ---------------------------------------------------------------------------
+// parseQuotaModelName — new format: qtSd/<groupSlug>/<provider>/<model>
+// ---------------------------------------------------------------------------
+
describe("parseQuotaModelName", () => {
it("round-trips a simple model name", () => {
- const name = quotaModelName("Times", "cx", "gpt-5.5");
+ const name = quotaModelName("Pool Principal", "codex", "gpt-5.5");
const parsed = parseQuotaModelName(name);
- assert.deepEqual(parsed, { poolSlug: "times", provider: "cx", model: "gpt-5.5" });
+ assert.deepEqual(parsed, { groupSlug: "poolprincipal", provider: "codex", model: "gpt-5.5" });
});
it("round-trips a model name with a slash in model", () => {
const name = quotaModelName("p", "openai", "org/model-x");
const parsed = parseQuotaModelName(name);
- assert.deepEqual(parsed, { poolSlug: "p", provider: "openai", model: "org/model-x" });
+ assert.deepEqual(parsed, { groupSlug: "p", provider: "openai", model: "org/model-x" });
});
- it("handles provider with a dash", () => {
- const parsed = parseQuotaModelName("quotaShared-pool-some-prov/m");
- assert.deepEqual(parsed, { poolSlug: "pool", provider: "some-prov", model: "m" });
+ it("handles model with multiple slashes", () => {
+ const parsed = parseQuotaModelName("qtSd/mypoolv2/openai/a/b/c");
+ assert.deepEqual(parsed, { groupSlug: "mypoolv2", provider: "openai", model: "a/b/c" });
});
it("returns null for a non-quota model name", () => {
assert.equal(parseQuotaModelName("gpt-4"), null);
});
- it("returns null when there is no '-' after the prefix", () => {
- assert.equal(parseQuotaModelName("quotaShared-noslash"), null);
+ it("returns null for the old quotaShared- format", () => {
+ assert.equal(parseQuotaModelName("quotaShared-pool-cx/gpt-5.5"), null);
});
- it("returns null when there is no '/' in the tail", () => {
- assert.equal(parseQuotaModelName("quotaShared-pool-noslash"), null);
+ it("returns null for too few segments (missing model)", () => {
+ assert.equal(parseQuotaModelName("qtSd/group/provider"), null);
});
it("returns null for empty provider", () => {
- assert.equal(parseQuotaModelName("quotaShared-pool-/model"), null);
+ assert.equal(parseQuotaModelName("qtSd/group//model"), null);
});
it("returns null for empty model", () => {
- assert.equal(parseQuotaModelName("quotaShared-pool-cx/"), null);
+ assert.equal(parseQuotaModelName("qtSd/group/cx/"), null);
});
- it("handles model with multiple slashes", () => {
- const parsed = parseQuotaModelName("quotaShared-mypoolv2-openai/a/b/c");
- assert.deepEqual(parsed, { poolSlug: "mypoolv2", provider: "openai", model: "a/b/c" });
+ it("returns null for empty groupSlug", () => {
+ assert.equal(parseQuotaModelName("qtSd//cx/model"), null);
});
});
+// ---------------------------------------------------------------------------
+// isQuotaModelName
+// ---------------------------------------------------------------------------
+
describe("isQuotaModelName", () => {
it("returns false for plain model names", () => {
assert.equal(isQuotaModelName("gpt-4"), false);
});
it("returns true for valid quota model names", () => {
- assert.equal(isQuotaModelName("quotaShared-x-cx/m"), true);
+ assert.equal(isQuotaModelName("qtSd/poolprincipal/codex/gpt-5.5"), true);
});
it("returns true for any string starting with the prefix", () => {
- assert.equal(isQuotaModelName("quotaShared-"), true);
+ assert.equal(isQuotaModelName("qtSd/"), true);
});
it("is consistent with the QUOTA_MODEL_PREFIX constant", () => {
const name = quotaModelName("pool", "cx", "gpt-4");
assert.equal(isQuotaModelName(name), true);
});
+
+ it("returns false for the old quotaShared- format", () => {
+ assert.equal(isQuotaModelName("quotaShared-x-codex/gpt-5.5"), false);
+ });
});