Block OpenRouter meta routes from model registry

This commit is contained in:
Mikael Hugo 2026-04-30 10:07:36 +02:00
parent 1dbd30c713
commit 7a09d476c1
3 changed files with 10 additions and 79 deletions

View file

@ -65,6 +65,9 @@ async function fetchOpenRouterModels(): Promise<Model<any>[]> {
const models: Model<any>[] = [];
for (const model of data.data) {
if (model.id === "openrouter/auto" || model.id === "openrouter/free") {
continue;
}
// Only include models that support tools
if (!model.supported_parameters?.includes("tools")) continue;
@ -1037,29 +1040,6 @@ async function generateModels() {
});
}
// Add "auto" alias for openrouter/auto
if (!allModels.some(m => m.provider === "openrouter" && m.id === "auto")) {
allModels.push({
id: "auto",
name: "Auto",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: true,
input: ["text", "image"],
cost: {
// we dont know about the costs because OpenRouter auto routes to different models
// and then charges you for the underlying used model
input:0,
output:0,
cacheRead:0,
cacheWrite:0,
},
contextWindow: 2000000,
maxTokens: 30000,
});
}
// Google Cloud Code Assist models (Gemini CLI) — sourced from
// @google/gemini-cli-core's VALID_GEMINI_MODELS so new models ship
// automatically on `npm update @google/gemini-cli-core`. cli-core is

View file

@ -216,13 +216,8 @@ describe("MODELS structural invariants", () => {
});
it("every model has a cost object with non-negative numeric fields", () => {
const knownNegativeCostModels = new Set([
"openrouter/openrouter/auto",
]);
const invalid: string[] = [];
for (const { providerKey, modelKey, model } of allModels()) {
if (knownNegativeCostModels.has(`${providerKey}/${modelKey}`)) continue;
const cost = model["cost"] as Record<string, unknown> | undefined;
if (!cost || typeof cost !== "object") {
invalid.push(`${providerKey}/${modelKey}: missing cost object`);
@ -238,6 +233,13 @@ describe("MODELS structural invariants", () => {
assert.deepEqual(invalid, [], `Models with invalid cost fields:\n ${invalid.join("\n ")}`);
});
it("does not expose OpenRouter meta-router aliases as selectable models", () => {
const openrouterModels = MODELS["openrouter"] as Record<string, unknown>;
for (const id of ["auto", "openrouter/auto", "openrouter/free"]) {
assert.equal(openrouterModels[id], undefined, `openrouter/${id} must be blocked`);
}
});
it("no provider has duplicate model IDs", () => {
const duplicates: string[] = [];
for (const [providerKey, providerModels] of Object.entries(MODELS)) {

View file

@ -7320,23 +7320,6 @@ export const MODELS = {
contextWindow: 131072,
maxTokens: 64000,
} satisfies Model<"openai-completions">,
"auto": {
id: "auto",
name: "Auto",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: true,
input: ["text", "image"],
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 2000000,
maxTokens: 30000,
} satisfies Model<"openai-completions">,
"baidu/ernie-4.5-21b-a3b": {
id: "baidu/ernie-4.5-21b-a3b",
name: "Baidu: ERNIE 4.5 21B A3B",
@ -9700,23 +9683,6 @@ export const MODELS = {
contextWindow: 200000,
maxTokens: 100000,
} satisfies Model<"openai-completions">,
"openrouter/auto": {
id: "openrouter/auto",
name: "Auto Router",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: true,
input: ["text", "image"],
cost: {
input: -1000000,
output: -1000000,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 2000000,
maxTokens: 4096,
} satisfies Model<"openai-completions">,
"openrouter/elephant-alpha": {
id: "openrouter/elephant-alpha",
name: "Elephant",
@ -9734,23 +9700,6 @@ export const MODELS = {
contextWindow: 262144,
maxTokens: 32768,
} satisfies Model<"openai-completions">,
"openrouter/free": {
id: "openrouter/free",
name: "Free Models Router",
api: "openai-completions",
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: true,
input: ["text", "image"],
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 200000,
maxTokens: 4096,
} satisfies Model<"openai-completions">,
"prime-intellect/intellect-3": {
id: "prime-intellect/intellect-3",
name: "Prime Intellect: INTELLECT-3",