Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
import assert from "node:assert/strict";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { createModels, InMemoryModelsStore } from "@earendil-works/pi-ai";
import { builtinProviders } from "@earendil-works/pi-ai/providers/all";
import { buildProviderModel } from "../../../packages/agent-runtime/dist/provider-binding.js";
import {
apiStyleForAdapter,
bindingForCustomModelInfo,
catalogModelIdsMatch,
modelIdsMatch,
resolveApiStyle,
} from "@pi-desktop/shared";
import {
MODELS_DEV_API_URL,
ModelsDevCatalog,
catalogModelConfigFor,
modelConfigFromModelsDev,
modelInfoFromModelsDev,
parseModelsDevCatalog,
thinkingLevelsFromModelsDev,
} from "../electron/main/models-dev-catalog.ts";
const catalogFixture = {
anthropic: {
name: "Anthropic",
models: {
"claude-opus-4.6": {
id: "claude-opus-4.6",
name: "Claude 4.6 Opus",
description: "High-end Claude for difficult coding, planning, and slower expert reasoning",
family: "claude-opus",
attachment: true,
reasoning: true,
reasoning_options: [{
type: "effort",
values: ["low", "medium", "high", "xhigh", "max"],
}],
tool_call: true,
structured_output: true,
temperature: false,
knowledge: "2025-05-31",
release_date: "2026-02-05",
last_updated: "2026-03-13",
modalities: {
input: ["text", "image", "pdf"],
output: ["text"],
},
open_weights: false,
limit: {
context: 1_000_000,
input: 1_000_000,
output: 128_000,
},
cost: {
input: 5,
output: 25,
cache_read: 0.5,
cache_write: 6.25,
reasoning: 25,
input_audio: 7,
output_audio: 28,
tiers: [{
input: 10,
output: 37.5,
cache_read: 1,
tier: { type: "context", size: 200_000 },
}],
context_over_200k: {
input: 10,
output: 37.5,
cache_read: 1,
cache_write: 12.5,
},
},
interleaved: { field: "reasoning_content" },
status: "stable",
experimental: { modes: { fast: { enabled: true } } },
provider: { npm: "@ai-sdk/anthropic" },
},
"audio-only": {
id: "audio-only",
modalities: { input: ["audio"], output: ["text"] },
},
"metadata-sparse": { id: "metadata-sparse" },
},
},
};
function responseFor(body, status = 200) {
return new Response(JSON.stringify(body), {
status,
headers: { "content-type": "application/json" },
});
}
async function loadFixtureCatalog(t, fixture = catalogFixture) {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-cache-"));
t.after(() => rm(dir, { recursive: true, force: true }));
const catalogPath = join(dir, "api.json");
await writeFile(catalogPath, JSON.stringify(fixture), "utf8");
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
return catalog;
}
test("published metadata retains exact Pi transcript transport bindings through runtime launch", async (t) => {
const pi = createModels({ modelsStore: new InMemoryModelsStore(),
authContext: { env: async () => undefined, fileExists: async () => false } });
for (const provider of builtinProviders()) pi.setProvider(provider);
for (const [vendorKey, modelId] of [
["deepseek", "deepseek-flash"], ["anthropic", "claude-opus-5-5"],
["openai", "gpt-6.1-sol"], ["openai-codex", "gpt-6.1-sol"],
]) {
const original = pi.getModel(vendorKey, modelId);
assert.ok(original, `${vendorKey}/${modelId}`);
const catalog = await loadFixtureCatalog(t, { [vendorKey]: {
name: vendorKey, api: original.baseUrl, models: { [modelId]: {
id: modelId, limit: { context: 543_210, output: 40_000 }, cost: { input: 1.25, output: 2.5 },
} },
} });
const target = { providerId: "account", vendorKey, modelId, baseUrl: original.baseUrl,
apiStyle: resolveApiStyle(original.api) };
const config = catalog.modelConfigFor(target);
assert.equal(config.source, "models.dev");
assert.equal(config.contextWindow, 543_210);
assert.equal(config.maxTokens, 40_000);
assert.equal(config.cost.input, 1.25);
assert.deepEqual(config.transcriptBinding, { modelId, api: original.api, baseUrl: original.baseUrl });
const provider = { ...target, id: "account", name: "Fixture", apiKey: "", authKind: "none",
supportsReasoning: false, supportedThinkingLevels: ["off"], modelConfig: config };
const wire = buildProviderModel(provider);
assert.equal(wire.compat.supportsMidConvoSystemMessages, true, vendorKey);
assert.equal(wire.compat.supportsMidConvoToolChanges, original.compat?.supportsMidConvoToolChanges === true);
assert.equal(wire.compat.supportsAdditionalTools, original.compat?.supportsAdditionalTools === true);
const relay = { ...target, baseUrl: "https://relay.invalid/v1" };
assert.equal(buildProviderModel({ ...provider, ...relay, modelConfig: catalog.modelConfigFor(relay) })
.compat.supportsMidConvoSystemMessages, false);
assert.equal(buildProviderModel({ ...provider, modelId: `${modelId}-alias` })
.compat.supportsMidConvoSystemMessages, false);
}
});
test("the bundled models.dev OpenAI record supplies the selected model limits", async () => {
const catalogPath = fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url));
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const model = catalog.findModel({ vendorKey: "openai", modelId: "gpt-6.1-sol" });
assert.ok(model);
const config = catalogModelConfigFor(catalog, {
providerId: "chatgpt-account",
vendorKey: "openai-codex",
baseUrl: "https://chatgpt.com/backend-api",
modelId: "gpt-6.1-sol",
});
assert.equal(model.limit.context, 1_050_000);
assert.equal(model.limit.output, 128_000);
assert.equal(config.source, "models.dev");
assert.equal(config.contextWindow, 1_050_000);
assert.equal(config.maxTokens, 128_000);
});
test("GPT-6.2 Sol and Astra launch with bundled limits, prices and Pi transport capabilities", async () => {
const catalogPath = fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url));
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const rows = [
["openai", "https://api.openai.com/v1", "openai-responses"],
["openai-codex", "https://chatgpt.com/backend-api", "openai-codex-responses"],
];
for (const [modelId, input, output] of [["gpt-6.2-sol", 2, 10], ["gpt-6.2-astra", 8, 40]]) {
for (const [vendorKey, baseUrl, api] of rows) {
const target = { providerId: "account", vendorKey, modelId, baseUrl, apiStyle: resolveApiStyle(api) };
const config = catalog.modelConfigFor(target);
assert.equal(config.source, "models.dev", `${vendorKey}/${modelId}`);
assert.equal(config.contextWindow, 1_050_000);
assert.equal(config.maxTokens, 128_000);
assert.equal(config.cost.input, input);
assert.equal(config.cost.output, output);
assert.ok(config.supportedThinkingLevels.includes("max"));
assert.deepEqual(config.transcriptBinding, { modelId, api, baseUrl });
const wire = buildProviderModel({ ...target, id: "account", name: "Fixture", apiKey: "", authKind: "none",
supportsReasoning: true, supportedThinkingLevels: ["low"], modelConfig: config });
assert.equal(wire.id, modelId);
assert.equal(wire.compat.supportsMidConvoSystemMessages, true, `${vendorKey}/${modelId}`);
assert.equal(wire.compat.supportsToolSearch, true, `${vendorKey}/${modelId}`);
}
}
});
test("explicit account limits stay pinned over a later models.dev value", async (t) => {
const catalog = await loadFixtureCatalog(t, {
openai: {
name: "OpenAI",
api: "https://api.openai.com/v1",
models: { model: { id: "model", limit: { context: 1_000_000, output: 100_000 } } },
},
});
const info = modelInfoFromModelsDev(catalog.findModel({ vendorKey: "openai", modelId: "model" }), "account");
const binding = bindingForCustomModelInfo("model", info);
binding.contextWindow = 40_000;
binding.contextWindowSource = "user";
binding.maxTokens = 4_000;
binding.maxTokensSource = "user";
catalog.configureAccount({ id: "account", vendorKey: "openai", models: [binding] });
const config = catalog.modelConfigFor({ providerId: "account", vendorKey: "openai", modelId: "model" });
assert.equal(config.contextWindow, 40_000);
assert.equal(config.maxTokens, 4_000);
assert.equal(config.source, "models.dev");
});
function observeModelIdReads(model) {
const modelId = model.modelId;
let reads = 0;
Object.defineProperty(model, "modelId", {
configurable: true,
get() {
reads += 1;
return modelId;
},
});
return () => reads;
}
test("repeated model matches and misses resolve through the bounded catalog index", async (t) => {
const catalog = await loadFixtureCatalog(t);
const input = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };
const match = catalog.findModel(input);
assert.ok(match);
const reads = observeModelIdReads(match);
const perQuery = reads();
assert.equal(catalog.findModel({ ...input }), match);
assert.equal(catalog.findModel({ ...input, modelId: " CLAUDE-OPUS-4.6 " }), match);
// A repeated exact match returns the same catalog object and touches only the
// constant-sized candidate bucket, not a full catalog scan.
assert.ok(reads() - perQuery <= 8, "a repeated match must reuse the catalog result");
const missing = { ...input, modelId: "unpublished-model" };
assert.equal(catalog.findModel(missing), undefined);
const afterMiss = reads();
assert.equal(catalog.findModel({ ...missing }), undefined);
assert.equal(catalog.findModel({ ...missing, modelId: " UNPUBLISHED-MODEL " }), undefined);
// A miss resolves through an empty bucket without scanning or growing the index.
assert.equal(reads(), afterMiss, "a repeated miss must not search again");
});
test("cached matches remain scoped to the requested provider and endpoint", async (t) => {
const fixture = Object.fromEntries(["alpha", "beta"].map((key) => [key, {
name: key,
api: `https://${key}.example/v1`,
models: {
"shared-model": {
id: "shared-model",
name: `${key} model`,
modalities: { input: ["text"], output: ["text"] },
},
},
}]));
const catalog = await loadFixtureCatalog(t, fixture);
const queries = [
[{ vendorKey: "alpha", modelId: "shared-model" }, "alpha"],
[{ vendorKey: "beta", modelId: "shared-model" }, "beta"],
[{ vendorKey: "custom", baseUrl: "https://alpha.example/v1", modelId: "shared-model" }, "alpha"],
[{ vendorKey: "custom", baseUrl: "https://beta.example/v1", modelId: "shared-model" }, "beta"],
[{ vendorKey: "alpha", baseUrl: "https://beta.example/v1", modelId: "shared-model" }, "beta"],
];
for (const [input, providerKey] of [...queries, ...queries.toReversed()]) {
assert.equal(catalog.findModel(input)?.providerKey, providerKey);
}
});
test("unknown endpoints do not inherit ambiguous cross-provider metadata", async (t) => {
for (const order of [["alpha", "beta"], ["beta", "alpha"]]) {
const fixture = Object.fromEntries(order.map((key) => [key, {
api: `https://${key}.example/v1`,
models: {
"shared-model": {
id: "shared-model",
reasoning: key === "alpha",
limit: { context: key === "alpha" ? 128_000 : 32_000, output: 8_192 },
},
},
}]));
const catalog = await loadFixtureCatalog(t, fixture);
for (const modelId of ["shared-model", "proxy/shared-model"]) {
const unknown = { vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId };
assert.equal(catalog.findModel(unknown), undefined, `ambiguous ${modelId} must miss`);
assert.equal(catalog.findModel(unknown), undefined, "ambiguous misses are cached");
}
const alpha = catalog.findModel({
vendorKey: "custom", baseUrl: "https://alpha.example/v1", modelId: "shared-model",
});
assert.equal(alpha?.providerKey, "alpha", "an exact endpoint scopes the lookup");
assert.equal(alpha?.reasoning, true);
assert.equal(alpha?.limit.context, 128_000);
const beta = catalog.findModel({ vendorKey: "beta", modelId: "shared-model" });
assert.equal(beta?.providerKey, "beta", "a known provider key scopes the lookup");
assert.equal(beta?.reasoning, false);
assert.equal(beta?.limit.context, 32_000);
}
});
test("an unknown endpoint can use a unique exact last-segment match", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: { models: { "shared-model": { id: "shared-model", reasoning: true } } },
});
assert.equal(catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "proxy/shared-model",
})?.providerKey, "alpha");
});
test("a known endpoint cannot borrow another provider's catalog model", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: { api: "https://alpha.example/v1", models: { "alpha-only": { id: "alpha-only" } } },
beta: { api: "https://beta.example/v1", models: { "proxy/shared-model": { id: "proxy/shared-model", reasoning: true } } },
});
assert.equal(catalog.findModel({ baseUrl: "https://alpha.example/v1", modelId: "shared-model" }), undefined);
assert.equal(catalog.findModel({ baseUrl: "https://beta.example/v1", modelId: "shared-model" })?.providerKey, "beta");
});
test("a shared catalog API prefers the explicitly selected vendor", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: { api: "https://gateway.example/v1", models: { "alpha-only": { id: "alpha-only" } } },
beta: { api: "https://gateway.example/v1", models: { "beta-only": { id: "beta-only" } } },
});
const input = { vendorKey: "beta", baseUrl: "https://gateway.example/v1" };
assert.equal(catalog.findModel({ ...input, modelId: "beta-only" })?.providerKey, "beta");
assert.equal(catalog.findModel({ ...input, modelId: "alpha-only" }), undefined);
});
test("a shared catalog API with no vendor key cannot select the first publisher", async (t) => {
for (const order of [["alpha", "beta"], ["beta", "alpha"]]) {
const catalog = await loadFixtureCatalog(t, Object.fromEntries(order.map((key) => [key, {
api: "https://gateway.example/v1",
models: { "shared-model": { id: "shared-model", reasoning: key === "alpha",
limit: { context: key === "alpha" ? 128_000 : 32_000, output: 8_192 } } },
}])));
assert.equal(catalog.providerKeyForRow({ vendorKey: "custom", baseUrl: "https://gateway.example/v1" }), undefined);
assert.equal(catalog.findModel({ vendorKey: "custom", baseUrl: "https://gateway.example/v1", modelId: "shared-model" }), undefined);
assert.equal(catalog.findModel({ vendorKey: "beta", baseUrl: "https://gateway.example/v1", modelId: "shared-model" })?.providerKey, "beta");
}
});
test("a recognized endpoint takes priority over an unrelated vendor fallback", async (t) => {
const catalog = await loadFixtureCatalog(t, {
openai: { models: { "shared-model": { id: "shared-model" } } },
deepseek: { models: { "shared-model": { id: "shared-model" } } },
});
assert.equal(catalog.findModel({
vendorKey: "openai",
baseUrl: "https://api.deepseek.com",
modelId: "shared-model",
})?.providerKey, "deepseek");
});
test("model lookup memory is bounded by the catalog, not by query count", async (t) => {
const catalog = await loadFixtureCatalog(t);
const input = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };
const match = catalog.findModel(input);
assert.ok(match);
const reads = observeModelIdReads(match);
// Thousands of distinct miss queries do not grow the per-generation index and
// do not evict an already-resolved key from it.
for (let index = 0; index < 3_000; index += 1) {
assert.equal(catalog.findModel({ ...input, modelId: `unknown-${index}` }), undefined);
}
const beforeRepeat = reads();
assert.equal(catalog.findModel(input), match);
// The resolved key stays resolvable to the same object without a catalog rescan.
assert.ok(reads() - beforeRepeat <= 8, "a resolved key stays usable after many distinct queries");
});
test("one read with more distinct keys than any cache budget does not rescan a resolved key", async (t) => {
const catalog = await loadFixtureCatalog(t);
const input = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };
const match = catalog.findModel(input);
assert.ok(match);
const reads = observeModelIdReads(match);
const baseline = reads();
const exactRepeats = 2_000;
// Interleave the originally resolved key among a burst of distinct keys far
// larger than the former 1,024-entry per-key eviction cache.
for (let index = 0; index < exactRepeats; index += 1) {
catalog.findModel({ ...input, modelId: `unknown-${index}` });
catalog.findModel(input);
}
const touches = reads() - baseline;
// Each exact re-query resolves through a bounded candidate bucket, so the work
// stays proportional to the repeated queries and independent of the distinct
// keys interleaved between them. The old 1,024-entry eviction cache would rescan
// the whole catalog (thousands of model reads) on every repeat once its budget
// was exceeded, growing with the distinct-key burst.
assert.ok(
touches <= exactRepeats * 8,
`exact re-queries touched the model ${touches} times, expected <= ${exactRepeats * 8}`,
);
});
test("model IDs match provider namespaces without matching model variants", () => {
assert.equal(modelIdsMatch("anthropic-claude-opus-5", "claude-opus-5"), true);
assert.equal(modelIdsMatch("anthropic/claude-opus-5", "claude-opus-5"), true);
assert.equal(modelIdsMatch("claude-opus-5@default", "claude-opus-5"), true);
assert.equal(modelIdsMatch("claude-opus-5-fast", "claude-opus-5"), false);
for (const suffix of ["agent", "latest", "thinking", "think"]) {
assert.equal(modelIdsMatch("foo", `foo-${suffix}`), false);
assert.equal(modelIdsMatch(`foo-${suffix}`, "foo"), false);
}
assert.equal(modelIdsMatch("gateway-a/foo", "gateway-b/foo"), false);
assert.equal(modelIdsMatch("foo@us-east", "foo@eu-west"), false);
assert.equal(modelIdsMatch("proxy/openai/gpt-4o", "openai/gpt-4o"), true);
assert.equal(modelIdsMatch("openai/gpt-4o", "proxy/gpt-4o"), false);
});
test("catalog metadata IDs match only exact case-insensitive last segments", () => {
for (const [catalogId, request] of [
["claude-opus-4.6", "proxy/claude-opus-4.6"],
["openai/gpt-4o", "hub/gpt-4o"],
["google/gemini-2.5-flash", "openai/gemini-2.5-flash"],
["proxy/nested/claude-opus-4.6", "other/CLAUDE-OPUS-4.6"],
["gateway-a/foo", "gateway-b/foo"],
]) {
assert.equal(catalogModelIdsMatch(catalogId, request), true, `${catalogId} / ${request}`);
assert.equal(catalogModelIdsMatch(request, catalogId), true, `${request} / ${catalogId}`);
}
for (const [catalogId, request] of [
["claude-opus-4.6", "proxy/claude-opus-4.6-thinking"],
["claude-opus-4.6", "claude-opus-4.6:thinking"],
["claude-opus-4.6", "proxy/claude-opus-4.6-agent"],
["claude-opus-4.6", "proxy/claude-opus-4.6-latest"],
["anthropic-claude-opus-4.6", "claude-opus-4.6"],
["google/gemini-pro-latest", "ag/gemini-pro-agent"],
["foo", "foo-think"],
["foo", "foo-agent"],
["foo", "foo-latest"],
["foo@us-east", "foo"],
]) {
assert.equal(catalogModelIdsMatch(catalogId, request), false, `${catalogId} / ${request}`);
assert.equal(catalogModelIdsMatch(request, catalogId), false, `${request} / ${catalogId}`);
}
});
test("catalog lookup uses exact last segments and rejects ambiguous matches", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { models: {
"model": { id: "model" },
"nested/unique-model": { id: "nested/unique-model", reasoning: true },
"google/gemini-pro-latest": { id: "google/gemini-pro-latest", reasoning: true },
"route-a/shared-leaf": { id: "route-a/shared-leaf", reasoning: true },
"route-b/shared-leaf": { id: "route-b/shared-leaf", reasoning: false },
"regional@us-east": { id: "regional@us-east" },
} },
});
assert.equal(
catalog.findModel({ vendorKey: "custom", modelId: "proxy/UNIQUE-MODEL" })?.modelId,
"nested/unique-model",
);
assert.equal(catalog.findModel({ vendorKey: "custom", modelId: "other/model" })?.modelId, "model");
assert.equal(catalog.findModel({ vendorKey: "custom", modelId: "proxy/shared-leaf" }), undefined);
assert.equal(catalog.findModel({ vendorKey: "gateway", modelId: "proxy/shared-leaf" }), undefined);
assert.equal(catalog.findModel({ vendorKey: "custom", modelId: "ag/gemini-pro-agent" }), undefined);
assert.equal(catalog.findModel({ vendorKey: "custom", modelId: "regional" }), undefined);
assert.equal(
catalog.findModel({ vendorKey: "custom", modelId: "proxy/regional@us-east" })?.modelId,
"regional@us-east",
);
});
test("ambiguous leaf matches prefer one official provider", async (t) => {
for (const order of [["relay", "openai"], ["openai", "relay"]]) {
const definitions = {
relay: { models: { "route/shared-leaf": {
id: "route/shared-leaf", reasoning: false, tool_call: false,
limit: { context: 32_000 },
} } },
openai: { models: { "shared-leaf": {
id: "shared-leaf", reasoning: true, tool_call: true,
reasoning_options: [{ type: "effort", values: ["low", "medium", "high"] }],
limit: { context: 128_000 },
} } },
};
const catalog = await loadFixtureCatalog(t, Object.fromEntries(
order.map((key) => [key, definitions[key]]),
));
const match = catalog.findModel({ vendorKey: "custom", modelId: "proxy/shared-leaf" });
assert.equal(match?.providerKey, "openai");
assert.equal(match?.reasoning, true);
assert.equal(match?.limit.context, 128_000);
}
});
test("official source keys ignore a cloud publisher carrying another vendor's model", async (t) => {
const catalog = await loadFixtureCatalog(t, {
xai: { models: { "grok-4.6": {
id: "grok-4.6", reasoning: true, tool_call: true,
reasoning_options: [{ type: "effort", values: ["low", "medium", "high", "xhigh"] }],
limit: { context: 500_000 },
} } },
"google-vertex": { models: { "xai/grok-4.6": {
id: "xai/grok-4.6", reasoning: true, tool_call: true,
limit: { context: 524_288 },
} } },
relay: { models: { "x-ai/grok-4.6": {
id: "x-ai/grok-4.6", reasoning: false, tool_call: false,
} } },
});
const match = catalog.findModel({ vendorKey: "custom", modelId: "ycj/grok-4.6" });
assert.equal(match?.providerKey, "xai");
assert.equal(match?.limit.context, 500_000);
});
test("ambiguous non-official leaf matches share unanimous capabilities", async (t) => {
const catalog = await loadFixtureCatalog(t, {
relayA: { models: { "route-a/shared-leaf": {
id: "route-a/shared-leaf", reasoning: true, tool_call: true,
reasoning_options: [{ type: "effort", values: ["low", "high"] }],
modalities: { input: ["text", "image"], output: ["text"] },
limit: { context: 64_000, output: 8_192 },
} } },
relayB: { models: { "route-b/shared-leaf": {
id: "route-b/shared-leaf", reasoning: true, tool_call: true,
reasoning_options: [{ type: "effort", values: ["low", "high"] }],
modalities: { input: ["image", "text"], output: ["text"] },
limit: { context: 128_000, output: 16_384 },
} } },
});
const match = catalog.findModel({ vendorKey: "custom", modelId: "proxy/shared-leaf" });
assert.ok(match);
assert.equal(match.reasoning, true);
assert.equal(match.toolCall, true);
assert.deepEqual(match.thinkingLevels, ["low", "high"]);
assert.deepEqual(match.modalities.input.toSorted(), ["image", "text"]);
});
test("ambiguous leaf matches with conflicting capabilities remain unmatched", async (t) => {
const catalog = await loadFixtureCatalog(t, {
relayA: { models: { "route-a/shared-leaf": {
id: "route-a/shared-leaf", reasoning: true, tool_call: true,
} } },
relayB: { models: { "route-b/shared-leaf": {
id: "route-b/shared-leaf", reasoning: false, tool_call: true,
} } },
});
assert.equal(
catalog.findModel({ vendorKey: "custom", modelId: "proxy/shared-leaf" }),
undefined,
);
});
test("gemini agent routes do not collapse to gemini latest catalog entries", async (t) => {
const catalog = await loadFixtureCatalog(t, {
google: { models: {
"gemini-pro-latest": { id: "gemini-pro-latest", reasoning: true },
} },
});
assert.equal(
catalog.findModel({ vendorKey: "custom", modelId: "ag/gemini-pro-agent" }),
undefined,
);
});
test("catalog lookup never collapses reasoning or release suffix variants", async (t) => {
const catalog = await loadFixtureCatalog(t);
const exact = catalog.findModel({ vendorKey: "custom", modelId: "proxy/claude-opus-4.6" });
assert.equal(exact?.modelId, "claude-opus-4.6");
assert.equal(exact.reasoning, true);
for (const modelId of [
"proxy/claude-opus-4.6-thinking",
"proxy/claude-opus-4.6-agent",
"proxy/claude-opus-4.6-latest",
"claude-opus-4.6:thinking",
"anthropic-claude-opus-4.6",
]) {
assert.equal(catalog.findModel({ vendorKey: "custom", modelId }), undefined, modelId);
}
});
/*
A gateway is indexed by models.dev under the vendor that owns the weights, so
an endpoint serving `Vendor/Model` ids often has no record of its own while
several other publishers state the identical id. Issue #938: those rows used
to fall back to the generic 128k text-only shape, hiding a correct context
window and tool support that the catalog does publish.
*/
test("an id the row's own catalog provider lacks borrows a unanimous exact-id record", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: { "gateway/own-model": { id: "gateway/own-model" } } },
publisherA: { models: { "Vendor/Shared-Model-0731": {
id: "Vendor/Shared-Model-0731", tool_call: true, reasoning: true,
modalities: { input: ["text", "image"], output: ["text"] },
attachment: true, family: "shared",
limit: { context: 262_144, output: 65_536 },
} } },
publisherB: { models: { "Vendor/Shared-Model-0731": {
id: "Vendor/Shared-Model-0731", tool_call: true, reasoning: true,
modalities: { input: ["text", "image"], output: ["text"] },
attachment: true, family: "shared",
limit: { context: 1_048_576, output: 32_768 },
} } },
});
const match = catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Shared-Model-0731",
});
assert.ok(match, "a published exact id must not drop to the generic shape");
assert.equal(match.toolCall, true);
assert.equal(match.reasoning, true);
const info = modelInfoFromModelsDev(match, "provider-1");
assert.equal(info.capabilities.includes("tools"), true);
assert.equal(info.capabilities.includes("vision"), true);
// Limits are the medians the publishers state; an even count takes the lower
// middle, so a borrow never rounds a window up on its own.
assert.equal(match.limit.context, 262_144);
assert.equal(match.limit.output, 32_768);
});
test("a borrowed record under-claims instead of asserting one publisher's extras", async (t) => {
// Both publishers agree on tool support, so the id is borrowable. They differ
// on vision, reasoning and structured output, so none of those may be
// reported: the borrow may only claim what every publisher states.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: { "gateway/own-model": { id: "gateway/own-model" } } },
publisherA: { models: { "Vendor/Mixed": {
id: "Vendor/Mixed", tool_call: true, reasoning: true, structured_output: true,
modalities: { input: ["text", "image"], output: ["text"] }, attachment: true,
limit: { context: 262_144 },
} } },
publisherB: { models: { "Vendor/Mixed": {
id: "Vendor/Mixed", tool_call: true, reasoning: false, structured_output: false,
modalities: { input: ["text"], output: ["text"] }, attachment: false,
limit: { context: 262_144 },
} } },
});
const match = catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Mixed",
});
assert.ok(match, "unanimous tool support is enough to borrow");
assert.equal(match.toolCall, true);
assert.equal(match.reasoning, false);
// A capability the publishers do not state unanimously is left unasserted
// (`undefined` means "no published answer"), never claimed from one source.
assert.equal(match.structuredOutput, undefined);
assert.equal(match.attachment, undefined);
assert.deepEqual(match.modalities.input, ["text"]);
const info = modelInfoFromModelsDev(match, "provider-1");
assert.equal(info.capabilities.includes("vision"), false);
assert.equal(info.capabilities.includes("reasoning"), false);
});
test("an even split on tool support leaves conflicting leaves unmatched", async (t) => {
// Conflicting capability signatures (tool_call) mean shared-capabilities enrichment
// must miss — no majority/consensus borrow for an unanchored / empty-gateway row.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Split": { id: "Vendor/Split", tool_call: true, limit: { context: 262_144 } } } },
publisherB: { models: { "Vendor/Split": { id: "Vendor/Split", tool_call: false, limit: { context: 262_144 } } } },
});
assert.equal(catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Split",
}), undefined);
});
test("a borrowed record never replaces what the row's own catalog provider publishes", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {
"Vendor/Shared-Model": { id: "Vendor/Shared-Model", tool_call: false, limit: { context: 200_000 } },
} },
publisherA: { models: {
"Vendor/Shared-Model": { id: "Vendor/Shared-Model", tool_call: true, limit: { context: 1_048_576 } },
} },
});
const match = catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Shared-Model",
});
assert.equal(match?.providerKey, "gateway");
assert.equal(match.limit.context, 200_000);
assert.equal(match.toolCall, false);
});
test("publishers that disagree about capabilities remain unmatched", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Disputed": {
id: "Vendor/Disputed", tool_call: true, reasoning: true, limit: { context: 262_144 },
} } },
publisherB: { models: { "Vendor/Disputed": {
id: "Vendor/Disputed", tool_call: false, reasoning: false, limit: { context: 262_144 },
} } },
});
assert.equal(catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Disputed",
}), undefined);
});
test("a majority of publishers with conflicting capability signatures stays unmatched", async (t) => {
// #1047 does not majority-vote across publishers for an empty/unanchored row.
// Conflicting tool_call signatures ⇒ unmatched.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 262_144 } } } },
publisherB: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 1_048_576 } } } },
publisherC: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 1_048_576 } } } },
publisherD: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: false, limit: { context: 1_048_576 } } } },
});
assert.equal(catalog.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Majority",
}), undefined);
});
test("conflicting reseller and shipped records for a leaf stay unmatched without an official", async (t) => {
// deepseek is not an official/source family for #1047 disambiguation, and the
// capability signatures conflict, so an unanchored relay must miss.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
deepseek: { models: { "shared-model": {
id: "shared-model", tool_call: true, limit: { context: 1_000_000, output: 393_216 },
} } },
resellerA: { models: { "shared-model": {
id: "shared-model", tool_call: false, limit: { context: 128_000, output: 8_192 },
} } },
resellerB: { models: { "shared-model": {
id: "shared-model", tool_call: false, limit: { context: 131_072, output: 8_192 },
} } },
});
assert.equal(catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "shared-model",
}), undefined);
});
test("resellers still answer for an id no shipped publisher states", async (t) => {
// The preference above is not a filter: an id only resellers publish would
// otherwise be shown as a generic 128k text-only row.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
resellerA: { models: { "reseller-only-model": {
id: "reseller-only-model", tool_call: true, limit: { context: 262_144 },
} } },
resellerB: { models: { "reseller-only-model": {
id: "reseller-only-model", tool_call: true, limit: { context: 262_144 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "reseller-only-model",
});
assert.ok(match, "a published id must not drop to the generic shape");
assert.equal(match.toolCall, true);
assert.equal(match.limit.context, 262_144);
});
test("route prefixes and official deployment markers resolve without rewriting served IDs", async (t) => {
// Exact last-segment match allows `test/mimo-v2.5` → `mimo-v2.5`.
// Model variants like `-thinking` / `-asr` are parts of the leaf and never
// strip; a whitelisted deployment label (`-test`, `-1m`) still reduces to
// the owner's published base ID.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: {
"gemini-2.5-pro": {
id: "gemini-2.5-pro", tool_call: true,
limit: { context: 1_048_576, output: 65_536 },
},
} },
xiaomi: { models: {
"mimo-v2.5": {
id: "mimo-v2.5", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
limit: { context: 1_048_576, output: 131_072 },
},
"mimo-v2.5-pro": {
id: "mimo-v2.5-pro", tool_call: true, limit: { context: 1_048_576, output: 131_072 },
},
} },
});
const relay = (modelId) =>
catalog.findModel({ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId });
for (const served of ["test/mimo-v2.5", "mimo-v2.5"]) {
assert.equal(relay(served)?.modelId, "mimo-v2.5", `${served} reads the published model`);
assert.equal(relay(served)?.limit.context, 1_048_576);
}
const info = modelInfoFromModelsDev(relay("test/mimo-v2.5"), "provider-1");
assert.ok(info.capabilities.includes("vision"));
assert.equal(relay("mimo-v2.5-thinking"), undefined);
assert.equal(relay("test/mimo-v2.5-pro-test")?.modelId, "mimo-v2.5-pro");
assert.equal(relay("mimo-v2.5-asr"), undefined);
assert.equal(relay("gemini-2.5-pro-1m")?.modelId, "gemini-2.5-pro");
});
test("a shipped publisher answers first for a row anchored to a reseller", async (t) => {
// The row's own publisher is known and publishes nothing for this id, so the
// borrow runs — and it reads the publisher the app ships before the resellers
// that also carry the id.
const catalog = await loadFixtureCatalog(t, {
reseller: { api: "https://reseller.example/v1", models: { "reseller/own": { id: "reseller/own" } } },
xai: { models: { "Vendor/Model": {
id: "Vendor/Model", tool_call: true, limit: { context: 500_000, output: 500_000 },
} } },
otherA: { models: { "Vendor/Model": {
id: "Vendor/Model", tool_call: false, limit: { context: 128_000, output: 8_192 },
} } },
otherB: { models: { "Vendor/Model": {
id: "Vendor/Model", tool_call: false, limit: { context: 131_072, output: 8_192 },
} } },
});
const match = catalog.findModel({
vendorKey: "reseller",
baseUrl: "https://reseller.example/v1",
modelId: "Vendor/Model",
});
assert.equal(match?.providerKey, "xai", "the shipped publisher's record answers");
assert.equal(match.toolCall, true);
assert.equal(match.limit.context, 500_000);
assert.equal(match.limit.output, 500_000);
});
test("an unanchored relay reads its family owner's record over a conflicting reseller spelling", async (t) => {
// `mimo-v2.5` and `XiaomiMiMo/MiMo-V2.5` share a case-insensitive leaf but
// disagree on modalities, so the shared-capabilities enrichment misses. The
// weight owner's exact record still answers an unidentified relay — the way
// the pre-catalog relay lookup did: a reseller's narrower copy never decides
// the window or modalities.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
xiaomi: { models: { "mimo-v2.5": {
id: "mimo-v2.5", tool_call: true,
modalities: { input: ["text", "image", "audio"], output: ["text"] },
limit: { context: 1_048_576, output: 131_072 },
} } },
huggingface: { models: { "XiaomiMiMo/MiMo-V2.5": {
id: "XiaomiMiMo/MiMo-V2.5", tool_call: true,
modalities: { input: ["text"], output: ["text"] },
limit: { context: 1_048_576, output: 131_072 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "mimo-v2.5",
});
assert.equal(match?.providerKey, "xiaomi", "the owner's record wins the unanchored relay");
assert.deepEqual(match?.modalities.input, ["text", "image", "audio"]);
assert.equal(match?.limit.context, 1_048_576);
});
test("an unanchored relay prefers its owner's limits over matching reseller copies", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
xiaomi: { models: { "mimo-v2.5": {
id: "mimo-v2.5", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
limit: { context: 1_048_576, output: 131_072 },
} } },
reseller: { models: { "mimo-v2.5": {
id: "mimo-v2.5", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
limit: { context: 262_144, output: 16_384 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "mimo-v2.5",
});
assert.equal(match?.providerKey, "xiaomi");
assert.equal(match?.limit.context, 1_048_576);
assert.equal(match?.limit.output, 131_072);
});
test("an unanchored relay stays generic when owner aliases disagree on capacity", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
minimax: { models: { "MiniMax-M2.7": {
id: "MiniMax-M2.7", tool_call: true,
limit: { context: 204_800, output: 131_072 },
} } },
"minimax-cn": { models: { "MiniMax-M2.7": {
id: "MiniMax-M2.7", tool_call: true,
limit: { context: 128_000, output: 65_536 },
} } },
});
assert.equal(catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "MiniMax-M2.7",
}), undefined, "conflicting owner limits must not be chosen by catalog order");
});
test("unique leaf enrichment coexists with exact-id borrowing and unknown misses", async (t) => {
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: {
"Vendor/Known": { id: "Vendor/Known", limit: { context: 262_144 } },
"Vendor/Known-2507": { id: "Vendor/Known-2507", limit: { context: 131_072 } },
} },
});
const input = { vendorKey: "gateway", baseUrl: "https://gateway.example/v1" };
// Near-miss and unknown ids do not reuse a sibling's limits.
assert.equal(catalog.findModel({ ...input, modelId: "Vendor/Known-3000" }), undefined);
assert.equal(catalog.findModel({ ...input, modelId: "unknown-model-xyz" }), undefined);
// A different route with the same unique final segment is valid enrichment.
assert.equal(catalog.findModel({ ...input, modelId: "Other/Known" })?.modelId, "Vendor/Known");
// Exact ids still resolve, including a case-only difference.
assert.equal(catalog.findModel({ ...input, modelId: "vendor/known" })?.limit.context, 262_144);
assert.equal(catalog.findModel({ ...input, modelId: "Vendor/Known" })?.limit.context, 262_144);
assert.equal(catalog.findModel({ ...input, modelId: "Vendor/Known-2507" })?.limit.context, 131_072);
// The sibling exists under a different id, so nothing is borrowed through it.
assert.equal(
catalog.findModel({ ...input, modelId: "Vendor/Known-2507" })?.modelId,
"Vendor/Known-2507",
);
});
test("a provider sharing the row's endpoint owns its own negative answer", async (t) => {
// Two names for one endpoint: an id published only by the sibling is not
// borrowed, because that sibling was already consulted and does not list it.
const catalog = await loadFixtureCatalog(t, {
alpha: { api: "https://gateway.example/v1", models: { "alpha-only": { id: "alpha-only" } } },
beta: { api: "https://gateway.example/v1", models: { "beta-only": { id: "beta-only" } } },
});
const input = { vendorKey: "beta", baseUrl: "https://gateway.example/v1" };
assert.equal(catalog.findModel({ ...input, modelId: "alpha-only" }), undefined);
// A different endpoint is a genuinely independent source and still transfers.
const other = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Elsewhere": { id: "Vendor/Elsewhere", limit: { context: 262_144 } } } },
});
assert.equal(
other.findModel({
vendorKey: "gateway",
baseUrl: "https://gateway.example/v1",
modelId: "Vendor/Elsewhere",
})?.limit.context,
262_144,
);
});
test("models.dev records retain all published model parameters and modalities", () => {
const [provider] = parseModelsDevCatalog(catalogFixture);
assert.equal(provider.providerKey, "anthropic");
assert.equal(provider.models.length, 3, "raw parsing keeps non-text records too");
const model = provider.models.find((item) => item.modelId === "claude-opus-4.6");
assert.equal(model.providerApi, undefined);
assert.equal(model.displayName, "Claude 4.6 Opus");
assert.equal(model.description, "High-end Claude for difficult coding, planning, and slower expert reasoning");
assert.equal(model.family, "claude-opus");
assert.equal(model.attachment, true);
assert.equal(model.reasoning, true);
assert.deepEqual(model.reasoningOptions, [{
type: "effort",
values: ["low", "medium", "high", "xhigh", "max"],
}]);
assert.deepEqual(model.modalities, {
input: ["text", "image", "pdf"],
output: ["text"],
});
assert.deepEqual(model.limit, {
context: 1_000_000,
input: 1_000_000,
output: 128_000,
});
assert.deepEqual(model.cost, {
input: 5,
output: 25,
cacheRead: 0.5,
cacheWrite: 6.25,
reasoning: 25,
inputAudio: 7,
outputAudio: 28,
tiers: [{
input: 10,
output: 37.5,
cacheRead: 1,
tier: { type: "context", size: 200_000 },
}],
contextOver200k: {
input: 10,
output: 37.5,
cacheRead: 1,
cacheWrite: 12.5,
},
});
assert.deepEqual(model.interleaved, { field: "reasoning_content" });
assert.equal(model.status, "stable");
assert.equal(model.temperature, false);
assert.deepEqual(model.experimental, { modes: { fast: { enabled: true } } });
assert.deepEqual(model.provider, { npm: "@ai-sdk/anthropic" });
const info = modelInfoFromModelsDev(model, "provider-row");
assert.equal(info.providerId, "provider-row");
assert.equal(info.contextWindow, 1_000_000);
assert.equal(info.maxTokens, 128_000);
assert.ok(info.capabilities.includes("text"));
assert.ok(info.capabilities.includes("tools"));
assert.ok(info.capabilities.includes("vision"));
assert.ok(info.capabilities.includes("pdf"));
assert.ok(info.capabilities.includes("reasoning"));
assert.ok(info.capabilities.includes("json"));
assert.ok(info.capabilities.includes("attachments"));
assert.equal(info.capabilities.includes("temperature"), false);
assert.equal(info.catalogSource, "models.dev");
assert.deepEqual(info.thinkingLevelMap, {
low: "low",
medium: "medium",
high: "high",
xhigh: "xhigh",
max: "max",
// Effort ladder without a published none/off value (#603).
off: null,
});
assert.deepEqual(info.provider, { npm: "@ai-sdk/anthropic" });
assert.deepEqual(info.experimental, { modes: { fast: { enabled: true } } });
assert.ok(
modelInfoFromModelsDev({ ...model, temperature: true }, "provider-row").capabilities.includes(
"temperature",
),
);
const allModalities = {
input: ["text", "image", "audio", "video", "pdf"],
output: ["text", "image", "audio", "video", "pdf"],
};
const multimodalInfo = modelInfoFromModelsDev(
{ ...model, modalities: allModalities },
"provider-row",
);
assert.deepEqual(multimodalInfo.modalities, allModalities);
for (const capability of ["vision", "audio", "video", "pdf"]) {
assert.ok(multimodalInfo.capabilities.includes(capability), capability);
}
const config = modelConfigFromModelsDev(model, "https://api.anthropic.com");
assert.equal(config.source, "models.dev");
assert.equal(config.name, "Claude 4.6 Opus");
assert.equal(config.contextWindow, 1_000_000);
assert.equal(config.maxTokens, 128_000);
assert.deepEqual(config.input, ["text", "image"]);
assert.deepEqual(config.modalities, info.modalities);
assert.deepEqual(config.supportedThinkingLevels, ["low", "medium", "high", "xhigh", "max"]);
assert.equal(config.thinkingProtocol, "adaptive");
assert.deepEqual(config.thinkingLevelMap, {
low: "low",
medium: "medium",
high: "high",
xhigh: "xhigh",
max: "max",
// Effort ladder without a published none/off value (#603).
off: null,
});
assert.equal(config.cost.reasoning, 25);
assert.deepEqual(config.provider, { npm: "@ai-sdk/anthropic" });
assert.deepEqual(config.catalogProvider, { npm: "@ai-sdk/anthropic" });
assert.deepEqual(config.experimental, { modes: { fast: { enabled: true } } });
assert.equal(config.cost.inputAudio, 7);
assert.equal(config.cost.outputAudio, 28);
assert.equal(config.cost.tiers?.[0]?.tier?.size, 200_000);
assert.equal(config.interleaved?.field, "reasoning_content");
const sparse = provider.models.find((item) => item.modelId === "metadata-sparse");
assert.equal(sparse.reasoningPublished, false);
assert.equal(sparse.modalitiesPublished, false);
});
test("models.dev parsing keeps the per-model wire API with a responses-only fallback", () => {
const [provider, llmGateway] = parseModelsDevCatalog({
"opencode-go": {
name: "OpenCode Go",
api: "https://opencode.ai/zen/go/v1",
models: {
"muse-spark-1.3-contributor": { id: "muse-spark-1.3-contributor" },
"deepseek-v4-flash": { id: "deepseek-v4-flash" },
"custom-responses": { id: "custom-responses", api: "openai-responses" },
},
},
"llmgateway": {
name: "LLM Gateway",
models: {
"muse-spark-1.3-contributor": { id: "muse-spark-1.3-contributor" },
},
},
});
const byId = Object.fromEntries(provider.models.map((model) => [model.modelId, model]));
assert.equal(byId["muse-spark-1.3-contributor"].modelApi, "openai-responses");
assert.equal(byId["deepseek-v4-flash"].modelApi, undefined);
assert.equal(byId["custom-responses"].modelApi, "openai-responses");
const gatewayMuse = llmGateway.models.find((model) => model.modelId === "muse-spark-1.3-contributor");
assert.equal(gatewayMuse.modelApi, undefined);
const config = modelConfigFromModelsDev(
byId["muse-spark-1.3-contributor"],
"https://opencode.ai/zen/go/v1",
);
assert.equal(config.api, "openai-responses");
});
test("models.dev parsing retains every model in a provider", () => {
const models = Object.fromEntries(
Array.from({ length: 627 }, (_, index) => [
`model-${String(index).padStart(4, "0")}`,
{ id: `model-${String(index).padStart(4, "0")}` },
]),
);
const [provider] = parseModelsDevCatalog({
provider: { name: "Provider", models },
});
assert.equal(provider.models.length, 627);
assert.equal(provider.models.at(-1)?.modelId, "model-0626");
});
test("matches vendor-prefixed models when the catalog provider key is a gateway", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-provider-match-"));
const catalogPath = join(dir, "api.json");
await writeFile(
catalogPath,
JSON.stringify({
gateway: {
name: "Gateway",
api: "https://gateway.example/v1",
models: {
"deepseek/deepseek-v4": {
id: "deepseek/deepseek-v4",
name: "DeepSeek V4",
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
limit: { context: 128_000, output: 16_000 },
},
},
},
}),
"utf8",
);
try {
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const match = catalog.findModel({
vendorKey: "deepseek",
modelId: "deepseek-v4",
});
assert.equal(match?.modelId, "deepseek/deepseek-v4");
assert.deepEqual(match?.modalities.input, ["text", "image", "pdf"]);
assert.equal(
catalog.modelsForProvider({ vendorKey: "deepseek", providerId: "row" }).length,
1,
);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("maps the OpenAI Codex account to OpenAI models.dev metadata", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-openai-codex-"));
const catalogPath = join(dir, "api.json");
await writeFile(
catalogPath,
JSON.stringify({
openai: {
name: "OpenAI",
models: {
"gpt-5.6-sol": {
id: "gpt-5.6-sol",
name: "GPT-5.6 Sol",
reasoning: true,
reasoning_options: [{
type: "effort",
values: ["none", "low", "medium", "high", "xhigh", "max"],
}],
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
limit: { context: 1_050_000, output: 128_000 },
},
},
},
}),
"utf8",
);
try {
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const input = {
vendorKey: "openai-codex",
baseUrl: "https://chatgpt.com/backend-api",
modelId: "gpt-5.6-sol",
};
const match = catalog.findModel(input);
assert.equal(match?.providerKey, "openai");
assert.equal(match?.reasoning, true);
assert.deepEqual(match?.thinkingLevels, [
"off",
"low",
"medium",
"high",
"xhigh",
"max",
]);
assert.equal(match?.limit.context, 1_050_000);
assert.equal(match?.limit.output, 128_000);
assert.equal(catalog.providerKeyForRow(input), "openai");
const fallback = catalog.modelsForProvider({
vendorKey: input.vendorKey,
baseUrl: input.baseUrl,
providerId: "oauth-row",
});
assert.equal(fallback.length, 1);
assert.equal(fallback[0].modelId, "gpt-5.6-sol");
assert.deepEqual(fallback[0].supportedThinkingLevels, [
"off",
"low",
"medium",
"high",
"xhigh",
"max",
]);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("matches Zhipu and Z.AI endpoints by catalog URL and vendor aliases", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-zhipu-"));
const catalogPath = join(dir, "api.json");
await writeFile(
catalogPath,
JSON.stringify({
zhipuai: {
name: "Zhipu AI",
api: "https://open.bigmodel.cn/api/paas/v4",
models: {
"glm-5": {
id: "glm-5",
name: "GLM-5",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 204_800, output: 131_072 },
},
},
},
"zhipuai-coding-plan": {
name: "Zhipu AI Coding Plan",
api: "https://open.bigmodel.cn/api/coding/paas/v4",
models: {
"glm-5.3": {
id: "glm-5.3",
name: "GLM-5.3",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 1_000_000, output: 131_072 },
},
},
},
zai: {
name: "Z.AI",
api: "https://api.z.ai/api/paas/v4",
models: {
"glm-5.1": {
id: "glm-5.1",
name: "GLM-5.1",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 200_000, output: 131_072 },
},
},
},
"zai-coding-plan": {
name: "Z.AI Coding Plan",
api: "https://api.z.ai/api/coding/paas/v4",
models: {
"glm-5.2": {
id: "glm-5.2",
name: "GLM-5.2",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 1_000_000, output: 131_072 },
},
},
},
}),
"utf8",
);
try {
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const chinaApi = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://open.bigmodel.cn/api/paas/v4",
modelId: "glm-5",
});
assert.equal(chinaApi?.providerKey, "zhipuai");
const chinaCoding = catalog.findModel({
vendorKey: "zai-coding-cn",
modelId: "glm-5.3",
});
assert.equal(chinaCoding?.providerKey, "zhipuai-coding-plan");
assert.equal(chinaCoding?.modelId, "glm-5.3");
const intlCoding = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://api.z.ai/api/coding/paas/v4",
modelId: "glm-5.2",
});
assert.equal(intlCoding?.providerKey, "zai-coding-plan");
assert.equal(
catalog.providerKeyForRow({
vendorKey: "bigmodel",
baseUrl: "https://open.bigmodel.cn/api/paas/v4",
}),
"zhipuai",
);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("maps MiniMax OpenAI-compatible endpoints to multimodal catalog metadata", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-minimax-openai-"));
const catalogPath = join(dir, "api.json");
await writeFile(
catalogPath,
JSON.stringify({
"minimax-cn": {
name: "MiniMax (China)",
api: "https://api.minimaxi.com/anthropic/v1",
models: {
"MiniMax-M3": {
id: "MiniMax-M3",
name: "MiniMax-M3",
attachment: true,
reasoning: true,
modalities: { input: ["text", "image", "video"], output: ["text"] },
limit: { context: 1_048_576, output: 524_288 },
},
},
},
}),
"utf8",
);
try {
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true);
const input = {
vendorKey: "custom",
baseUrl: "https://api.minimaxi.com/v1",
providerId: "custom-row",
};
const match = catalog.findModel({ ...input, modelId: "MiniMax-M3" });
assert.equal(match?.providerKey, "minimax-cn");
assert.deepEqual(match?.modalities.input, ["text", "image", "video"]);
assert.equal(match?.attachment, true);
assert.equal(catalog.modelsForProvider(input)[0]?.modelId, "MiniMax-M3");
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("models.dev reasoning options map to canonical levels", () => {
assert.deepEqual(
thinkingLevelsFromModelsDev(true, [{
type: "effort",
values: ["max", "low", "none", "invalid"],
}]),
["off", "low", "max"],
);
assert.deepEqual(thinkingLevelsFromModelsDev(true, [{ type: "toggle" }]), ["off", "medium"]);
assert.deepEqual(thinkingLevelsFromModelsDev(true, [{ type: "budget_tokens", min: 1024 }]), ["off", "medium"]);
assert.deepEqual(thinkingLevelsFromModelsDev(true, []), ["low", "medium", "high"]);
assert.deepEqual(thinkingLevelsFromModelsDev(false, [{ type: "effort", values: ["high"] }]), []);
});
test("toggle ladders still map off to none", () => {
const [provider] = parseModelsDevCatalog({
vendor: {
name: "Vendor",
models: {
"toggle-model": {
id: "toggle-model",
reasoning: true,
reasoning_options: [{ type: "toggle" }],
},
},
},
});
const info = modelInfoFromModelsDev(provider.models[0], "row");
assert.equal(info.thinkingLevelMap?.off, "none");
});
test("the application loads the bundled release snapshot without network access", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-release-"));
const catalogPath = join(dir, "api.json");
await writeFile(catalogPath, JSON.stringify(catalogFixture), "utf8");
let calls = 0;
try {
const catalog = new ModelsDevCatalog({
catalogPath,
fetchImpl: async () => {
calls += 1;
throw new Error("startup must not fetch");
},
});
assert.equal(
catalog.findModel({ vendorKey: "anthropic", modelId: "claude-opus-4.6" }),
undefined,
"a lookup before the bundled snapshot loads can miss",
);
assert.equal(await catalog.ensureLoaded(), true);
assert.equal(calls, 0);
assert.equal(catalog.getStatus().source, "bundled");
assert.equal(catalog.getStatus().catalogPath, catalogPath);
assert.equal(
catalog.findModel({ vendorKey: "anthropic", modelId: "claude-opus-4.6" })?.family,
"claude-opus",
);
assert.equal(
catalog.modelsForProvider({ vendorKey: "anthropic", providerId: "row" }).length,
2,
"only text-capable models enter the agent picker",
);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("the bundled snapshot maps the latest 0.87.1 model ids to usable metadata", async () => {
const catalog = new ModelsDevCatalog({
catalogPath: fileURLToPath(new URL("../resources/models.dev/api.json", import.meta.url)),
});
assert.equal(await catalog.ensureLoaded(), true);
const cases = [
{
vendorKey: "openai-codex",
baseUrl: "https://chatgpt.com/backend-api",
modelId: "gpt-6-sol",
contextWindow: 1_050_000,
maxTokens: 128_000,
thinkingLevels: ["off", "low", "medium", "high", "xhigh", "max"],
},
{
vendorKey: "openai-codex",
baseUrl: "https://chatgpt.com/backend-api",
modelId: "gpt-6-luna",
contextWindow: 1_050_000,
maxTokens: 128_000,
thinkingLevels: ["off", "low", "medium", "high", "xhigh", "max"],
},
{
vendorKey: "anthropic",
baseUrl: "https://api.anthropic.com",
modelId: "claude-opus-5-5",
contextWindow: 1_000_000,
maxTokens: 128_000,
thinkingLevels: ["low", "medium", "high", "xhigh", "max"],
},
{
vendorKey: "xai",
baseUrl: "https://api.x.ai/v1",
modelId: "grok-4.7",
contextWindow: 500_000,
maxTokens: 500_000,
thinkingLevels: ["low", "medium", "high", "xhigh"],
},
];
for (const expected of cases) {
const model = catalog.findModel(expected);
assert.ok(model, `${expected.vendorKey}/${expected.modelId} must be in the snapshot`);
assert.equal(model.reasoning, true);
assert.deepEqual(model.thinkingLevels, expected.thinkingLevels);
assert.deepEqual(model.modalities.input, ["text", "image", "pdf"]);
const config = modelConfigFromModelsDev(model, expected.baseUrl);
assert.equal(config.contextWindow, expected.contextWindow);
assert.equal(config.maxTokens, expected.maxTokens);
assert.deepEqual(config.input, ["text", "image"]);
}
const copilotClaude = catalog.findModel({
vendorKey: "github-copilot",
baseUrl: "https://api.individual.githubcopilot.com",
modelId: "claude-opus-5.5",
});
assert.ok(copilotClaude, "GitHub Copilot must include Claude Opus 5.5");
assert.equal(copilotClaude.reasoning, true);
assert.equal(copilotClaude.limit.context, 1_000_000);
});
test("concurrent catalog reads share the bundled snapshot load", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-concurrent-load-"));
const catalogPath = join(dir, "api.json");
await writeFile(catalogPath, JSON.stringify(catalogFixture), "utf8");
try {
const catalog = new ModelsDevCatalog({ catalogPath });
const first = catalog.ensureLoaded();
const second = catalog.ensureLoaded();
assert.equal(await first, true);
assert.equal(await second, true);
assert.equal(
catalog.findModel({ vendorKey: "anthropic", modelId: "claude-opus-4.6" })?.family,
"claude-opus",
);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("Settings refresh always refetches models.dev and only updates memory", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-refresh-"));
const catalogPath = join(dir, "api.json");
await writeFile(catalogPath, JSON.stringify(catalogFixture), "utf8");
const refreshedFixture = {
...catalogFixture,
anthropic: {
...catalogFixture.anthropic,
models: {
...catalogFixture.anthropic.models,
"claude-opus-4.6": {
...catalogFixture.anthropic.models["claude-opus-4.6"],
name: "Updated Claude",
},
"new-model": {
id: "new-model",
name: "New Model",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 64_000, output: 4_000 },
},
},
},
};
const calls = [];
try {
const catalog = new ModelsDevCatalog({
catalogPath,
fetchImpl: async (url, options) => {
calls.push({ url, options });
return responseFor(refreshedFixture);
},
});
assert.equal(await catalog.ensureLoaded(), true);
const existingInput = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };
const previousMatch = catalog.findModel(existingInput);
assert.ok(previousMatch);
assert.equal(catalog.findModel({ vendorKey: "anthropic", modelId: "new-model" }), undefined);
assert.equal(calls.length, 0);
assert.equal(await catalog.refresh(), true);
assert.equal(calls.length, 1);
assert.equal(calls[0].url, MODELS_DEV_API_URL);
assert.deepEqual(calls[0].options.headers, { Accept: "application/json" });
const refreshedMatch = catalog.findModel(existingInput);
assert.notEqual(refreshedMatch, previousMatch);
assert.equal(refreshedMatch?.displayName, "Updated Claude");
assert.equal(
catalog.findModel({ vendorKey: "anthropic", modelId: "new-model" })?.displayName,
"New Model",
);
assert.deepEqual(
JSON.parse(await readFile(catalogPath, "utf8")),
catalogFixture,
"settings refresh must not write the bundled release resource",
);
assert.equal(await catalog.refresh(), true, "a second settings refresh is also remote");
assert.equal(calls.length, 2);
assert.equal(catalog.getStatus().source, "remote");
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("a failed settings refresh preserves the bundled snapshot in memory", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-models-dev-failure-"));
const catalogPath = join(dir, "api.json");
await writeFile(catalogPath, JSON.stringify(catalogFixture), "utf8");
try {
const catalog = new ModelsDevCatalog({
catalogPath,
fetchImpl: async () => {
throw new Error("offline");
},
});
assert.equal(await catalog.ensureLoaded(), true);
const input = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };
const match = catalog.findModel(input);
assert.ok(match);
const reads = observeModelIdReads(match);
const missing = { ...input, modelId: "unpublished-model" };
assert.equal(catalog.findModel(missing), undefined);
const beforeRefresh = reads();
assert.equal(await catalog.refresh(), false);
assert.equal(catalog.findModel(input), match);
assert.equal(catalog.findModel(missing), undefined);
assert.equal(reads(), beforeRefresh, "a failed refresh preserves both cached matches and misses");
assert.equal(
catalog.findModel({ vendorKey: "anthropic", modelId: "claude-opus-4.6" })?.family,
"claude-opus",
);
assert.match(catalog.getStatus().lastError, /offline/);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
/*
The published `npm` / `env` / `doc` fields survive parsing because the setup
form still derives the wire API from the adapter package and still points the
user at the provider's own docs. Migrated here when the catalog-search suite
was removed with the browsable-catalog UI.
*/
test("parsed providers keep the published npm, env and doc fields", () => {
const providers = parseModelsDevCatalog({
anthropic: {
id: "anthropic",
name: "Anthropic",
npm: "@ai-sdk/anthropic",
api: "https://api.anthropic.com",
doc: "https://docs.anthropic.com",
env: ["ANTHROPIC_API_KEY"],
models: {
"claude-opus-4.6": {
id: "claude-opus-4.6",
name: "Claude 4.6 Opus",
modalities: { input: ["text"], output: ["text"] },
limit: { context: 200000, output: 64000 },
},
},
},
"openrouter-lite": {
id: "openrouter-lite",
name: "OpenRouter Lite",
npm: "@ai-sdk/openai-compatible",
models: {
"some-model": {
id: "some-model",
name: "Some Model",
modalities: { input: ["text"], output: ["text"] },
},
},
},
});
const anthropic = providers.find((item) => item.providerKey === "anthropic");
assert.equal(anthropic.npm, "@ai-sdk/anthropic");
assert.equal(anthropic.doc, "https://docs.anthropic.com");
assert.deepEqual(anthropic.env, ["ANTHROPIC_API_KEY"]);
assert.equal(anthropic.api, "https://api.anthropic.com");
const gateway = providers.find((item) => item.providerKey === "openrouter-lite");
assert.deepEqual(gateway.env, [], "a provider without env vars parses to an empty list");
assert.equal(gateway.doc, undefined);
});
test("the wire API style is derived from the published adapter package", () => {
assert.equal(apiStyleForAdapter("@ai-sdk/anthropic"), "anthropic_messages");
assert.equal(apiStyleForAdapter("@ai-sdk/google-vertex/anthropic"), "anthropic_messages");
assert.equal(apiStyleForAdapter("@ai-sdk/google"), "google_generative_ai");
assert.equal(apiStyleForAdapter("@ai-sdk/openai"), "responses");
// The long tail of gateways is OpenAI-compatible chat completions.
assert.equal(apiStyleForAdapter("@ai-sdk/openai-compatible"), "chat_completions");
assert.equal(apiStyleForAdapter(undefined), "chat_completions");
});
// A custom Anthropic Messages gateway (unknown base URL, vendorKey "custom")
// serving a Claude id that several catalog providers publish with differing
// reasoning options. The lookup refuses to pick one publisher, but the thinking
// wire shape of an exact Anthropic id is Anthropic's own (#990).
const ambiguousClaudeFixture = {
anthropic: {
name: "Anthropic",
npm: "@ai-sdk/anthropic",
models: {
"claude-opus-5-5": {
id: "claude-opus-5-5",
name: "Claude Opus 5.5",
reasoning: true,
reasoning_options: [{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] }],
tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
limit: { context: 1_000_000, output: 128_000 },
},
},
},
requesty: {
name: "Requesty",
npm: "@ai-sdk/openai-compatible",
api: "https://router.requesty.ai/v1",
models: {
"claude-opus-5-5": {
id: "claude-opus-5-5",
name: "Claude Opus 5.5",
reasoning: true,
reasoning_options: [
{ type: "effort", values: ["none", "low", "medium", "high", "max"] },
{ type: "budget_tokens" },
],
tool_call: true,
modalities: { input: ["text"], output: ["text"] },
limit: { context: 200_000, output: 64_000 },
},
"glm-5": {
id: "glm-5",
name: "GLM 5",
reasoning: true,
reasoning_options: [{ type: "effort", values: ["low", "high"] }],
tool_call: true,
modalities: { input: ["text"], output: ["text"] },
limit: { context: 200_000, output: 32_000 },
},
},
},
};
const customGateway = {
vendorKey: "custom",
baseUrl: "https://gateway.example/v1",
};
test("a custom gateway enriches an ambiguous Claude leaf from the official provider", async (t) => {
const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);
const config = catalogModelConfigFor(catalog, {
...customGateway,
apiStyle: "anthropic_messages",
modelId: "claude-opus-5-5",
});
assert.equal(config.source, "models.dev");
assert.equal(config.contextWindow, 1_000_000);
assert.equal(config.maxTokens, 128_000);
assert.equal(config.reasoning, true);
assert.deepEqual(config.reasoningOptions, [
{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] },
]);
assert.deepEqual(config.thinkingLevelMap, {
low: "low",
medium: "medium",
high: "high",
xhigh: "xhigh",
max: "max",
off: null,
});
});
test("official-provider enrichment is API-style independent while unknown ids stay generic", async (t) => {
const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);
const completions = catalogModelConfigFor(catalog, {
...customGateway,
apiStyle: "chat_completions",
modelId: "claude-opus-5-5",
});
assert.equal(completions.source, "models.dev");
assert.equal(completions.contextWindow, 1_000_000);
assert.deepEqual(completions.reasoningOptions, [
{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] },
]);
// An id absent from every publisher stays generic, even on Anthropic Messages.
const unlisted = catalogModelConfigFor(catalog, {
...customGateway,
apiStyle: "anthropic_messages",
modelId: "unlisted-reasoning-model",
});
assert.equal(unlisted.source, "generic");
assert.equal(unlisted.reasoningOptions, undefined);
assert.equal(unlisted.thinkingLevelMap, undefined);
// Aliases of a Claude id are not an exact Anthropic id.
const renamed = catalogModelConfigFor(catalog, {
...customGateway,
apiStyle: "anthropic_messages",
modelId: "my-claude-opus-5-5-thinking",
});
assert.equal(renamed.reasoningOptions, undefined);
});
test("a resolved catalog record still wins over the Anthropic thinking fallback", async (t) => {
const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);
const config = catalogModelConfigFor(catalog, {
vendorKey: "requesty",
baseUrl: "https://router.requesty.ai/v1",
apiStyle: "anthropic_messages",
modelId: "claude-opus-5-5",
});
assert.equal(config.source, "models.dev");
assert.equal(config.contextWindow, 200_000);
assert.ok(config.reasoningOptions?.some((option) => option.type === "budget_tokens"));
});
/*
Release stamps in the published catalog.
A gateway serves `mify/mimo-v2.5-pro-0731` while models.dev indexes the model
under the id that owns the weights. The alias only ever borrows metadata: the
id the row is addressed with stays the discovery result.
*/
test("a dated snapshot leaf does not borrow an undated published model", async (t) => {
const catalog = await loadFixtureCatalog(t, {
mify: {
api: "https://api.mify.example/v1",
models: {
"mimo-v2.5-pro": {
id: "mimo-v2.5-pro",
name: "MiMo v2.5 Pro",
reasoning: true,
tool_call: true,
limit: { context: 262_144, output: 32_768 },
},
},
},
});
assert.equal(
catalog.findModel({ vendorKey: "mify", modelId: "mify/mimo-v2.5-pro-0731" }),
undefined,
);
});
test("exact published leaves resolve without release-stamp aliasing", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: { api: "https://alpha.example/v1", models: {
"foo-v2": { id: "foo-v2", limit: { context: 32_000 } },
"foo-v2-0731": { id: "foo-v2-0731", limit: { context: 128_000 } },
} },
beta: { api: "https://beta.example/v1", models: {
"foo-v2": { id: "foo-v2", limit: { context: 64_000 } },
} },
});
const exact = catalog.findModel({ vendorKey: "alpha", modelId: "foo-v2-0731" });
assert.equal(exact?.modelId, "foo-v2-0731");
assert.equal(exact?.limit.context, 128_000);
// Unpublished stamps do not strip down to a shorter sibling.
assert.equal(catalog.findModel({ vendorKey: "alpha", modelId: "foo-v2-0815" }), undefined);
// Same leaf, identical capabilities (limits are not part of the signature) ⇒
// shared-capabilities enrichment with the lower median window.
const shared = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "foo-v2",
});
assert.equal(shared?.limit.context, 32_000);
// A uniquely published dated leaf still enriches.
const published = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://relay.example/v1",
modelId: "foo-v2-0731",
});
assert.equal(published?.providerKey, "alpha");
assert.equal(published?.limit.context, 128_000);
});
/*
A custom endpoint is often the same publisher on another path.
The reported failure: a custom row at `https://open.bigmodel.cn/api/v1` listed
its models but every one of them showed generic defaults, because provider
matching only accepted models.dev's own path for that host.
*/
test("a custom endpoint on a uniquely published host inherits that publisher", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: {
api: "https://alpha.example/api/paas/v4",
models: {
"glm-5.3": {
id: "glm-5.3",
reasoning: true,
tool_call: true,
limit: { context: 1_000_000, output: 131_072 },
},
},
},
});
const model = catalog.findModel({
vendorKey: "custom",
baseUrl: "https://alpha.example/api/v1",
modelId: "glm-5.3",
});
assert.equal(model?.providerKey, "alpha");
assert.equal(model?.limit.context, 1_000_000);
assert.equal(model?.toolCall, true);
// The whole row's records are reachable, not just the one id.
assert.equal(
catalog.modelsForProvider({ vendorKey: "custom", baseUrl: "https://alpha.example/api/v1", providerId: "row" }).length,
1,
);
});
test("a host two publishers share leaves conflicting leaves unmatched", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: {
api: "https://shared.example/api/paas/v4",
models: { "glm-5.3": { id: "glm-5.3", reasoning: true, limit: { context: 1_000_000 } } },
},
beta: {
api: "https://shared.example/api/coding/v4",
models: { "glm-5.3": { id: "glm-5.3", reasoning: false, limit: { context: 32_000 } } },
},
});
assert.equal(catalog.findModel({
vendorKey: "custom",
baseUrl: "https://shared.example/v1",
modelId: "glm-5.3",
}), undefined);
// Naming the publisher still resolves it to that publisher's own record.
const alpha = catalog.findModel({
vendorKey: "alpha",
baseUrl: "https://shared.example/v1",
modelId: "glm-5.3",
});
assert.equal(alpha?.providerKey, "alpha");
assert.equal(alpha?.limit.context, 1_000_000);
});
test("a relay's dotted version name reads the owner's dashed published record", async (t) => {
// `claude-sonnet-4.5` is Claude's `claude-sonnet-4-5`: a notation difference,
// not a distinct model, so the owner's own published record answers.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
anthropic: { models: { "claude-sonnet-4-5": {
id: "claude-sonnet-4-5", tool_call: true, limit: { context: 200_000, output: 64_000 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "claude-sonnet-4.5",
});
assert.ok(match, "a dotted version alias must reach the owner's published record");
assert.equal(match.providerKey, "anthropic");
assert.equal(match.modelId, "claude-sonnet-4-5", "the wire id is never rewritten");
assert.equal(match.limit.context, 200_000);
assert.equal(match.limit.output, 64_000);
});
test("a relay's canonical generation name reads the owner's live record", async (t) => {
// The relay serves `deepseek-v4.1-flash` — models.dev's canonical id for
// DeepSeek's current flash model, which DeepSeek publishes only under version
// aliases. The live (non-deprecated) alias is what answers.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
deepseek: { models: {
"deepseek-flash": {
id: "deepseek-flash", tool_call: true,
canonical_model_id: "deepseek/deepseek-v4.1-flash",
limit: { context: 1_000_000, output: 393_216 },
},
"deepseek-v4-flash": {
id: "deepseek-v4-flash", tool_call: true, status: "deprecated",
canonical_model_id: "deepseek/deepseek-v4.1-flash",
limit: { context: 1_000_000, output: 393_216 },
},
} },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "deepseek-v4.1-flash",
});
assert.ok(match, "the owner's canonical id must not drop to the generic seed");
assert.equal(match.providerKey, "deepseek");
assert.equal(match.modelId, "deepseek-flash", "the live alias answers, not the deprecated one");
assert.equal(match.limit.context, 1_000_000);
});
test("a generation name the catalog never publishes stays unmatched", async (t) => {
// `gemini-3-flash` is a distinct (non-preview) model the catalog does not
// publish; a preview record must not answer for it.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: { "gemini-3-flash-preview": {
id: "gemini-3-flash-preview", tool_call: true, limit: { context: 1_000_000 },
} } },
});
assert.equal(catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "gemini-3-flash",
}), undefined);
});
test("a vendor's sibling keys answer for a family the primary key never states", async (t) => {
// `qwen3.8-flash` lives only on Alibaba's token-plan key, while the relay
// serves it under the family name. The primary key states nothing, so the
// vendor's own sibling key supplies the record rather than a reseller copy.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
alibaba: { models: { "qwen3.7-flash": {
id: "qwen3.7-flash", tool_call: true, limit: { context: 1_000_000, output: 131_072 },
} } },
"alibaba-token-plan": { models: { "qwen3.8-flash": {
id: "qwen3.8-flash", tool_call: true, limit: { context: 1_000_000, output: 131_072 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "qwen3.8-flash",
});
assert.equal(match?.providerKey, "alibaba-token-plan");
assert.equal(match?.limit.context, 1_000_000);
assert.equal(match?.limit.output, 131_072);
});
test("a sibling key that contradicts the primary key cannot suppress its answer", async (t) => {
// Alibaba's public key and token-plan key disagree about the same id. The
// token-plan key is only in the new widened tier, so it cannot veto the
// primary tier's answer.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
alibaba: { models: { "qwen3.8-flash": {
id: "qwen3.8-flash", tool_call: true, limit: { context: 512_000, output: 64_000 },
} } },
"alibaba-token-plan": { models: { "qwen3.8-flash": {
id: "qwen3.8-flash", tool_call: true, limit: { context: 1_000_000, output: 131_072 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "qwen3.8-flash",
});
assert.equal(match?.providerKey, "alibaba");
assert.equal(match?.limit.context, 512_000);
assert.equal(match?.limit.output, 64_000);
});
test("a corroborated canonical declaration translates a relay-only generation name", async (t) => {
// The relay serves `gemini-3-flash`, which its owner never publishes; two
// independent publishers carry it only under a vendor-prefixed id and both
// declare it canonical for `gemini-3-flash-preview`. Their own capability
// flags disagree — as resellers' do in the live catalog — so no shared
// reseller record answers and the owner path decides. The declaration only
// translates the name; the capacity stays Google's own.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: { "gemini-3-flash-preview": {
id: "gemini-3-flash-preview", tool_call: true,
limit: { context: 1_048_576, output: 65_536 },
} } },
neon: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000, output: 1 },
} } },
pioneer: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000, output: 2 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "gemini-3-flash",
});
assert.equal(match?.providerKey, "google", "the owner's own record answers");
assert.equal(match?.modelId, "gemini-3-flash-preview");
assert.equal(match?.limit.context, 1_048_576, "capacity comes from the owner, not the declarers");
assert.equal(match?.limit.output, 65_536);
});
test("one reseller's private alias is not evidence for a canonical translation", async (t) => {
// A single publisher's own naming choice must not rewrite the id: the served
// name keeps the record that reseller publishes for it, and the owner's
// preview record is never projected onto it.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: { "gemini-3-flash-preview": {
id: "gemini-3-flash-preview", tool_call: true, limit: { context: 1_048_576 },
} } },
"some-reseller": { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "gemini-3-flash",
});
assert.equal(match?.providerKey, "some-reseller", "the served id keeps its own publisher");
assert.equal(match?.limit.context, 1_000_000, "an uncorroborated alias never borrows the owner's capacity");
});
test("an ambiguous canonical translation stays unmatched", async (t) => {
// Two corroborated targets say the name maps two ways. The resellers disagree
// on capability flags, so no shared record answers either; nothing is claimed.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: {
"gemini-3-flash-preview": {
id: "gemini-3-flash-preview", tool_call: true, limit: { context: 1_048_576 },
},
"gemini-3-flash-lite": {
id: "gemini-3-flash-lite", tool_call: true, limit: { context: 1_000_000 },
},
} },
neon: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000 },
} } },
pioneer: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000 },
} } },
opencode: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
canonical_model_id: "google/gemini-3-flash-lite",
limit: { context: 1_000_000 },
} } },
vercel: { models: { "google/gemini-3-flash": {
id: "google/gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-lite",
limit: { context: 1_000_000 },
} } },
});
assert.equal(catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "gemini-3-flash",
}), undefined);
});
test("a canonical translation never displaces an id that already resolves", async (t) => {
// The relay's id is published outright by a reseller, so the ordinary lookup
// answers. A corroborated declaration pointing elsewhere must not override
// that: translation only fills a gap, it never rewrites a served name.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
google: { models: { "gemini-3-flash-preview": {
id: "gemini-3-flash-preview", tool_call: true, limit: { context: 1_048_576 },
} } },
neon: { models: { "gemini-3-flash": {
id: "gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000 },
} } },
pioneer: { models: { "gemini-3-flash": {
id: "gemini-3-flash", tool_call: true,
canonical_model_id: "google/gemini-3-flash-preview",
limit: { context: 1_000_000 },
} } },
});
const match = catalog.findModel({
vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "gemini-3-flash",
});
assert.equal(match?.modelId, "gemini-3-flash", "the served id keeps its own record");
});