Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(routing): read image support from the catalog, not a dialect's default

Jack Rudenkob66a2a078815
diff --git a/packages/cli/src/adapters/model-catalog-vision.test.ts b/packages/cli/src/adapters/model-catalog-vision.test.ts
new file mode 100644
index 00000000..24ce9cdf
--- /dev/null
+++ b/packages/cli/src/adapters/model-catalog-vision.test.ts
@@ -0,0 +1,38 @@
+import { expect, test } from "bun:test";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import type { DiskCacheV3 } from "../providers/all-models-cache.js";
+import { lookupModelAcceptsImages } from "./model-catalog.js";
+
+const fixture: DiskCacheV3 = JSON.parse(
+ readFileSync(
+ new URL("../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json", import.meta.url),
+ "utf8"
+ )
+);
+test.each([
+ { modalities: ["image", "text"], vision: false, expected: true },
+ { modalities: ["text"], vision: true, expected: false },
+ { modalities: [], vision: true, expected: true },
+ { modalities: [], vision: false, expected: false },
+ { modalities: undefined, vision: true, expected: true },
+ { modalities: undefined, vision: undefined, expected: undefined },
+ { modalities: [], vision: undefined, expected: undefined },
+])("image input metadata: %j", ({ modalities, vision, expected }) => {
+ const dir = mkdtempSync(join(tmpdir(), "vision-wire-"));
+ try {
+ const cache = structuredClone(fixture);
+ const entry = cache.entries.find((e) => e.modelId === "gpt-6.1-sol")!;
+ if (modalities === undefined) delete entry.inputModalities;
+ else entry.inputModalities = [...modalities];
+ if (vision === undefined) delete entry.supportsVision;
+ else entry.supportsVision = vision;
+ const path = join(dir, "catalog.json");
+ writeFileSync(path, JSON.stringify(cache));
+ expect(lookupModelAcceptsImages(entry.modelId, path)).toBe(expected);
+ expect(lookupModelAcceptsImages("unpublished-model", path)).toBeUndefined();
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
diff --git a/packages/cli/src/adapters/model-catalog.ts b/packages/cli/src/adapters/model-catalog.ts
index 8c905494..903ae4aa 100644
--- a/packages/cli/src/adapters/model-catalog.ts
+++ b/packages/cli/src/adapters/model-catalog.ts
@@ -74,6 +74,20 @@ export function lookupModel(modelId: string, cachePath?: string): ModelEntry | u
};
}
+/**
+ * Whether the catalog says this model accepts images: its `inputModalities`
+ * when published (a list without "image" is a no), else `supportsVision`.
+ * `undefined` when the catalog states neither — unknown, never false.
+ */
+export function lookupModelAcceptsImages(modelId: string, cachePath?: string): boolean | undefined {
+ const entry = findCacheEntry(modelId, cachePath);
+ if (!entry) return undefined;
+ if (Array.isArray(entry.inputModalities) && entry.inputModalities.length > 0) {
+ return entry.inputModalities.includes("image");
+ }
+ return typeof entry.supportsVision === "boolean" ? entry.supportsVision : undefined;
+}
+
/**
* Reasoning capability for a model, straight from the slim catalog.
*
diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.ts
index b60cbc8a..07d39272 100644
--- a/packages/cli/src/handlers/composed-handler.ts
+++ b/packages/cli/src/handlers/composed-handler.ts
@@ -31,7 +31,7 @@ import type { ProviderTransport, StreamFormat } from "../providers/transport/typ
import type { ModelHandler } from "./types.js";
// Alias for readability within this file
type BaseModelAdapter = BaseAPIFormat;
-import { lookupModelForProvider } from "../adapters/model-catalog.js";
+import { lookupModelAcceptsImages, lookupModelForProvider } from "../adapters/model-catalog.js";
import type { QuotaAdapter } from "../auth/quota/adapter.js";
import { resolveQuotaAdapter } from "../auth/quota/registry.js";
import { PLAN_POLL_INTERVAL_MS } from "../auth/quota/types.js";
@@ -405,6 +405,18 @@ export class ComposedHandler implements ModelHandler {
/** Model vision support — model adapter wins over provider adapter */
private getModelSupportsVision(): boolean {
+ // A catalog connection asks the catalog's data about the MODEL (not a
+ // dialect's default by name). Unknown is not "no": an image the user
+ // attached is sent, and the upstream's own answer is what they see.
+ const connection = this.options.connection;
+ if (connection) {
+ if (connection.generationId === "declared") return true;
+ try {
+ return lookupModelAcceptsImages(connection.modelId, this.options.catalogCachePath) ?? true;
+ } catch {
+ return true;
+ }
+ }
return this.modelAdapter?.supportsVision() ?? this.getAdapter().supportsVision();
}