Skip to content

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

refactor(routing)!: remove model-name API, token and effort rules

Jack Rudenko0d40e3961415
diff --git a/packages/cli/src/adapters/base-api-format.ts b/packages/cli/src/adapters/base-api-format.ts
index e6fa23d9..a832d60c 100644
--- a/packages/cli/src/adapters/base-api-format.ts
+++ b/packages/cli/src/adapters/base-api-format.ts
@@ -922,6 +922,18 @@ export abstract class BaseAPIFormat implements APIFormat, ModelDialect {
*/
protected pinnedEffort?: EffortLevel;
+ /**
+ * The upstream model's vendor from its catalog connection (`""` when the
+ * catalog names none); undefined without a connection. Set by the handler
+ * that owns a connection, so upstream-family behaviour reads data, not the
+ * model name.
+ */
+ protected upstreamVendor?: string;
+
+ setUpstreamVendor(vendor: string): void {
+ this.upstreamVendor = vendor;
+ }
+
/** Install the `--effort` override for this handler. undefined clears it. */
setEffortOverride(level: EffortLevel | undefined): void {
this.pinnedEffort = level;
@@ -984,7 +996,13 @@ export abstract class BaseAPIFormat implements APIFormat, ModelDialect {
* Override for non-OpenAI formats (e.g., Gemini parts-based format).
*/
convertMessages(claudeRequest: any, filterIdentityFn?: (s: string) => string): any[] {
- return convertMessagesToOpenAI(claudeRequest, this.modelId, filterIdentityFn);
+ return convertMessagesToOpenAI(
+ claudeRequest,
+ this.modelId,
+ filterIdentityFn,
+ false,
+ this.upstreamVendor
+ );
}
/**
diff --git a/packages/cli/src/adapters/codex-api-format.ts b/packages/cli/src/adapters/codex-api-format.ts
index c336c7ff..0036f55e 100644
--- a/packages/cli/src/adapters/codex-api-format.ts
+++ b/packages/cli/src/adapters/codex-api-format.ts
@@ -14,12 +14,7 @@
import { mapToolChoiceToResponsesAPI } from "../handlers/shared/format/openai-tools.js";
import { log } from "../logger.js";
import type { StreamFormat } from "../providers/transport/types.js";
-import {
- type AdapterResult,
- BaseAPIFormat,
- type EffortLevel,
- matchesModelFamily,
-} from "./base-api-format.js";
+import { type AdapterResult, BaseAPIFormat } from "./base-api-format.js";
import { reasoningForCall } from "./reasoning-cache.js";
/**
@@ -69,17 +64,9 @@ export class CodexAPIFormat extends BaseAPIFormat {
};
}
- shouldHandle(modelId: string): boolean {
- // Two valid Codex naming patterns:
- // - prefix: "codex", "codex-mini", "openai/codex-foo"
- // - suffix: "gpt-5-codex", "gpt-5.2-codex", "openai/gpt-5-codex"
- // The suffix form is what the openai-codex provider's nativeModelPatterns
- // matches (/codex$/i), so the format adapter must agree — otherwise the
- // request gets routed to the Codex /v1/responses endpoint but shaped as
- // a Chat Completions body, which the server 400s.
- if (matchesModelFamily(modelId, "codex")) return true;
- const lower = modelId.toLowerCase();
- return /(^|\/)[a-z0-9.+-]*-codex$/.test(lower);
+ /** Never selected by model name: the connection's `wire.api` chooses Responses. */
+ shouldHandle(_modelId: string): boolean {
+ return false;
}
getName(): string {
@@ -96,7 +83,9 @@ export class CodexAPIFormat extends BaseAPIFormat {
if (replayedReasoning > 0) {
log(`[CodexAPIFormat] replaying ${replayedReasoning} cached reasoning item(s)`);
}
- const normalizedModel = normalizeCodexModel(this.modelId);
+ // The ChatGPT Codex backend knows bare ids only; every other Responses host
+ // gets the connection's exact wire id.
+ const model = this.codexExtras ? normalizeCodexModel(this.modelId) : this.modelId;
// Strip IDs from message items (stateless mode doesn't support server-side state)
const strippedMessages = convertedMessages.map((item: any) => {
@@ -104,34 +93,20 @@ export class CodexAPIFormat extends BaseAPIFormat {
return rest;
});
- // BUG FIX: this used to hardcode reasoning.effort = "medium", ignoring
- // Claude Code's effort signal entirely. Now read it and clamp per the
- // Codex (Responses API) model gates; default stays "medium" when absent.
- const effort = this.resolveCodexEffort(claudeRequest);
-
+ // No output limit, reasoning effort or verbosity here: on a catalog
+ // connection those are the wire's (step 5w), and nothing else may choose
+ // them. The old name-based effort ladder and its "medium" default are gone.
const payload: any = {
- model: normalizedModel,
+ model,
input: strippedMessages,
stream: true,
...(this.codexExtras ? { store: false, include: ["reasoning.encrypted_content"] } : {}),
- reasoning: {
- effort,
- summary: "auto",
- },
- text: {
- verbosity: "medium",
- },
};
if (claudeRequest.system) {
payload.instructions = claudeRequest.system;
}
- if (claudeRequest.max_tokens) {
- // Codex API doesn't support max_tokens - use default
- // payload.max_tokens = Math.max(16, claudeRequest.max_tokens);
- }
-
if (tools.length > 0) {
payload.tools = tools.map((tool: any) => {
if (tool.type === "function" && tool.function) {
@@ -159,66 +134,6 @@ export class CodexAPIFormat extends BaseAPIFormat {
// ─── Private helpers ───────────────────────────────────────────────
- /**
- * Resolve Claude Code's effort signal to a Codex Responses-API
- * `reasoning.effort` value. Codex models accept the OpenAI set
- * `none | low | medium | high | xhigh` but NOT `minimal` (codex drops it)
- * and `max` doesn't exist (ceiling is xhigh). `xhigh` is documented only on
- * gpt-5.1-codex-max. `none` is valid on the gpt-5.1-codex family.
- *
- * Default is "medium" when Claude Code sends no effort signal (the historical
- * Codex default — preserved so behavior is unchanged for non-effort requests).
- */
- private resolveCodexEffort(claudeRequest: any): string {
- const level = this.resolveEffortLevel(claudeRequest);
- if (!level) return "medium"; // historical default
-
- const value = this.clampCodexEffort(level);
- log(`[CodexAPIFormat] reasoning.effort -> ${value} (from ${level}) for ${this.modelId}`);
- return value;
- }
-
- /** gpt-5.1-codex-max (and later codex-max), plus the gpt-5.6 family —
- * the models accepting xhigh on the Responses API. */
- private acceptsXhigh(): boolean {
- const m = this.modelId.toLowerCase();
- return /codex.*max/.test(m) || /gpt-5\.6/.test(m);
- }
-
- /** gpt-5.6 family — first OpenAI models with a native `max` effort
- * (catalog-confirmed: efforts=[max,xhigh,high,medium,low,none]). */
- private acceptsMax(): boolean {
- return /gpt-5\.6/.test(this.modelId.toLowerCase());
- }
-
- /** gpt-5.1+ codex family and the gpt-5.6 family — accept `none`. */
- private isCodex51Plus(): boolean {
- const m = this.modelId.toLowerCase();
- return /gpt-5\.[1-9].*codex/.test(m) || /gpt-5\.6/.test(m);
- }
-
- private clampCodexEffort(level: EffortLevel): string {
- switch (level) {
- case "none":
- // `none` valid on the gpt-5.1-codex family; older codex → low.
- return this.isCodex51Plus() ? "none" : "low";
- case "minimal":
- return "low"; // codex drops `minimal`
- case "low":
- case "medium":
- case "high":
- return level;
- case "xhigh":
- return this.acceptsXhigh() ? "xhigh" : "high";
- case "max":
- // gpt-5.6 takes native max; older codex has no max → xhigh/high.
- if (this.acceptsMax()) return "max";
- return this.acceptsXhigh() ? "xhigh" : "high";
- default:
- return "medium";
- }
- }
-
/**
* Convert Chat Completions format messages to Responses API format.
* System messages go to 'instructions' field (handled by buildPayload).
diff --git a/packages/cli/src/adapters/dialect-manager.ts b/packages/cli/src/adapters/dialect-manager.ts
index a54cf209..8e18003c 100644
--- a/packages/cli/src/adapters/dialect-manager.ts
+++ b/packages/cli/src/adapters/dialect-manager.ts
@@ -10,20 +10,20 @@
import type { StreamFormat } from "../providers/transport/types.js";
import { type BaseAPIFormat, DefaultAPIFormat } from "./base-api-format.js";
-import { CodexAPIFormat } from "./codex-api-format.js";
import { DeepSeekModelDialect } from "./deepseek-model-dialect.js";
import { GeminiAPIFormat } from "./gemini-api-format.js";
import { GLMModelDialect } from "./glm-model-dialect.js";
import { GrokModelDialect } from "./grok-model-dialect.js";
import { MiniMaxModelDialect } from "./minimax-model-dialect.js";
-import { OpenAIAPIFormat } from "./openai-api-format.js";
import { QwenModelDialect } from "./qwen-model-dialect.js";
import { XiaomiModelDialect } from "./xiaomi-model-dialect.js";
/**
- * Candidate dialects, in match order. ORDER IS LOAD-BEARING: Codex must be
- * tried before OpenAI, because a codex model id also satisfies OpenAI's test
- * and whichever runs first wins.
+ * Candidate dialects, in match order, for a handler WITHOUT a catalog
+ * connection only (a dynamic subscription, a custom or local endpoint). A
+ * catalog connection never gets a name-picked dialect: its `wire` decides
+ * (`ComposedHandler`). The OpenAI and Codex formats are not here at all: the
+ * API is chosen by `wire.api`, never by a model name.
*
* These are factories rather than instances because `shouldHandle` is an
* instance method, so asking "does this dialect want the model" requires
@@ -33,8 +33,6 @@ import { XiaomiModelDialect } from "./xiaomi-model-dialect.js";
const DIALECT_FACTORIES: ReadonlyArray<(modelId: string, wire?: StreamFormat) => BaseAPIFormat> = [
(m, w) => new GrokModelDialect(m, w),
(m, w) => new GeminiAPIFormat(m, w),
- (m, w) => new CodexAPIFormat(m, w),
- (m, w) => new OpenAIAPIFormat(m, w),
(m, w) => new QwenModelDialect(m, w),
(m, w) => new MiniMaxModelDialect(m, w),
(m, w) => new DeepSeekModelDialect(m, w),
diff --git a/packages/cli/src/adapters/effort-mapping.test.ts b/packages/cli/src/adapters/effort-mapping.test.ts
index 7a1531be..4c5e0d7f 100644
--- a/packages/cli/src/adapters/effort-mapping.test.ts
+++ b/packages/cli/src/adapters/effort-mapping.test.ts
@@ -11,59 +11,46 @@
* ai-docs/sessions/dev-research-reasoning-effort-20260629-010035-c1b698d0/report.md §3.
*/
-import { afterEach, beforeEach, describe, expect, test } from "bun:test";
-import { existsSync, readFileSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
-import { dirname } from "node:path";
-import {
- ALL_MODELS_CACHE_PATH,
- type DiskCacheV3,
- writeAllModelsCache,
-} from "../providers/all-models-cache.js";
+import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test";
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { type DiskCacheV3, writeAllModelsCache } from "../providers/all-models-cache.js";
import { type AdapterResult, BaseAPIFormat, type EffortLevel } from "./base-api-format.js";
-import { CodexAPIFormat } from "./codex-api-format.js";
import { DeepSeekModelDialect } from "./deepseek-model-dialect.js";
import { GeminiAPIFormat } from "./gemini-api-format.js";
import { GLMModelDialect } from "./glm-model-dialect.js";
import { GrokModelDialect } from "./grok-model-dialect.js";
import { MiniMaxModelDialect } from "./minimax-model-dialect.js";
-import { OpenAIAPIFormat } from "./openai-api-format.js";
+import { lookupModelReasoning, lookupModelReasoningStatus } from "./model-catalog.js";
import { QwenModelDialect } from "./qwen-model-dialect.js";
const SYNTHETIC_FUGU_MODEL_ID = "fugu-acme-ultra";
+const cacheDir = mkdtempSync(join(tmpdir(), "effort-mapping-"));
+const cachePath = join(cacheDir, "catalog.json");
+afterAll(() => rmSync(cacheDir, { recursive: true, force: true }));
function seedDefaultCatalog(entries: DiskCacheV3["entries"]): () => void {
- const cacheDir = dirname(ALL_MODELS_CACHE_PATH);
- const cacheDirExisted = existsSync(cacheDir);
- const previousContents = existsSync(ALL_MODELS_CACHE_PATH)
- ? readFileSync(ALL_MODELS_CACHE_PATH, "utf-8")
- : null;
-
writeAllModelsCache(
{
- catalogGenerationId: "test-generation",
- plans: [],
version: 3,
+ catalogGenerationId: "test-generation",
lastUpdated: new Date().toISOString(),
entries,
models: [],
+ plans: [],
},
- ALL_MODELS_CACHE_PATH
+ cachePath
);
-
- return () => {
- if (previousContents === null) {
- rmSync(ALL_MODELS_CACHE_PATH, { force: true });
- if (!cacheDirExisted) {
- try {
- rmdirSync(cacheDir);
- } catch {
- // Another test may have created something in the shared cache dir.
- }
- }
- return;
- }
- writeFileSync(ALL_MODELS_CACHE_PATH, previousContents, "utf-8");
- };
+ return () => rmSync(cachePath, { force: true });
+}
+class CatalogDeepSeek extends DeepSeekModelDialect {
+ protected override lookupReasoningCapability() {
+ return lookupModelReasoning(this.getModelId(), cachePath);
+ }
+ protected override lookupReasoningStatus() {
+ return lookupModelReasoningStatus(this.getModelId(), cachePath);
+ }
}
// ─── Part 1: shared resolveEffortLevel ────────────────────────────────────
@@ -124,142 +111,6 @@ describe("resolveEffortLevel (shared)", () => {
});
});
-// ─── Part 2A: OpenAI per-model gates ──────────────────────────────────────
-
-function openaiEffort(modelId: string, effort: string): string | undefined {
- const fmt = new OpenAIAPIFormat(modelId);
- const payload = (fmt as any).buildChatCompletionsPayload(
- { output_config: { effort }, max_tokens: 100 },
- [],
- []
- );
- return payload.reasoning_effort;
-}
-
-describe("OpenAI gates", () => {
- test("o1-mini STRIPS reasoning_effort entirely (no param exists)", () => {
- expect(openaiEffort("o1-mini", "high")).toBeUndefined();
- expect(openaiEffort("o1-mini", "low")).toBeUndefined();
- });
-
- test("o-series (o3-mini) caps at high — xhigh/max clamp to high", () => {
- expect(openaiEffort("o3-mini", "xhigh")).toBe("high");
- expect(openaiEffort("o3-mini", "max")).toBe("high");
- expect(openaiEffort("o3-mini", "high")).toBe("high");
- expect(openaiEffort("o3-mini", "medium")).toBe("medium");
- });
-
- test("o-series rejects none/minimal → low", () => {
- expect(openaiEffort("o3-mini", "none")).toBe("low");
- expect(openaiEffort("o3-mini", "minimal")).toBe("low");
- });
-
- test("original GPT-5 accepts minimal; none → minimal; max → high (no xhigh)", () => {
- expect(openaiEffort("gpt-5", "minimal")).toBe("minimal");
- expect(openaiEffort("gpt-5", "none")).toBe("minimal");
- expect(openaiEffort("gpt-5", "xhigh")).toBe("high");
- expect(openaiEffort("gpt-5", "max")).toBe("high");
- });
-
- test("gpt-5.5 (5.1+) unchanged — pinned by reasoning-effort.test.ts", () => {
- expect(openaiEffort("gpt-5.5", "minimal")).toBe("low");
- expect(openaiEffort("gpt-5.5", "none")).toBe("none");
- expect(openaiEffort("gpt-5.5", "xhigh")).toBe("xhigh");
- expect(openaiEffort("gpt-5.5", "max")).toBe("xhigh");
- });
-});
-
-// ─── Part 2A (Sakana/Fugu): clamp-up via the OpenAI path ──────────────────
-
-describe("Sakana Fugu (OpenAI-compatible path) clamps UP to high", () => {
- let cleanupCatalog: (() => void) | undefined;
-
- beforeEach(() => {
- cleanupCatalog = seedDefaultCatalog([
- {
- modelId: SYNTHETIC_FUGU_MODEL_ID,
- aliases: [],
-
- reasoning: {
- supported: true,
- control: "effort",
- efforts: ["max", "xhigh", "high"],
- defaultEffort: "high",
- },
- },
- ]);
- });
-
- afterEach(() => {
- cleanupCatalog?.();
- cleanupCatalog = undefined;
- });
-
- test.each([
- ["fugu", "none", "high"],
- ["fugu", "minimal", "high"],
- ["fugu", "low", "high"],
- ["fugu", "medium", "high"],
- ["fugu", "high", "high"],
- ["fugu", "xhigh", "xhigh"],
- ["fugu", "max", "xhigh"],
- ["fugu-ultra", "low", "high"],
- // The synthetic catalog entry advertises `max`, so the catalog-driven clamp
- // passes it through. Without the fixture (or without catalog lookup), the
- // Fugu name fallback would normalise `max` down to `xhigh` and this fails.
- [SYNTHETIC_FUGU_MODEL_ID, "max", "max"],
- ["sakana/fugu-ultra-20260615", "medium", "high"],
- ])("%s effort '%s' → reasoning_effort '%s'", (model, input, expected) => {
- expect(openaiEffort(model, input)).toBe(expected);
- });
-});
-
-// ─── Part 2B: Codex (Responses API) ───────────────────────────────────────
-
-function codexReasoning(modelId: string, req: any): any {
- const fmt = new CodexAPIFormat(modelId);
- return (fmt as any).buildPayload(req, [], []).reasoning;
-}
-
-describe("Codex reasoning.effort", () => {
- test("flows effort into reasoning.effort (not hardcoded medium)", () => {
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "high" } }).effort).toBe(
- "high"
- );
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "low" } }).effort).toBe("low");
- });
-
- test("default stays 'medium' when no effort signal", () => {
- expect(codexReasoning("gpt-5-codex", { max_tokens: 100 }).effort).toBe("medium");
- });
-
- test("codex drops minimal → low; no max (→high); xhigh→high off codex-max", () => {
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "minimal" } }).effort).toBe(
- "low"
- );
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "max" } }).effort).toBe("high");
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "xhigh" } }).effort).toBe(
- "high"
- );
- });
-
- test("codex-max accepts xhigh", () => {
- expect(codexReasoning("gpt-5.1-codex-max", { output_config: { effort: "xhigh" } }).effort).toBe(
- "xhigh"
- );
- expect(codexReasoning("gpt-5.1-codex-max", { output_config: { effort: "max" } }).effort).toBe(
- "xhigh"
- );
- });
-
- test("none → 'none' on gpt-5.1-codex family, 'low' on older codex", () => {
- expect(codexReasoning("gpt-5.1-codex", { output_config: { effort: "none" } }).effort).toBe(
- "none"
- );
- expect(codexReasoning("gpt-5-codex", { output_config: { effort: "none" } }).effort).toBe("low");
- });
-});
-
// ─── Part 2C: Gemini ──────────────────────────────────────────────────────
function geminiThinkingConfig(modelId: string, req: any): any {
@@ -366,35 +217,6 @@ describe("Grok reasoning_effort gates", () => {
);
});
- test("grok-4 / grok-4-0709 STRIP (not on allowlist, param 400s)", () => {
- expect(grokEffort("grok-4", { output_config: { effort: "high" } })).toBeUndefined();
- expect(grokEffort("grok-4-0709", { output_config: { effort: "high" } })).toBeUndefined();
- });
-
- test("non-reasoning + grok-2 STRIP", () => {
- expect(
- grokEffort("grok-4-fast-non-reasoning", { output_config: { effort: "high" } })
- ).toBeUndefined();
- expect(grokEffort("grok-2", { output_config: { effort: "high" } })).toBeUndefined();
- });
-
- test("allowlist: grok-build-0.1 / grok-code-fast-1 STRIP (live-verified reject the param)", () => {
- // These matched no old deny pattern → wrongly got reasoning_effort → 400.
- // The allowlist flip strips them (they're not a known-accepting family).
- expect(grokEffort("grok-build-0.1", { output_config: { effort: "minimal" } })).toBeUndefined();
- expect(grokEffort("grok-code-fast-1", { output_config: { effort: "low" } })).toBeUndefined();
- });
-
- test("allowlist: grok-4.20 reasoning models STRIP despite grok-4.x shape (live-verified 400)", () => {
- // The decisive case for allowlist-over-denylist: grok-4.20 IS a reasoning
- // model and matches dot-decimal grok-4.x, yet the live API rejects the
- // param — only grok-4.3 accepts it. Naming can't gate this.
- expect(grokEffort("grok-4.20", { output_config: { effort: "high" } })).toBeUndefined();
- expect(
- grokEffort("grok-4.20-0309-reasoning", { output_config: { effort: "high" } })
- ).toBeUndefined();
- });
-
test("an unknown/new grok model SENDS effort optimistically", () => {
// Silently losing a supported capability is invisible; an unsupported
// parameter produces a loud 400 that recoverFromRejection can repair once.
@@ -869,7 +691,7 @@ describe("GLM Anthropic wire reasoning stays separate", () => {
// ─── Part 2G: DeepSeek ────────────────────────────────────────────────────
function dsPrep(modelId: string, req: any): any {
- const fmt = new DeepSeekModelDialect(modelId);
+ const fmt = new CatalogDeepSeek(modelId);
return (fmt as any).prepareRequest({}, req);
}
diff --git a/packages/cli/src/adapters/effort-not-silently-dropped.test.ts b/packages/cli/src/adapters/effort-not-silently-dropped.test.ts
index d81702ca..72f78049 100644
--- a/packages/cli/src/adapters/effort-not-silently-dropped.test.ts
+++ b/packages/cli/src/adapters/effort-not-silently-dropped.test.ts
@@ -4,9 +4,10 @@
*/
import { beforeEach, expect, test } from "bun:test";
-import { readAllModelsCache } from "../providers/all-models-cache.js";
+import { readFileSync } from "node:fs";
+import type { DiskCacheV3 } from "../providers/all-models-cache.js";
+import { shapeRequestFromWire } from "../providers/wire-request.js";
import { DeepSeekModelDialect } from "./deepseek-model-dialect.js";
-import { resolveModelDialect } from "./dialect-manager.js";
import { resetReasoningEffortMemo } from "./grok-effort-support.js";
import { GrokModelDialect } from "./grok-model-dialect.js";
@@ -14,74 +15,40 @@ beforeEach(() => {
resetReasoningEffortMemo();
});
-const hostedCatalog = readAllModelsCache();
-const hostedEntries = hostedCatalog?.entries ?? [];
+const fixture: DiskCacheV3 = JSON.parse(
+ readFileSync(
+ new URL("../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json", import.meta.url),
+ "utf8"
+ )
+);
-interface EffortBearingRequest {
- reasoning_effort?: unknown;
- thinking?: unknown;
- enable_thinking?: unknown;
- thinking_budget?: unknown;
- effort?: unknown;
- reasoning?: { effort?: unknown };
- generationConfig?: {
- thinkingConfig?: {
- thinkingLevel?: unknown;
- thinkingBudget?: unknown;
- };
- };
-}
-
-function emitsNativeEffortSignal(result: EffortBearingRequest | null | undefined): boolean {
- return (
- result?.reasoning_effort !== undefined ||
- result?.thinking !== undefined ||
- result?.enable_thinking !== undefined ||
- result?.thinking_budget !== undefined ||
- result?.effort !== undefined ||
- result?.reasoning?.effort !== undefined ||
- result?.generationConfig?.thinkingConfig?.thinkingLevel !== undefined ||
- result?.generationConfig?.thinkingConfig?.thinkingBudget !== undefined
- );
-}
-
-if (hostedEntries.length === 0) {
- test.skip("hosted catalog effort guard — skipped because readAllModelsCache() returned no entries; warm the hosted model cache to run it", () => {});
-} else {
- test("every effort-controlled catalog model's dialect emits an effort signal on the native wire", () => {
- const failures: string[] = [];
- const effortControlled = hostedEntries.filter(
- (entry) => entry.reasoning?.supported === true && entry.reasoning.control === "effort"
- );
-
- for (const entry of effortControlled) {
- const dialect = resolveModelDialect(entry.modelId);
- const dialectName = dialect.getName();
-
- // Layer-1 format converters own effort for models with no Layer-2 dialect.
- if (dialectName === "DefaultAPIFormat") continue;
-
- // Gemini and Codex emit their native knobs while building the payload;
- // model dialects emit theirs while preparing it. Exercise both stages and
- // inspect the final native-wire request so neither can mask the other.
- const originalRequest = { messages: [], output_config: { effort: "low" } };
- const nativeRequest = dialect.buildPayload(originalRequest, [], []);
- const result = dialect.prepareRequest(nativeRequest, originalRequest);
-
- if (!emitsNativeEffortSignal(result)) {
- failures.push(
- `Model "${entry.modelId}" resolves to dialect "${dialectName}" and advertises efforts ${JSON.stringify(
- entry.reasoning?.efforts ?? []
- )}, but the dialect is silently dropping the user's effort setting on the default (native) wire.`
- );
- }
- }
-
- if (failures.length > 0) {
- throw new Error(`Catalog effort regression guard failed:\n${failures.join("\n")}`);
+test("every published effort-controlled connection emits its wire effort field", () => {
+ let checked = 0;
+ for (const entry of fixture.entries) {
+ for (const connection of entry.aggregators ?? []) {
+ const wire = connection.wire;
+ if (
+ wire?.status !== "known" ||
+ wire.reasoning.status !== "supported" ||
+ !("path" in wire.reasoning.effort)
+ )
+ continue;
+ const body: Record<string, unknown> = {};
+ const shaped = shapeRequestFromWire(body, wire, { effort: "high", hasTools: false });
+ const label = `${entry.modelId} ${connection.route?.routeId}/${connection.route?.routeProfileId}`;
+ expect(shaped.sentEffort, label).toBeDefined();
+ const path = wire.reasoning.effort.path
+ .split("/")
+ .slice(1)
+ .map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~"));
+ let emitted: unknown = body;
+ for (const part of path) emitted = (emitted as Record<string, unknown> | undefined)?.[part];
+ expect(emitted, label).toBeDefined();
+ checked++;
}
- });
-}
+ }
+ expect(checked).toBeGreaterThan(0);
+});
test("future Grok and DeepSeek model-name fallbacks are rules, not version pins", () => {
const highEffort = { output_config: { effort: "high" } };
diff --git a/packages/cli/src/adapters/grok-effort-support.test.ts b/packages/cli/src/adapters/grok-effort-support.test.ts
index ba7003a4..a98522aa 100644
--- a/packages/cli/src/adapters/grok-effort-support.test.ts
+++ b/packages/cli/src/adapters/grok-effort-support.test.ts
@@ -5,6 +5,9 @@
*/
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
import {
acceptsReasoningEffort,
acceptsReasoningEffortValue,
@@ -43,12 +46,17 @@ describe("live xAI reasoning_effort support", () => {
test("normalises the x-ai/ vendor prefix", () => {
expect(grokEffort("x-ai/grok-4.6", "high")).toBe("high");
+ rememberReasoningEffortRejected("grok-build-0.1");
expect(grokEffort("x-ai/grok-build-0.1", "high")).toBeUndefined();
});
test.each(["grok-4.20-0309-reasoning", "grok-4.20-0309-non-reasoning", "grok-build-0.1"])(
"%s strips reasoning_effort after its live parameter rejection",
(modelId) => {
+ // The cloud models catalog may already reject effort for these ids.
+ // Only the post-rejection verdict is independent of the local cache.
+ rememberReasoningEffortRejected(modelId);
+ expect(learnedReasoningEffortRejects()).toContain(modelId);
expect(grokEffort(modelId, "high")).toBeUndefined();
}
);
@@ -154,3 +162,41 @@ describe("GrokModelDialect.recoverFromRejection", () => {
}
);
});
+
+test("cold grok-2-unknown accepts effort until a learned 400", () => {
+ // The exported support API has no cache-path seam. A fresh child import and
+ // empty home prove this is cold, independently of the caller's catalog.
+ const dir = mkdtempSync(join(tmpdir(), "grok-cold-"));
+ try {
+ const script = `
+ const { acceptsReasoningEffort } = await import(${JSON.stringify(new URL("./grok-effort-support.ts", import.meta.url).pathname)});
+ const { GrokModelDialect } = await import(${JSON.stringify(new URL("./grok-model-dialect.ts", import.meta.url).pathname)});
+ const id = "grok-2-unknown";
+ const before = acceptsReasoningEffort(id);
+ const recovery = new GrokModelDialect(id).recoverFromRejection(
+ {reasoning_effort: "high"},
+ "Model grok-2-unknown does not support parameter reasoningEffort."
+ );
+ console.log(JSON.stringify({before, after: acceptsReasoningEffort(id), payload: recovery?.payload}));
+ `;
+ const child = Bun.spawnSync([process.execPath, "--eval", script], {
+ env: {
+ PATH: process.env.PATH,
+ HOME: dir,
+ CLAUDISH_DISABLE_KEYCHAIN: "1",
+ CLAUDISH_DISABLE_OP: "1",
+ CLAUDISH_DISABLE_CATALOG_WARM: "1",
+ },
+ stdout: "pipe",
+ stderr: "pipe",
+ });
+ expect(child.exitCode, child.stderr.toString()).toBe(0);
+ expect(JSON.parse(child.stdout.toString())).toEqual({
+ before: true,
+ after: false,
+ payload: {},
+ });
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
diff --git a/packages/cli/src/adapters/grok-effort-support.ts b/packages/cli/src/adapters/grok-effort-support.ts
index e7aaf5d3..6a1029e6 100644
Binary files a/packages/cli/src/adapters/grok-effort-support.ts and b/packages/cli/src/adapters/grok-effort-support.ts differ
diff --git a/packages/cli/src/adapters/model-catalog.ts b/packages/cli/src/adapters/model-catalog.ts
index f23cbafd..8c905494 100644
--- a/packages/cli/src/adapters/model-catalog.ts
+++ b/packages/cli/src/adapters/model-catalog.ts
@@ -13,7 +13,6 @@
import type { ReasoningModeCapabilities } from "../model-loader.js";
import {
type CachedSubscriptionPlan,
- type ModelEndpoint,
type ReasoningCapability,
type RouteVariant,
type SlimModelEntry,
@@ -140,22 +139,6 @@ export function lookupModelMaxOutputTokens(
return typeof value === "number" && value > 0 ? value : undefined;
}
-/**
- * The output-token parameter name this model's API expects.
- *
- * Returns `max_tokens` / `max_completion_tokens` / `max_output_tokens`, or
- * undefined for a cold cache or a model the catalog has no opinion on — in
- * which case the caller keeps whatever it did before.
- *
- * Callers must PREFER this over any name-based guess. Measured against the live
- * catalog, guessing from the name sends the wrong parameter to the whole
- * gpt-5.6-* family (they take `max_output_tokens`, the guess says
- * `max_completion_tokens`).
- */
-export function lookupModelTokenParam(modelId: string, cachePath?: string): string | undefined {
- return findCacheEntry(modelId, cachePath)?.tokenParam;
-}
-
/**
* Preset-variant metadata — which family this model belongs to, and whether it
* is that family's default on its provider.
@@ -276,18 +259,6 @@ export function lookupModelCapabilities(
return { supportsTools: entry.supportsTools, supportsThinking: entry.supportsThinking };
}
-/**
- * The wire API this model is reachable on for a transport family
- * (`openai` / `anthropic` / `gemini`).
- */
-export function lookupModelEndpoint(
- modelId: string,
- transport: string,
- cachePath?: string
-): ModelEndpoint | undefined {
- return findCacheEntry(modelId, cachePath)?.endpoints?.[transport];
-}
-
/**
* Provider-aware context window lookup.
*
diff --git a/packages/cli/src/adapters/openai-api-format.ts b/packages/cli/src/adapters/openai-api-format.ts
index 6a377089..21cdb9f1 100644
--- a/packages/cli/src/adapters/openai-api-format.ts
+++ b/packages/cli/src/adapters/openai-api-format.ts
@@ -1,21 +1,18 @@
/**
- * OpenAIAPIFormat — Layer 1 wire format for OpenAI Chat Completions API.
+ * OpenAIAPIFormat — Layer 1 wire format for the OpenAI Chat Completions API.
*
- * Handles:
- * - Context window detection for OpenAI models (gpt-*, o1, o3, codex)
- * - Mapping 'thinking.budget_tokens' to 'reasoning_effort' for o1/o3 models
- * - max_completion_tokens vs max_tokens for newer models
- * - Codex Responses API message conversion and payload building
- * - Tool choice mapping
- *
- * Also serves as Layer 2 ModelDialect for OpenAI-native models (o1/o3 reasoning params).
+ * Converts the Claude request into a Chat Completions body: messages, tools,
+ * tool choice, sampling parameters. It decides NOTHING about the output-limit
+ * field or reasoning: on a catalog connection both come from the connection's
+ * `wire` (`ComposedHandler` step 5w, `providers/wire-request.ts`), which
+ * overwrites whatever is written here. Without a wire (a custom endpoint),
+ * the documented default applies: `max_tokens`, and no reasoning field —
+ * `--model-params` adds one where the user knows the endpoint takes it.
*/
import { mapToolChoiceToOpenAI } from "../handlers/shared/format/openai-tools.js";
-import { log } from "../logger.js";
import type { StreamFormat } from "../providers/transport/types.js";
-import { type AdapterResult, BaseAPIFormat, type EffortLevel } from "./base-api-format.js";
-import { lookupModelReasoning, lookupModelTokenParam } from "./model-catalog.js";
+import { type AdapterResult, BaseAPIFormat } from "./base-api-format.js";
export class OpenAIAPIFormat extends BaseAPIFormat {
processTextContent(textContent: string, _accumulatedText: string): AdapterResult {
@@ -40,286 +37,34 @@ export class OpenAIAPIFormat extends BaseAPIFormat {
return 128;
}
- // Tool-name encoding used to live here, and here ONLY, which is why no other
- // OpenAI-shaped adapter did it. It is now in `prepareRequest`'s template, so
- // this hook has nothing left to do.
-
/**
- * OpenAI's own reasoning knob. Not called on the Anthropic wire.
+ * Chat Completions has no `thinking` block; a leftover one is removed. The
+ * reasoning field itself is the wire's to write.
*/
- protected override applyNativeReasoning(request: any, originalRequest: any): any {
- // Map Claude Code's effort (output_config.effort, or legacy
- // thinking.budget_tokens) → OpenAI reasoning_effort for reasoning-capable
- // models. Only set it if buildPayload hasn't already (it builds the payload
- // first; this covers paths that call prepareRequest on a payload built
- // elsewhere). Always strip a leftover `thinking` block — OpenAI rejects it.
- if (this.supportsReasoningEffort() && request.reasoning_effort === undefined) {
- const effort = this.resolveReasoningEffort(originalRequest);
- if (effort) {
- request.reasoning_effort = effort;
- log(`[OpenAIAPIFormat] reasoning_effort -> ${effort} for ${this.modelId}`);
- }
- }
+ protected override applyNativeReasoning(request: any, _originalRequest: any): any {
if (request.thinking) delete request.thinking;
-
return request;
}
- shouldHandle(modelId: string): boolean {
- return modelId.startsWith("oai/") || modelId.includes("o1") || modelId.includes("o3");
+ /** Never selected by model name: the connection's `wire.api` chooses this format. */
+ shouldHandle(_modelId: string): boolean {
+ return false;
}
getName(): string {
return "OpenAIAPIFormat";
}
- // ─── ComposedHandler integration ───────────────────────────────────
-
override buildPayload(claudeRequest: any, messages: any[], tools: any[]): any {
- return this.buildChatCompletionsPayload(claudeRequest, messages, tools);
- }
-
- // ─── Private helpers ───────────────────────────────────────────────
-
- /**
- * Whether this model accepts OpenAI's `reasoning_effort` parameter. Covers the
- * o-series (o1/o3/o4) AND the gpt-5 family — gpt-5/gpt-5.x take reasoning_effort
- * too, which the older o1/o3-only gate missed (so effort was silently dropped
- * for gpt-5.5). Sakana Fugu (routed through this OpenAI-compatible path) also
- * takes a nested-but-here-top-level reasoning_effort.
- *
- * STRIP exceptions (the param 400s or doesn't exist):
- * - `o1-mini`: the only o-series model with NO reasoning_effort param at all.
- */
- private supportsReasoningEffort(): boolean {
- // CATALOG FIRST. The name rule below is a cold-cache fallback only.
- //
- // Measured against the live catalog, the name rule is wrong in both
- // directions: 60 models take reasoning_effort but do not match it (every
- // fugu-*, deepseek-v4-*, gemini-3-flash-agent, claude-*-fast), so effort was
- // silently dropped; and 14 models match it but do NOT take the param
- // (gpt-5-image, gpt-5.2-chat, gpt-5.3-chat, …), where sending it can 400.
- // `isSakanaFugu()` below is the fossil of hand-patching one of those 60.
- const reasoning = lookupModelReasoning(this.modelId);
- if (reasoning) return reasoning.supported === true && reasoning.control === "effort";
-
- const model = this.modelId.toLowerCase();
- // o1-mini is the lone o-series model without the param → strip.
- if (model.includes("o1-mini")) return false;
- return (
- model.includes("o1") ||
- model.includes("o3") ||
- model.includes("o4") ||
- model.includes("gpt-5") ||
- this.isSakanaFugu()
- );
- }
-
- /** Sakana Fugu (fugu / fugu-ultra / sakana/*) — routed through this OpenAI path. */
- private isSakanaFugu(): boolean {
- const model = this.modelId.toLowerCase();
- return model.startsWith("fugu") || model.startsWith("sakana/") || model.includes("/fugu");
- }
-
- /** gpt-5.1 and later (5.1/5.2/5.5, and their -codex variants). */
- private isGpt51Plus(): boolean {
- const model = this.modelId.toLowerCase();
- return /gpt-5\.[1-9]/.test(model);
- }
-
- /** o-series reasoning models (o1/o3/o4) — accept only low|medium|high. */
- private isOSeries(): boolean {
- const model = this.modelId.toLowerCase();
- return model.includes("o1") || model.includes("o3") || model.includes("o4");
- }
-
- /** Original GPT-5 (gpt-5, gpt-5-mini/nano/pro/codex) — NOT gpt-5.1+. */
- private isOriginalGpt5(): boolean {
- const model = this.modelId.toLowerCase();
- return model.includes("gpt-5") && !this.isGpt51Plus();
- }
-
- /**
- * Whether this model accepts `xhigh`. The original GPT-5 family and the
- * o-series cap at `high` — sending `xhigh` 400s, so those clamp down. The
- * gpt-5.1+ family DOES accept `xhigh` (verified against the live API for
- * gpt-5.5 — see reasoning-effort.test.ts). gpt-5.1-codex-max is the documented
- * minimum, but the pinned test asserts the broader gpt-5.1+ acceptance.
- */
- private acceptsXhigh(): boolean {
- return this.isGpt51Plus() || this.isSakanaFugu();
- }
-
- /**
- * Map Claude Code's effort signal to a valid OpenAI `reasoning_effort` value.
- *
- * Modern Claude Code (Opus 4.7/4.8) sends `output_config.effort` as a string
- * level (none/minimal/low/medium/high/xhigh/max). Older clients sent
- * `thinking.budget_tokens` (a number) — kept as a fallback.
- *
- * Normalization to a canonical level is delegated to the shared
- * resolveEffortLevel(); this method then clamps that level to the value set
- * the SPECIFIC model accepts (OpenAI's gates differ sharply per family).
- *
- * OpenAI's accepted set is `none | minimal | low | medium | high | xhigh`
- * (`max` is rejected — `xhigh` is the ceiling; `minimal` is rejected on
- * gpt-5.1+). Sakana Fugu accepts ONLY `high | xhigh` (everything below 400s),
- * so its values clamp UP. Returns undefined when there's no effort signal.
- */
- private resolveReasoningEffort(claudeRequest: any): string | undefined {
- // Legacy budget bucketing is pinned by reasoning-effort.test.ts (gpt-5.x:
- // <16000→low, >=32000→high, else medium) — keep it here rather than via the
- // shared resolver, whose buckets differ. The string-level path delegates to
- // the shared normalizer.
- const rawLevel = claudeRequest?.output_config?.effort;
- let level: EffortLevel | undefined;
- if (typeof rawLevel === "string") {
- level = this.resolveEffortLevel(claudeRequest);
- if (!level) return undefined; // unknown string → let OpenAI default
- } else {
- const budget = claudeRequest?.thinking?.budget_tokens;
- if (typeof budget !== "number") return undefined;
- level = budget < 16000 ? "low" : budget >= 32000 ? "high" : "medium";
- }
-
- // Sakana Fugu: ONLY high|xhigh valid; clamp everything below UP to high.
- // Applied only on a cold cache — when the catalog is available it already
- // says `efforts: ["xhigh","high"]`, and clampToVocabulary's upward walk
- // produces the same answer generically (and gets fugu-ultra's `max` right,
- // which this hardcoded pair does not).
- if (this.isSakanaFugu() && !lookupModelReasoning(this.modelId)?.efforts?.length) {
- const value = level === "xhigh" || level === "max" ? "xhigh" : "high";
- log(`[OpenAIAPIFormat] Sakana Fugu clamp ${level} -> ${value} for ${this.modelId}`);
- return value;
- }
-
- return this.clampOpenAIEffort(level);
- }
-
- /**
- * Canonical strength ordering, strongest first. Used to walk to the nearest
- * level a model actually advertises. Ordering only — never a per-model list.
- */
- private static readonly EFFORT_LADDER = [
- "max",
- "xhigh",
- "high",
- "medium",
- "low",
- "minimal",
- "none",
- ] as const;
-
- /**
- * Clamp a requested level to a model's OWN advertised vocabulary.
- *
- * Walks DOWN the ladder from the requested level first (a weaker level is the
- * safe substitution), and only walks UP if the model advertises nothing
- * weaker. That upward walk is what makes Sakana Fugu work without a special
- * case: its vocabulary is `["xhigh","high"]`, so a `low` request finds nothing
- * below and clamps up to `high` — exactly what the hand-written rule did.
- */
- private clampToVocabulary(level: EffortLevel, efforts: string[]): string {
- const allowed = new Set(efforts.map((e) => e.toLowerCase()));
- if (allowed.has(level)) return level;
-
- const ladder = OpenAIAPIFormat.EFFORT_LADDER;
- const idx = ladder.indexOf(level as (typeof ladder)[number]);
- if (idx === -1) return efforts[0];
-
- // `none` is NOT merely the weakest level — it turns reasoning off. Falling
- // into it as a substitution silently changes what the model does, so it is
- // only ever returned on an exact match. A model that lacks the requested
- // weak level (e.g. `minimal` on gpt-5.5) gets the next level UP instead.
- for (let i = idx + 1; i < ladder.length; i++) {
- if (ladder[i] !== "none" && allowed.has(ladder[i])) return ladder[i];
- }
- for (let i = idx - 1; i >= 0; i--) {
- if (allowed.has(ladder[i])) return ladder[i];
- }
- return efforts[0];
- }
-
- /** Clamp a canonical level to the value set the current OpenAI model accepts. */
- private clampOpenAIEffort(level: EffortLevel): string {
- // CATALOG FIRST — the model's own advertised vocabulary. The name ladder
- // below is a cold-cache fallback, and it is measurably wrong in places: it
- // grants `xhigh` to every gpt-5.1+ id, but the catalog says gpt-5.1 accepts
- // only ["high","medium","low","none"].
- const efforts = lookupModelReasoning(this.modelId)?.efforts;
- if (efforts?.length) {
- const value = this.clampToVocabulary(level, efforts);
- if (value !== level) {
- log(`[OpenAIAPIFormat] effort ${level} -> ${value} (catalog) for ${this.modelId}`);
- }
- return value;
- }
- return this.clampOpenAIEffortByName(level);
- }
-
- /** Cold-cache fallback: the pre-catalog name ladder, unchanged. */
- private clampOpenAIEffortByName(level: EffortLevel): string {
- // `max` never exists on OpenAI — xhigh is the ceiling.
- // `minimal` is rejected on gpt-5.1+ and on the o-series.
- // `none` is valid only on the gpt-5.1+ family.
- // `xhigh` is accepted only on gpt-5.1-codex-max.
- switch (level) {
- case "none":
- // gpt-5.1+ accepts none; o-series → low; original GPT-5 → minimal.
- if (this.isGpt51Plus()) return "none";
- if (this.isOSeries()) return "low";
- if (this.isOriginalGpt5()) return "minimal";
- return "none";
- case "minimal":
- // Rejected on gpt-5.1+ and o-series → low. Valid on original GPT-5.
- if (this.isGpt51Plus() || this.isOSeries()) return "low";
- return "minimal";
- case "low":
- case "medium":
- case "high":
- return level;
- case "xhigh":
- return this.acceptsXhigh() ? "xhigh" : "high";
- case "max":
- // No `max` on OpenAI; ceiling is xhigh (only on codex-max), else high.
- return this.acceptsXhigh() ? "xhigh" : "high";
- default:
- return "medium";
- }
- }
-
- /**
- * Which output-token parameter this model expects.
- *
- * CATALOG FIRST (`tokenParam`), because the correct answer is not derivable
- * from the name: the gpt-5.6-* family takes `max_output_tokens` while the
- * name rule below says `max_completion_tokens`. The rule also has no way to
- * be right about a model released after it was written.
- */
- private tokenParamName(): string {
- const fromCatalog = lookupModelTokenParam(this.modelId);
- if (fromCatalog) return fromCatalog;
-
- const model = this.modelId.toLowerCase();
- const usesMaxCompletion =
- model.includes("gpt-5") ||
- model.includes("o1") ||
- model.includes("o3") ||
- model.includes("o4");
- return usesMaxCompletion ? "max_completion_tokens" : "max_tokens";
- }
-
- private buildChatCompletionsPayload(claudeRequest: any, messages: any[], tools: any[]): any {
const payload: any = {
model: this.modelId,
messages,
temperature: claudeRequest.temperature ?? 1,
stream: true,
stream_options: { include_usage: true },
+ max_tokens: claudeRequest.max_tokens,
};
- payload[this.tokenParamName()] = claudeRequest.max_tokens;
-
if (tools.length > 0) {
payload.tools = tools;
}
@@ -329,17 +74,6 @@ export class OpenAIAPIFormat extends BaseAPIFormat {
payload.tool_choice = toolChoice;
}
- // Map Claude Code's effort (output_config.effort, or legacy
- // thinking.budget_tokens) → OpenAI reasoning_effort for reasoning-capable
- // models (o-series + gpt-5 family).
- if (this.supportsReasoningEffort()) {
- const effort = this.resolveReasoningEffort(claudeRequest);
- if (effort) {
- payload.reasoning_effort = effort;
- log(`[OpenAIAPIFormat] reasoning_effort -> ${effort} for ${this.modelId}`);
- }
- }
-
this.applyOpenAISamplingParams(payload, claudeRequest);
return payload;
diff --git a/packages/cli/src/adapters/openrouter-api-format.test.ts b/packages/cli/src/adapters/openrouter-api-format.test.ts
new file mode 100644
index 00000000..16c40f82
--- /dev/null
+++ b/packages/cli/src/adapters/openrouter-api-format.test.ts
@@ -0,0 +1,43 @@
+import { afterEach, beforeEach, expect, test } from "bun:test";
+import { _resetCatalogClient, _setCatalogEntriesForTest } from "../providers/catalog-client.js";
+import { OpenRouterAPIFormat } from "./openrouter-api-format.js";
+
+beforeEach(() => _setCatalogEntriesForTest(null));
+afterEach(() => _resetCatalogClient());
+const request = { messages: [{ role: "user", content: "hello" }], max_tokens: 100 };
+
+test("x-ai vendor adds the Grok tool-format prompt to an opaque id", () => {
+ const messages = new OpenRouterAPIFormat("opaque-model", { vendor: "x-ai" }).convertMessages(
+ request
+ );
+ expect(messages[0].role).toBe("system");
+ expect(messages[0].content).toContain("MUST use the OpenAI tool_calls format with JSON");
+});
+test("openai vendor suppresses Grok and Gemini name-picked prompts", () => {
+ const format = new OpenRouterAPIFormat("grok-gemini-reasoning", { vendor: "openai" });
+ expect(format.convertMessages(request)).toEqual(request.messages);
+ expect(format.getName()).toBe("OpenRouterAPIFormat(DefaultAPIFormat)");
+});
+test.each(["x-ai", "openai", "google"])("vendor %s does not emit include_reasoning", (vendor) => {
+ const format = new OpenRouterAPIFormat("o3-reasoning", { vendor });
+ expect(format.buildPayload(request, [], [])).not.toHaveProperty("include_reasoning");
+});
+test("google vendor selects Gemini behavior for an opaque id", () => {
+ const format = new OpenRouterAPIFormat("opaque-model", { vendor: "google" });
+ expect(format.getName()).toBe("OpenRouterAPIFormat(GeminiAPIFormat)");
+ expect(format.convertMessages(request)[0].content).toContain(
+ "Keep ALL internal reasoning INTERNAL"
+ );
+ expect(
+ format.extractThoughtSignaturesFromReasoningDetails([
+ { type: "reasoning.encrypted", id: "call_1", data: "signed-thought" },
+ ])
+ ).toEqual(new Map([["call_1", "signed-thought"]]));
+});
+test("without a vendor the existing prompt and include_reasoning rules remain", () => {
+ const format = new OpenRouterAPIFormat("grok-reasoning");
+ expect(format.convertMessages(request)[0].content).toContain(
+ "MUST use the OpenAI tool_calls format with JSON"
+ );
+ expect(format.buildPayload(request, [], []).include_reasoning).toBe(true);
+});
diff --git a/packages/cli/src/adapters/openrouter-api-format.ts b/packages/cli/src/adapters/openrouter-api-format.ts
index 1f3ce808..088a2175 100644
--- a/packages/cli/src/adapters/openrouter-api-format.ts
+++ b/packages/cli/src/adapters/openrouter-api-format.ts
@@ -15,21 +15,40 @@ import {
mapToolChoiceToOpenAI,
} from "../handlers/shared/format/openai-tools.js";
import type { StreamFormat } from "../providers/transport/types.js";
-import { type AdapterResult, BaseAPIFormat } from "./base-api-format.js";
+import { type AdapterResult, BaseAPIFormat, DefaultAPIFormat } from "./base-api-format.js";
import { resolveModelDialect } from "./dialect-manager.js";
+import { GeminiAPIFormat } from "./gemini-api-format.js";
export class OpenRouterAPIFormat extends BaseAPIFormat {
private innerAdapter: BaseAPIFormat;
-
- constructor(modelId: string) {
+ /**
+ * The model's vendor from its catalog connection, when there is one. With
+ * it, nothing here is chosen by model name: the upstream family's fixes key
+ * on this field, and reasoning is the connection wire's (step 5w). Without
+ * it (no catalog connection), the name-picked dialect still applies.
+ */
+ private readonly vendor?: string;
+
+ constructor(modelId: string, options: { vendor?: string } = {}) {
super(modelId);
+ this.vendor = options.vendor;
+ if (options.vendor !== undefined) this.setUpstreamVendor(options.vendor);
+ this.innerAdapter =
+ options.vendor === undefined
+ ? resolveModelDialect(modelId)
+ : options.vendor === "google"
+ ? new GeminiAPIFormat(modelId)
+ : new DefaultAPIFormat(modelId);
+ }
- // Get model-specific dialect (GrokModelDialect, GeminiAPIFormat, etc.)
- this.innerAdapter = resolveModelDialect(modelId);
+ private isUpstream(vendor: "google", nameHints: string[]): boolean {
+ if (this.vendor !== undefined) return this.vendor === vendor;
+ return nameHints.some((hint) => this.modelId.includes(hint));
}
- /** Synchronous reasoning support check via model ID patterns */
+ /** Without a connection only: the old name check, kept for that path. */
private modelSupportsReasoning(): boolean {
+ if (this.vendor !== undefined) return false;
const id = this.modelId.toLowerCase();
return (
id.includes("o1") ||
@@ -65,14 +84,10 @@ export class OpenRouterAPIFormat extends BaseAPIFormat {
// Use default OpenAI conversion
const messages = super.convertMessages(claudeRequest, filterIdentityFn);
- // Add model-specific system prompt tweaks
- if (this.modelId.includes("grok") || this.modelId.includes("x-ai")) {
- const msg =
- "IMPORTANT: When calling tools, you MUST use the OpenAI tool_calls format with JSON. NEVER use XML format like <xai:function_call>.";
- this.appendToSystemPrompt(messages, msg);
- }
+ // The Grok tool-format instruction is added by the shared converter above,
+ // keyed on the connection's vendor (or the name, without a connection).
- if (this.modelId.includes("gemini") || this.modelId.includes("google/")) {
+ if (this.isUpstream("google", ["gemini", "google/"])) {
const geminiMsg = `CRITICAL INSTRUCTION FOR OUTPUT FORMAT:
1. Keep ALL internal reasoning INTERNAL. Never output your thought process as visible text.
2. Do NOT start responses with phrases like "Wait, I'm...", "Let me think...", "Okay, so...", "First, I need to..."
diff --git a/packages/cli/src/adapters/reasoning-effort.test.ts b/packages/cli/src/adapters/reasoning-effort.test.ts
index 0bea4347..727eaeab 100644
--- a/packages/cli/src/adapters/reasoning-effort.test.ts
+++ b/packages/cli/src/adapters/reasoning-effort.test.ts
@@ -1,71 +1,94 @@
-/**
- * Regression: Claude Code effort → OpenAI reasoning_effort mapping.
- *
- * Claude Code (Opus 4.7/4.8) conveys effort via `output_config.effort` (a string
- * level: none/low/medium/high/xhigh/max). Previously claudish only mapped the
- * legacy `thinking.budget_tokens`, gated to o1/o3 models, so for gpt-5.5 the
- * effort was silently DROPPED (no reasoning_effort reached OpenAI) — and the
- * legacy mapping could emit `minimal`, which gpt-5.x REJECTS.
- *
- * Valid OpenAI reasoning_effort values for gpt-5.x (verified against the live
- * API): none | low | medium | high | xhigh. (minimal and max are rejected.)
- */
-
-import { describe, expect, test } from "bun:test";
+import { expect, test } from "bun:test";
+import { resolveConnection } from "../providers/connection-resolver.js";
+import { shapeRequestFromWire, wireChoicesFromClaudeRequest } from "../providers/wire-request.js";
+import { CodexAPIFormat } from "./codex-api-format.js";
+import { resolveModelDialect } from "./dialect-manager.js";
import { OpenAIAPIFormat } from "./openai-api-format.js";
-function reasoningEffortFor(modelId: string, effort: string): string | undefined {
- const fmt = new OpenAIAPIFormat(modelId);
- const req: any = { output_config: { effort }, max_tokens: 100, temperature: 1 };
- // buildChatCompletionsPayload is the ComposedHandler path that sets the field.
- const payload = (fmt as any).buildChatCompletionsPayload(req, [], []);
- return payload.reasoning_effort;
-}
-
-describe("output_config.effort → reasoning_effort (gpt-5.5)", () => {
- test.each([
- ["low", "low"],
- ["medium", "medium"],
- ["high", "high"],
- ["xhigh", "xhigh"], // gpt-5.5 supports xhigh — must pass through, not clamp to high
- ["none", "none"],
- ["minimal", "low"], // gpt-5.5 REJECTS "minimal" → map to "low"
- ["max", "xhigh"], // gpt-5.5 REJECTS "max" → xhigh is the ceiling
- ])("effort '%s' → reasoning_effort '%s'", (input, expected) => {
- expect(reasoningEffortFor("gpt-5.5-2026-04-23", input)).toBe(expected);
- });
+const cachePath = new URL(
+ "../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json",
+ import.meta.url
+).pathname;
- test("the bare rolling gpt-5.5 alias maps effort too", () => {
- expect(reasoningEffortFor("gpt-5.5", "xhigh")).toBe("xhigh");
- });
+test.each(["gpt-5.5", "o3-mini", "o1-mini", "gpt-4-turbo", "fugu-ultra", "gpt-5-codex"])(
+ "OpenAI format uses max_tokens without reasoning or name selection for %s",
+ (id) => {
+ const format = new OpenAIAPIFormat(id);
+ const request = {
+ max_tokens: 100,
+ thinking: { budget_tokens: 40000 },
+ output_config: { effort: "high" },
+ };
+ const payload = format.buildPayload(request, [], []);
+ expect(payload.max_tokens).toBe(100);
+ for (const key of [
+ "reasoning_effort",
+ "reasoning",
+ "max_completion_tokens",
+ "max_output_tokens",
+ ])
+ expect(payload).not.toHaveProperty(key);
+ expect(format.shouldHandle(id)).toBe(false);
+ const prepared = format.prepareRequest({ thinking: request.thinking, keep: "yes" }, request);
+ expect(prepared).not.toHaveProperty("thinking");
+ expect(prepared.keep).toBe("yes");
+ expect(prepared).not.toHaveProperty("reasoning_effort");
+ }
+);
- test("o-series models still map effort", () => {
- expect(reasoningEffortFor("o3-mini", "high")).toBe("high");
- });
+test.each(["gpt-5.5", "o3-mini", "gpt-5-codex", "gpt-5.1-codex-max"])(
+ "%s does not select an OpenAI or Codex dialect",
+ (id) => {
+ expect(resolveModelDialect(id).getName()).toBe("DefaultAPIFormat");
+ expect(new CodexAPIFormat(id).shouldHandle(id)).toBe(false);
+ }
+);
- test("legacy thinking.budget_tokens still maps (no minimal — gpt-5.x rejects it)", () => {
- const fmt = new OpenAIAPIFormat("gpt-5.5");
- const low = (fmt as any).buildChatCompletionsPayload(
- { thinking: { budget_tokens: 2000 }, max_tokens: 100 },
- [],
- []
- );
- expect(low.reasoning_effort).toBe("low"); // never "minimal"
- const high = (fmt as any).buildChatCompletionsPayload(
- { thinking: { budget_tokens: 40000 }, max_tokens: 100 },
+test.each([undefined, "low", "medium", "high", "xhigh", "max"])(
+ "Codex format does not invent reasoning or verbosity for effort %s",
+ (effort) => {
+ const payload = new CodexAPIFormat("gpt-5.1-codex-max").buildPayload(
+ { max_tokens: 100, output_config: { effort } },
[],
[]
);
- expect(high.reasoning_effort).toBe("high");
- });
-
- test("non-reasoning model (gpt-4-turbo) does NOT get reasoning_effort", () => {
- expect(reasoningEffortFor("gpt-4-turbo", "high")).toBeUndefined();
- });
+ expect(payload).not.toHaveProperty("reasoning");
+ expect(payload).not.toHaveProperty("text");
+ expect(payload).not.toHaveProperty("reasoning_effort");
+ }
+);
+test("Codex extras alone enable model normalization, store and include", () => {
+ const id = "vendor/exact-model";
+ const generic = new CodexAPIFormat(id, undefined, { codexExtras: false }).buildPayload(
+ {},
+ [],
+ []
+ );
+ expect(generic.model).toBe(id);
+ expect(generic).not.toHaveProperty("store");
+ expect(generic).not.toHaveProperty("include");
+ const codex = new CodexAPIFormat(id).buildPayload({}, [], []);
+ expect(codex.model).toBe("exact-model");
+ expect(codex.store).toBe(false);
+ expect(codex.include).toEqual(["reasoning.encrypted_content"]);
+});
- test("no effort signal → no reasoning_effort set", () => {
- const fmt = new OpenAIAPIFormat("gpt-5.5");
- const payload = (fmt as any).buildChatCompletionsPayload({ max_tokens: 100 }, [], []);
- expect(payload.reasoning_effort).toBeUndefined();
+test.each([
+ ["low", "low"],
+ ["medium", "medium"],
+ ["high", "high"],
+ ["minimal", "low"],
+ ["max", "max"],
+])("published OpenAI Responses wire maps %s to %s", (effort, expected) => {
+ const result = resolveConnection("openai", "gpt-6.1-sol", cachePath);
+ if (!result.ok || result.connection.wire.status !== "known")
+ throw new Error("missing fixture wire");
+ const body: Record<string, unknown> = {};
+ shapeRequestFromWire(body, result.connection.wire, {
+ ...wireChoicesFromClaudeRequest({ max_tokens: 100, output_config: { effort } }),
+ hasTools: false,
});
+ expect(body).toHaveProperty("reasoning.effort", expected);
+ expect(body).toHaveProperty("max_output_tokens", 100);
+ expect(body).not.toHaveProperty("reasoning_effort");
});
diff --git a/packages/cli/src/format-translation.test.ts b/packages/cli/src/format-translation.test.ts
index dee3137a..7b68fc56 100644
--- a/packages/cli/src/format-translation.test.ts
+++ b/packages/cli/src/format-translation.test.ts
@@ -1237,18 +1237,6 @@ describe("Model Adapter Quirks", () => {
expect(request.temperature).toBe(0.7);
});
- test("OpenAIAdapter: thinking → reasoning_effort for o3", async () => {
- const { OpenAIAPIFormat } = await import("./adapters/openai-api-format.js");
- const adapter = new OpenAIAPIFormat("o3-mini");
-
- const request: any = { model: "o3-mini", messages: [] };
- const original = { thinking: { budget_tokens: 32000 } };
-
- adapter.prepareRequest(request, original);
- expect(request.reasoning_effort).toBe("high");
- expect(request.thinking).toBeUndefined();
- });
-
test("GLMAdapter: glm-5 converts Anthropic budget thinking to GLM's toggle", async () => {
const { GLMModelDialect } = await import("./adapters/glm-model-dialect.js");
const adapter = new GLMModelDialect("glm-5");
diff --git a/packages/cli/src/handlers/advisor-routing-and-state.test.ts b/packages/cli/src/handlers/advisor-routing-and-state.test.ts
index 63d9d60e..6c8e83a3 100644
--- a/packages/cli/src/handlers/advisor-routing-and-state.test.ts
+++ b/packages/cli/src/handlers/advisor-routing-and-state.test.ts
@@ -1,4 +1,8 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
+import { mkdirSync, 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 { _resetCatalogClient, _setCatalogEntriesForTest } from "../providers/catalog-client.js";
import {
ADVISOR_STUB_PATHS,
@@ -9,7 +13,6 @@ import {
markAdvisorCallConsumed,
recordAdvisorEventsFromResponseBody,
rewriteAdvisorToolResults,
- runAdvisorCall,
} from "./native-handler-advisor.js";
const cfg = { enabled: true, logPath: undefined };
@@ -245,49 +248,111 @@ describe("OpenRouter advisor wire-model resolution", () => {
});
describe("advisor request token parameter routing", () => {
- const messages = [{ role: "user", content: "Review this fixture." }];
- const apiKeys = {
- openai: "test-openai-key",
- openrouter: "test-openrouter-key",
- google: "test-google-key",
- };
-
+ // resolveConnection inside the advisor has no cache-path argument. Import it
+ // in an isolated child so its default path cannot reach the user's cache.
async function captureRequest(
- model: string
+ model: string,
+ cache?: DiskCacheV3
): Promise<{ url: URL; body: Record<string, unknown> }> {
- let capturedInput: RequestInfo | URL | undefined;
- let capturedInit: RequestInit | undefined;
- const fetchImpl = Object.assign(
- async (input: RequestInfo | URL, init?: RequestInit) => {
- capturedInput = input;
- capturedInit = init;
- return new Response(JSON.stringify({ choices: [{ message: { content: "ok" } }] }), {
- status: 200,
- headers: { "Content-Type": "application/json" },
- });
- },
- { preconnect(_url: string | URL): void {} }
- ) as typeof fetch;
-
- await runAdvisorCall({
- toolUseId: `advisor-token-param-${model}`,
- messages,
- models: [model],
- collector: null,
- apiKeys,
- fetchImpl,
- warn: () => {},
- });
-
- if (capturedInput === undefined || capturedInit?.body === undefined) {
- throw new Error(`Expected ${model} to issue an advisor request`);
+ const dir = mkdtempSync(join(tmpdir(), "advisor-wire-"));
+ try {
+ if (cache) {
+ mkdirSync(join(dir, ".claudish"));
+ writeFileSync(
+ join(dir, ".claudish", "cloud-models-catalog-v3.json"),
+ JSON.stringify(cache)
+ );
+ }
+ const script = `
+ const { runAdvisorCall } = await import(${JSON.stringify(new URL("./native-handler-advisor.ts", import.meta.url).pathname)});
+ let captured;
+ globalThis.fetch = async (input, init) => {
+ captured = { url: String(input), body: JSON.parse(String(init.body)) };
+ return Response.json({ choices: [{ message: { content: "ok" } }] });
+ };
+ await runAdvisorCall({ toolUseId: "advisor-wire-test", messages: [{role: "user", content: "Review this fixture."}],
+ models: [${JSON.stringify(model)}], collector: null,
+ apiKeys: {openai: "test-key", google: "test-key", openrouter: "test-key"},
+ fetchImpl: globalThis.fetch, warn: () => {} });
+ if (!captured) throw new Error("Advisor issued no request");
+ console.log(JSON.stringify(captured));
+ `;
+ const child = Bun.spawnSync([process.execPath, "--eval", script], {
+ env: {
+ PATH: process.env.PATH,
+ HOME: dir,
+ CLAUDISH_DISABLE_KEYCHAIN: "1",
+ CLAUDISH_DISABLE_OP: "1",
+ CLAUDISH_DISABLE_CATALOG_WARM: "1",
+ },
+ stdout: "pipe",
+ stderr: "pipe",
+ });
+ expect(child.exitCode, child.stderr.toString()).toBe(0);
+ const captured = JSON.parse(child.stdout.toString());
+ return { url: new URL(captured.url), body: captured.body };
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
}
- return {
- url: new URL(String(capturedInput)),
- body: JSON.parse(String(capturedInit.body)) as Record<string, unknown>,
- };
}
+ const fixture: DiskCacheV3 = JSON.parse(
+ readFileSync(
+ new URL(
+ "../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json",
+ import.meta.url
+ ),
+ "utf8"
+ )
+ );
+ it.each(["max_tokens", "max_completion_tokens"] as const)(
+ "reads %s from the OpenAI chat connection",
+ async (tokenParam) => {
+ const cache = structuredClone(fixture);
+ const entry = cache.entries.find((entry) => entry.modelId === "gpt-6.1-sol")!;
+ const connection = entry.aggregators!.find(
+ (connection) =>
+ connection.route?.routeId === "openai" && connection.route.routeProfileId === "direct-api"
+ )!;
+ if (connection.wire?.status !== "known") throw new Error("missing fixture wire");
+ // Change only the API and limit field of a real connection to exercise a
+ // chat wire; this fixture's OpenAI connections currently all use Responses.
+ connection.wire.api = "chat-completions";
+ connection.wire.tokenParam = tokenParam;
+ const request = await captureRequest("[email protected]", cache);
+ expect(request.body).toHaveProperty(tokenParam);
+ expect(request.body).not.toHaveProperty(
+ tokenParam === "max_tokens" ? "max_completion_tokens" : "max_tokens"
+ );
+ expect(request.body).not.toHaveProperty("max_output_tokens");
+ }
+ );
+
+ it("does not copy the Responses token field into advisor Chat Completions", async () => {
+ const request = await captureRequest("[email protected]", fixture);
+ expect(request.body).toHaveProperty("max_completion_tokens");
+ expect(request.body).not.toHaveProperty("max_output_tokens");
+ });
+
+ it.each(["max_output_tokens", { status: "unknown" }, { status: "not_applicable" }] as const)(
+ "uses the chat default for token field %j",
+ async (tokenParam) => {
+ const cache = structuredClone(fixture);
+ const entry = cache.entries.find((entry) => entry.modelId === "gpt-6.1-sol")!;
+ const connection = entry.aggregators!.find(
+ (connection) =>
+ connection.route?.routeId === "openai" && connection.route.routeProfileId === "direct-api"
+ )!;
+ if (connection.wire?.status !== "known") throw new Error("missing fixture wire");
+ connection.wire.api = "chat-completions";
+ connection.wire.tokenParam = tokenParam;
+ const request = await captureRequest("[email protected]", cache);
+ expect(request.body).toHaveProperty("max_completion_tokens");
+ expect(request.body).not.toHaveProperty("max_tokens");
+ expect(request.body).not.toHaveProperty("max_output_tokens");
+ }
+ );
+
it("uses max_completion_tokens on the direct OpenAI route", async () => {
const request = await captureRequest("openai@some-model");
diff --git a/packages/cli/src/handlers/composed-handler-wire.test.ts b/packages/cli/src/handlers/composed-handler-wire.test.ts
index 7b97a0d6..83389fc1 100644
--- a/packages/cli/src/handlers/composed-handler-wire.test.ts
+++ b/packages/cli/src/handlers/composed-handler-wire.test.ts
@@ -155,3 +155,177 @@ test("request marker context sends priority on OpenAI", async () => {
expect(calls[0]!.body.service_tier).toBe("priority");
expect(wireMarkerContext.getStore()).toBeUndefined();
});
+
+test.each(["google/gemini-3.8-flash", "opaque-model"])(
+ "Google vendor on a chat wire preserves thought signatures for %s",
+ async (model) => {
+ const connection = resolved("openrouter", "gemini-3.8-flash");
+ expect(connection.vendor).toBe("google");
+ expect(connection.wire.api).toBe("chat-completions");
+ // Rename only the fixture connection's ids: the vendor and wire remain real.
+ connection.externalModelId = model;
+ connection.modelId = model;
+ const handler = buildKnownWireHandler(
+ context("openrouter", model),
+ "openrouter",
+ connection,
+ connection.wire
+ )!;
+ handlers.push(handler);
+ const details = [{ type: "reasoning.encrypted", id: "call_signature", data: "test-signature" }];
+ const bodies: any[] = [];
+ globalThis.fetch = (async (_input, init) => {
+ bodies.push(JSON.parse(String(init?.body)));
+ if (bodies.length > 1) return new Response("captured", { status: 599 });
+ const frames = [
+ {
+ choices: [
+ {
+ delta: {
+ role: "assistant",
+ reasoning_details: details,
+ tool_calls: [
+ {
+ index: 0,
+ id: "call_signature",
+ type: "function",
+ function: { name: "Read", arguments: '{"path":"README.md"}' },
+ },
+ ],
+ },
+ finish_reason: null,
+ },
+ ],
+ },
+ { choices: [{ delta: {}, finish_reason: "tool_calls" }] },
+ ];
+ return new Response(
+ frames.map((frame) => `data: ${JSON.stringify(frame)}\n\n`).join("") + "data: [DONE]\n\n",
+ { headers: { "content-type": "text/event-stream" } }
+ );
+ }) as typeof fetch;
+ const app = new Hono();
+ app.post("/", async (c) => handler.handle(c, await c.req.json()));
+ const base = {
+ model,
+ stream: true,
+ max_tokens: 100,
+ tools: [
+ {
+ name: "Read",
+ description: "Read",
+ input_schema: { type: "object", properties: { path: { type: "string" } } },
+ },
+ ],
+ };
+ const messages: any[] = [{ role: "user", content: "Read README.md" }];
+ const first = await app.request("/", {
+ method: "POST",
+ body: JSON.stringify({ ...base, messages }),
+ headers: { "content-type": "application/json" },
+ });
+ expect(first.status).toBe(200);
+ expect(await first.text()).toContain("call_signature");
+ messages.push(
+ {
+ role: "assistant",
+ content: [
+ { type: "tool_use", id: "call_signature", name: "Read", input: { path: "README.md" } },
+ ],
+ },
+ {
+ role: "user",
+ content: [{ type: "tool_result", tool_use_id: "call_signature", content: "file contents" }],
+ }
+ );
+ await app.request("/", {
+ method: "POST",
+ body: JSON.stringify({ ...base, messages }),
+ headers: { "content-type": "application/json" },
+ });
+ expect(bodies).toHaveLength(2);
+ const assistant = bodies[1].messages.find((message: any) => message.role === "assistant");
+ expect(assistant.reasoning_details).toEqual(details);
+ }
+);
+
+test.each([
+ ["openai", "grok-vendor-regression", false],
+ ["", "grok-vendor-regression", false],
+ ["x-ai", "opaque-model", true],
+] as const)(
+ "chat wire vendor %s controls the xAI instruction for %s",
+ async (vendor, model, expectsInstruction) => {
+ const connection = resolved("fireworks", "deepseek-v4.1-flash");
+ expect(connection.wire.api).toBe("chat-completions");
+ // Keep the fixture's chat wire and route binding, but make vendor and id
+ // disagree. Fireworks uses a plain OpenAIAPIFormat, with no vendor hint
+ // supplied by its constructor: ComposedHandler must pass the connection's.
+ connection.vendor = vendor;
+ connection.externalModelId = model;
+ connection.modelId = model;
+ const handler = buildKnownWireHandler(
+ context("fireworks", model),
+ "fireworks",
+ connection,
+ connection.wire
+ )!;
+ expect(handler).toBeInstanceOf(ComposedHandler);
+ handlers.push(handler);
+ const calls = capture("invalid value");
+ const app = new Hono();
+ app.post("/", (c) =>
+ handler.handle(c, {
+ model,
+ system: "You help with code.",
+ messages: [{ role: "user", content: "hello" }],
+ max_tokens: 100,
+ stream: true,
+ })
+ );
+ await app.request("/", { method: "POST" });
+ expect(calls).toHaveLength(1);
+ const system = calls[0]!.body.messages.find(
+ (message: { role: string }) => message.role === "system"
+ );
+ expect(system?.content).toContain("You help with code.");
+ const instruction = "NEVER use XML format like <xai:function_call>";
+ if (expectsInstruction) expect(system.content).toContain(instruction);
+ else expect(system.content).not.toContain(instruction);
+ }
+);
+
+test("a catalog connection bypasses the MiniMax name-picked temperature dialect", async () => {
+ const connection = resolved("opencode-zen", "minimax-m3");
+ const ctx = context("opencode-zen", "minimax-m3");
+ const connected = buildKnownWireHandler(ctx, "opencode-zen", connection, connection.wire)!;
+ const offCatalog = new ComposedHandler(
+ new OpenAIProviderTransport(ctx.provider, ctx.modelName, ctx.apiKey),
+ ctx.targetModel,
+ ctx.modelName,
+ 0,
+ { adapter: new OpenAIAPIFormat(ctx.modelName) }
+ );
+ handlers.push(connected, offCatalog);
+ const bodies: any[] = [];
+ globalThis.fetch = (async (_input, init) => {
+ bodies.push(JSON.parse(String(init?.body)));
+ return new Response("captured", { status: 599 });
+ }) as typeof fetch;
+ for (const handler of [connected, offCatalog]) {
+ const app = new Hono();
+ app.post("/", (c) =>
+ handler.handle(c, {
+ model: "minimax-m3",
+ messages: [{ role: "user", content: "hello" }],
+ max_tokens: 100,
+ temperature: 0,
+ stream: true,
+ })
+ );
+ await app.request("/", { method: "POST" });
+ }
+ expect(bodies).toHaveLength(2);
+ expect(bodies[0].temperature).toBe(0);
+ expect(bodies[1].temperature).toBe(0.01);
+});
diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.ts
index c1f4406c..f5121e43 100644
--- a/packages/cli/src/handlers/composed-handler.ts
+++ b/packages/cli/src/handlers/composed-handler.ts
@@ -21,7 +21,11 @@
*/
import type { Context } from "hono";
-import type { BaseAPIFormat, EffortLevel } from "../adapters/base-api-format.js";
+import {
+ type BaseAPIFormat,
+ DefaultAPIFormat,
+ type EffortLevel,
+} from "../adapters/base-api-format.js";
import type { ProviderTransport, StreamFormat } from "../providers/transport/types.js";
import type { ModelHandler } from "./types.js";
// Alias for readability within this file
@@ -289,14 +293,24 @@ export class ComposedHandler implements ModelHandler {
// provider.overrideStreamFormat(), which only re-labels the RESPONSE for
// aggregators. Undefined when no explicit converter was passed (the dialect
// is then also the converter) → dialects fall back to the OpenAI default.
- this.resolvedDialect = resolveModelDialect(
- this.bareModelName,
- this.explicitAdapter?.getStreamFormat()
- );
+ //
+ // A CATALOG CONNECTION gets no name-picked dialect at all: its `wire`
+ // decides every reasoning and limit field (step 5w), and a dialect chosen
+ // by model name is exactly the guess the wire replaces. Only a handler
+ // without a connection (dynamic subscription, custom or local endpoint)
+ // still resolves one.
+ this.resolvedDialect = options.connection
+ ? new DefaultAPIFormat(this.bareModelName, this.explicitAdapter?.getStreamFormat())
+ : resolveModelDialect(this.bareModelName, this.explicitAdapter?.getStreamFormat());
// Always resolve model-specific adapter (GLM, Grok, DeepSeek, etc.)
// This handles model quirks independent of provider transport (LiteLLM, OpenRouter, etc.)
const resolvedModelAdapter = this.resolvedDialect;
+ if (options.connection) {
+ for (const adapter of [this.explicitAdapter, this.resolvedDialect]) {
+ adapter?.setUpstreamVendor(options.connection.vendor ?? "");
+ }
+ }
if (resolvedModelAdapter.getName() !== "DefaultAPIFormat") {
this.modelAdapter = resolvedModelAdapter;
}
@@ -327,8 +341,20 @@ export class ComposedHandler implements ModelHandler {
// Use bareModelName for the middleware gate — .includes() works identically for
// "[email protected]" and "gemini-2.5-flash", and bare form is the invariant.
this.middlewareManager = new MiddlewareManager();
- if (this.bareModelName.includes("gemini") || this.bareModelName.includes("google/")) {
- this.middlewareManager.register(new GeminiThoughtSignatureMiddleware());
+ // With a connection, from data: a Gemini-API wire, or a Google model behind
+ // a gateway (OpenRouter carries its thought signatures in reasoning_details).
+ const connectionWire = options.connection?.wire;
+ if (
+ options.connection
+ ? (connectionWire?.status === "known" && connectionWire.api === "gemini") ||
+ options.connection.vendor === "google"
+ : this.bareModelName.includes("gemini") || this.bareModelName.includes("google/")
+ ) {
+ // Selected from data when there is a connection: the middleware's own
+ // name gate must not re-filter an opaque gateway id out again.
+ this.middlewareManager.register(
+ new GeminiThoughtSignatureMiddleware({ alwaysHandle: !!options.connection })
+ );
}
this.middlewareManager
.initialize()
diff --git a/packages/cli/src/handlers/native-handler-advisor.ts b/packages/cli/src/handlers/native-handler-advisor.ts
index 9249a233..f65f0473 100644
--- a/packages/cli/src/handlers/native-handler-advisor.ts
+++ b/packages/cli/src/handlers/native-handler-advisor.ts
@@ -35,12 +35,12 @@ import { catalogRouteMatchesProvider } from "../providers/catalog-route-bindings
*/
import { appendFileSync } from "node:fs";
-import { lookupModelTokenParam } from "../adapters/model-catalog.js";
import { credentials } from "../auth/credentials/authority.js";
import { getAlwaysOnLogPath, getLogFilePath, log, logStderr } from "../logger.js";
import { type SlimModelEntry, readAllModelsCache } from "../providers/all-models-cache.js";
import { getCatalogEntries, latestAnthropicTierModelId } from "../providers/catalog-client.js";
import { findEntryByAlias } from "../providers/catalog-query.js";
+import { resolveConnection } from "../providers/connection-resolver.js";
import { parseModelSpec } from "../providers/model-parser.js";
import { extractProviderMessage, extractUpstreamStatus } from "./shared/anthropic-error.js";
@@ -1877,20 +1877,11 @@ const ADVISOR_MAX_OUTPUT_TOKENS = 2048;
*
* - `openrouter` and `google` keep `max_tokens`. Both normalise it for every
* model they serve, and run D proves it live (deepseek-v4-pro, HTTP 200).
- * - `openai` (api.openai.com) asks the LIVE catalog, via the same
- * `tokenParam` field claudish's OpenAI chat-completions converter reads first
- * (`OpenAIApiFormat.tokenParamName` → `lookupModelTokenParam`). That converter
- * is the existing per-format rule; its catalog lookup is the part that is
- * right, and it is reused here rather than restated. Its private name-based
- * fallback (`gpt-5`/`o1`/`o3`/`o4` → `max_completion_tokens`) is NOT copied —
- * a second copy of a guess is exactly what CLAUDE.md's "never hardcode a
- * provider's models" rule is about, and this endpoint has a better default (below).
- *
- * ONE endpoint-level correction on the catalog's answer: `max_output_tokens` is
- * the RESPONSES-API spelling. The catalog says exactly that for gpt-5.6-sol
- * (`endpoints.openai.api === "responses"`), but the advisor always POSTs
- * `/v1/chat/completions`, which does not accept it. On this route it becomes
- * `max_completion_tokens` — the spelling OpenAI's own 400 asked for:
+ * - `openai` (api.openai.com) reads the `openai/direct-api` connection's
+ * `wire.tokenParam`, when that wire is Chat Completions. A Responses wire's
+ * field (`max_output_tokens`) is never a chat field: the advisor always POSTs
+ * `/v1/chat/completions`, so there it becomes `max_completion_tokens` — the
+ * spelling OpenAI's own 400 asked for:
* "Unsupported parameter: 'max_tokens' is not supported with this model.
* Use 'max_completion_tokens' instead."
* (observed twice for gpt-5.6-sol, runs phase7b-B and phase7b-C).
@@ -1901,14 +1892,17 @@ const ADVISOR_MAX_OUTPUT_TOKENS = 2048;
*/
function advisorTokenParamFor(route: AdvisorRoute): string {
if (route.kind !== "openai") return "max_tokens";
- let fromCatalog: string | undefined;
- try {
- fromCatalog = lookupModelTokenParam(route.wireModel);
- } catch {
- // The lookup rejects a `provider@model` string outright; a wire id it will
- // not read is simply no information, like a cold cache.
+ // The connection's own wire, and only when that wire is Chat Completions —
+ // the API this request uses. Since catalog 3.7.0 the model-level
+ // `tokenParam` describes the owner's direct connection, which for a
+ // Responses model is `max_output_tokens`: not a chat field at all.
+ const resolution = resolveConnection("openai", route.wireModel);
+ const wire = resolution.ok ? resolution.connection.wire : undefined;
+ if (wire?.status === "known" && wire.api === "chat-completions") {
+ if (wire.tokenParam === "max_tokens" || wire.tokenParam === "max_completion_tokens") {
+ return wire.tokenParam;
+ }
}
- if (fromCatalog === "max_tokens" || fromCatalog === "max_completion_tokens") return fromCatalog;
return "max_completion_tokens";
}
diff --git a/packages/cli/src/handlers/shared/format/openai-messages.ts b/packages/cli/src/handlers/shared/format/openai-messages.ts
index 1f410367..e31a529b 100644
--- a/packages/cli/src/handlers/shared/format/openai-messages.ts
+++ b/packages/cli/src/handlers/shared/format/openai-messages.ts
@@ -14,7 +14,13 @@ export function convertMessagesToOpenAI(
req: any,
modelId: string,
filterIdentityFn?: (s: string) => string,
- simpleFormat = false
+ simpleFormat = false,
+ /**
+ * The upstream model's vendor from its catalog connection (`""` when the
+ * catalog names none). When given, it alone decides the Grok tool-format
+ * instruction; the model-name check below applies only without a connection.
+ */
+ upstreamVendor?: string
): any[] {
const messages: any[] = [];
@@ -27,7 +33,11 @@ export function convertMessagesToOpenAI(
}
// Add instruction for Grok models to use proper tool format
- if (modelId.includes("grok") || modelId.includes("x-ai")) {
+ const isGrokUpstream =
+ upstreamVendor !== undefined
+ ? upstreamVendor === "x-ai"
+ : modelId.includes("grok") || modelId.includes("x-ai");
+ if (isGrokUpstream) {
const msg =
"IMPORTANT: When calling tools, you MUST use the OpenAI tool_calls format with JSON. NEVER use XML format like <xai:function_call>.";
if (messages.length > 0 && messages[0].role === "system") {
diff --git a/packages/cli/src/middleware/gemini-thought-signature.ts b/packages/cli/src/middleware/gemini-thought-signature.ts
index aa6967fb..f99ccca1 100644
--- a/packages/cli/src/middleware/gemini-thought-signature.ts
+++ b/packages/cli/src/middleware/gemini-thought-signature.ts
@@ -46,7 +46,15 @@ export class GeminiThoughtSignatureMiddleware implements ModelMiddleware {
}
>();
+ /**
+ * `alwaysHandle`: the handler selected this middleware from catalog data
+ * (a Gemini-API wire, or a Google model behind a gateway), so the model name
+ * — possibly an opaque gateway id — is not asked again.
+ */
+ constructor(private readonly options: { alwaysHandle?: boolean } = {}) {}
+
shouldHandle(modelId: string): boolean {
+ if (this.options.alwaysHandle) return true;
return modelId.includes("gemini") || modelId.includes("google/");
}
diff --git a/packages/cli/src/providers/connection-resolver.test.ts b/packages/cli/src/providers/connection-resolver.test.ts
index 23ee2bc0..1baca2de 100644
--- a/packages/cli/src/providers/connection-resolver.test.ts
+++ b/packages/cli/src/providers/connection-resolver.test.ts
@@ -229,6 +229,7 @@ describe("production connection resolution", () => {
ok: true,
connection: {
provider,
+ vendor: record.provider,
modelId,
route: { routeId, routeProfileId },
externalModelId,
diff --git a/packages/cli/src/providers/connection-resolver.ts b/packages/cli/src/providers/connection-resolver.ts
index 4d7503a5..231d2f79 100644
--- a/packages/cli/src/providers/connection-resolver.ts
+++ b/packages/cli/src/providers/connection-resolver.ts
@@ -30,6 +30,12 @@ export interface ResolvedConnection {
provider: string;
/** The catalog record's canonical model id. */
modelId: string;
+ /**
+ * The model's vendor (the catalog's `provider` field), when published. Data,
+ * not a name match: what a gateway needs to know about the upstream family
+ * (Gemini thought signatures, Grok tool-call format) is read from here.
+ */
+ vendor?: string;
route: CatalogRouteBinding;
/** The exact id sent to the provider. */
externalModelId: string;
@@ -135,6 +141,7 @@ export function resolveConnection(
connection: {
provider,
modelId: found.entry.modelId,
+ ...(found.entry.provider ? { vendor: found.entry.provider } : {}),
route,
externalModelId: found.connection.externalModelId as string,
wire: found.connection.wire,
diff --git a/packages/cli/src/providers/no-name-rules.test.ts b/packages/cli/src/providers/no-name-rules.test.ts
new file mode 100644
index 00000000..1a790b34
--- /dev/null
+++ b/packages/cli/src/providers/no-name-rules.test.ts
@@ -0,0 +1,60 @@
+import { expect, test } from "bun:test";
+import { readFileSync, readdirSync } from "node:fs";
+import { join, relative } from "node:path";
+
+const root = new URL("../", import.meta.url).pathname;
+const forbidden = [
+ "requiresResponsesApi",
+ "clampOpenAIEffortByName",
+ "clampCodexEffort",
+ "SEED_REJECTS",
+ "isSakanaFugu",
+ "isGpt51Plus",
+ "isOSeries",
+ "isOriginalGpt5",
+ "isCodex51Plus",
+ "acceptsXhigh",
+ "acceptsMax",
+ "isO3Model",
+ "lookupModelTokenParam",
+ "lookupModelEndpoint",
+ "tokenParamName",
+];
+function files(dir: string): string[] {
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
+ const path = join(dir, entry.name);
+ return entry.isDirectory()
+ ? files(path)
+ : /\.tsx?$/.test(path) && !/\.test\.tsx?$/.test(path)
+ ? [path]
+ : [];
+ });
+}
+function hits(path: string, needles: string[]): string[] {
+ // Decode bytes explicitly: embedded NULs must never make a source file invisible.
+ const source = new TextDecoder().decode(readFileSync(path));
+ return source
+ .split("\n")
+ .flatMap((line, index) =>
+ needles
+ .filter((needle) => line.includes(needle))
+ .map((needle) => `${relative(root, path)}:${index + 1}: ${needle}`)
+ );
+}
+test("non-local production sources contain none of the deleted name rules", () => {
+ const found = files(root)
+ .filter((path) => relative(root, path) !== "adapters/local-adapter.ts")
+ .flatMap((path) => hits(path, forbidden));
+ expect(found, found.join("\n")).toEqual([]);
+});
+test("profiles do not select an API by model family", () => {
+ const found = hits(
+ join(root, "providers/provider-profiles.ts"),
+ ["qwen3", "gpt-", "grok-", "minimax-", "claude-"].map((name) => `startsWith("${name}")`)
+ );
+ expect(found, found.join("\n")).toEqual([]);
+});
+test("OpenAI transport does not select Responses by codex in the name", () => {
+ const found = hits(join(root, "providers/transport/openai.ts"), ['includes("codex")']);
+ expect(found, found.join("\n")).toEqual([]);
+});
diff --git a/packages/cli/src/providers/provider-profiles.test.ts b/packages/cli/src/providers/provider-profiles.test.ts
index 55732aff..df5bdc2c 100644
--- a/packages/cli/src/providers/provider-profiles.test.ts
+++ b/packages/cli/src/providers/provider-profiles.test.ts
@@ -1,162 +1,112 @@
-import { afterAll, describe, expect, test } from "bun:test";
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
+import { describe, expect, test } from "bun:test";
+import { OpenAIAPIFormat } from "../adapters/openai-api-format.js";
+import { ComposedHandler } from "../handlers/composed-handler.js";
import { getProviderByName, toRemoteProvider } from "./provider-definitions.js";
-import { createHandlerForProvider } from "./provider-profiles.js";
-
-// The composition table must not read the ambient ~/.claudish/all-models.json.
-const fixtureDir = mkdtempSync(join(tmpdir(), "provider-profiles-"));
-const catalogCachePath = join(fixtureDir, "all-models.json");
-
-afterAll(() => {
- rmSync(fixtureDir, { recursive: true, force: true });
-});
-
-writeFileSync(
- catalogCachePath,
- JSON.stringify({
- catalogGenerationId: "test-generation",
- plans: [],
- version: 3,
- lastUpdated: new Date().toISOString(),
- entries: [
- {
- modelId: "acme-responses-x1.0",
- aliases: [],
-
- endpoints: {
- openai: { api: "responses", toolsWithReasoning: "requires-responses" },
- },
- tokenParam: "max_output_tokens",
- },
- ],
- models: [],
- })
-);
-
-interface Composition {
- transport: string;
- streamFormat: string;
- endpoint: string;
-}
-
-async function describeHandler(providerName: string, modelName: string): Promise<Composition> {
- const def = getProviderByName(providerName)!;
- const handler: any = await createHandlerForProvider({
- provider: toRemoteProvider(def),
+import {
+ type ProfileContext,
+ openCodeZenProfile,
+ openaiCodexProfile,
+ openaiProfile,
+ vertexProfile,
+} from "./provider-profiles.js";
+import { buildWireHandler } from "./wire-handler.js";
+
+const catalogCachePath = new URL(
+ "../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json",
+ import.meta.url
+).pathname;
+function context(provider: string, modelName: string): ProfileContext {
+ return {
+ provider: toRemoteProvider(getProviderByName(provider)!),
modelName,
+ targetModel: `${provider}@${modelName}`,
apiKey: "test-key",
- targetModel: modelName,
- port: 1234,
+ port: 0,
sharedOpts: {},
catalogCachePath,
- } as any);
-
- return handler.describeComposition();
+ };
+}
+async function describeHandler(provider: string, model: string) {
+ const handler = await vertexProfile.createHandler(context(provider, model));
+ expect(handler).toBeInstanceOf(ComposedHandler);
+ try {
+ return (handler as ComposedHandler).describeComposition();
+ } finally {
+ await handler?.shutdown();
+ }
}
-const expectedCompositions = [
- {
- provider: "opencode-zen-go",
- model: "grok-4.7",
- streamFormat: "openai-responses-sse",
- endpoint: "https://opencode.ai/zen/go/v1/responses",
- },
- {
- provider: "opencode-zen-go",
- model: "minimax-m2.5",
- streamFormat: "anthropic-sse",
- endpoint: "https://opencode.ai/zen/go/v1/messages",
- },
- {
- provider: "opencode-zen-go",
- model: "glm-5",
- streamFormat: "openai-sse",
- endpoint: "https://opencode.ai/zen/go/v1/chat/completions",
- },
- {
- provider: "opencode-zen-go",
- model: "gpt-5.6-luna",
- streamFormat: "openai-responses-sse",
- endpoint: "https://opencode.ai/zen/go/v1/responses",
- },
- {
- provider: "opencode-zen",
- model: "minimax-m2.5",
- streamFormat: "openai-sse",
- endpoint: "https://opencode.ai/zen/v1/chat/completions",
- },
- {
- provider: "opencode-zen",
- model: "glm-5",
- streamFormat: "openai-sse",
- endpoint: "https://opencode.ai/zen/v1/chat/completions",
- },
- {
- provider: "opencode-zen",
- model: "gpt-5.6-luna",
- streamFormat: "openai-responses-sse",
- endpoint: "https://opencode.ai/zen/v1/responses",
- },
- {
- provider: "opencode-zen-go",
- model: "qwen3.7-plus",
- streamFormat: "anthropic-sse",
- endpoint: "https://opencode.ai/zen/go/v1/messages",
- },
- {
- provider: "opencode-zen",
- model: "qwen3.7-max",
- streamFormat: "anthropic-sse",
- endpoint: "https://opencode.ai/zen/v1/messages",
- },
- {
- provider: "opencode-zen",
- model: "claude-fable-5",
- streamFormat: "anthropic-sse",
- endpoint: "https://opencode.ai/zen/v1/messages",
- },
- {
- provider: "opencode-zen",
- model: "grok-4.5",
- streamFormat: "openai-responses-sse",
- endpoint: "https://opencode.ai/zen/v1/responses",
- },
-] as const;
-
-describe("OpenCode Zen provider composition", () => {
- for (const row of expectedCompositions) {
- test(`${row.provider} ${row.model} uses ${row.streamFormat} at ${row.endpoint}`, async () => {
- expect(await describeHandler(row.provider, row.model)).toEqual({
- transport: row.provider,
- streamFormat: row.streamFormat,
- endpoint: row.endpoint,
- });
+for (const provider of ["openai", "opencode-zen", "opencode-zen-go"]) {
+ for (const model of [
+ "qwen3.7-plus",
+ "claude-opus-5",
+ "minimax-m3",
+ "gpt-6.1-sol",
+ "grok-4.7",
+ "codex-mini-latest",
+ ]) {
+ test(`${provider}@${model} off catalog uses OpenAIAPIFormat and the configured chat endpoint`, async () => {
+ const ctx = context(provider, model);
+ const factory = provider === "openai" ? openaiProfile : openCodeZenProfile;
+ const handler = factory.createHandler(ctx);
+ expect(handler).toBeInstanceOf(ComposedHandler);
+ try {
+ expect((handler as any).explicitAdapter).toBeInstanceOf(OpenAIAPIFormat);
+ expect((handler as ComposedHandler).describeComposition()).toEqual({
+ transport: provider,
+ streamFormat: "openai-sse",
+ endpoint: ctx.provider.baseUrl + ctx.provider.apiPath,
+ });
+ } finally {
+ await handler?.shutdown();
+ }
});
}
+}
- test("Go MiniMax and metered Zen MiniMax use their documented distinct APIs", async () => {
- expect(
- (await describeHandler("opencode-zen-go", "minimax-m3")).endpoint.endsWith("/v1/messages")
- ).toBe(true);
- expect(
- (await describeHandler("opencode-zen", "minimax-m3")).endpoint.endsWith(
- "/v1/chat/completions"
- )
- ).toBe(true);
+for (const [provider, model, streamFormat, endpoint] of [
+ [
+ "opencode-zen-go",
+ "grok-4.7",
+ "openai-responses-sse",
+ "https://opencode.ai/zen/go/v1/responses",
+ ],
+ ["opencode-zen-go", "minimax-m3", "anthropic-sse", "https://opencode.ai/zen/go/v1/messages"],
+ ["opencode-zen", "minimax-m3", "openai-sse", "https://opencode.ai/zen/v1/chat/completions"],
+ ["openai", "gpt-6.1-sol", "openai-responses-sse", "https://api.openai.com/v1/responses"],
+ ["poe", "grok-4.7", "openai-sse", "https://api.poe.com/v1/chat/completions"],
+]) {
+ test(`${provider}@${model} composition comes from its published wire`, async () => {
+ const result = await buildWireHandler(context(provider!, model!), provider!);
+ if (result.kind !== "handler") throw new Error(JSON.stringify(result));
+ try {
+ expect(result.handler).toBeInstanceOf(ComposedHandler);
+ expect((result.handler as ComposedHandler).describeComposition()).toEqual({
+ transport: provider,
+ streamFormat,
+ endpoint,
+ });
+ } finally {
+ await result.handler.shutdown();
+ }
});
-});
+}
-describe("Poe gateway composition", () => {
- test("builds a callable OpenAI-compatible handler", async () => {
- expect(await describeHandler("poe", "GPT-4o")).toEqual({
- transport: "poe",
- streamFormat: "openai-sse",
- endpoint: "https://api.poe.com/v1/chat/completions",
- });
- });
-});
+test.each(["gpt-5.3-codex", "gpt-4o"])(
+ "Codex off-catalog profile uses Responses for %s",
+ async (model) => {
+ const handler = openaiCodexProfile.createHandler(context("openai-codex", model));
+ try {
+ expect((handler as ComposedHandler).describeComposition()).toEqual({
+ transport: "openai-codex",
+ streamFormat: "openai-responses-sse",
+ endpoint: "https://api.openai.com/v1/responses",
+ });
+ } finally {
+ await handler?.shutdown();
+ }
+ }
+);
describe("Vertex project-aware composition", () => {
test("a selected project constructs its regional OAuth endpoint even with an Express key", async () => {
@@ -189,67 +139,3 @@ describe("Vertex project-aware composition", () => {
}
});
});
-
-describe("OpenAI Responses-API gate", () => {
- const responsesComposition = {
- transport: "openai",
- streamFormat: "openai-responses-sse",
- endpoint: "https://api.openai.com/v1/responses",
- } as const;
- const chatCompletionsComposition = {
- transport: "openai",
- streamFormat: "openai-sse",
- endpoint: "https://api.openai.com/v1/chat/completions",
- } as const;
- const openAICompositionCases = [
- { model: "acme-responses-x1.0", expected: responsesComposition },
- { model: "gpt-5.3-codex", expected: responsesComposition },
- { model: "gpt-5-codex", expected: responsesComposition },
- { model: "gpt-5.1-codex-max", expected: responsesComposition },
- { model: "gpt-5.1-codex-mini", expected: responsesComposition },
- { model: "GPT-5.1-CODEX-MINI", expected: responsesComposition },
- { model: "gpt-5.6-luna", expected: responsesComposition },
- { model: "gpt-5.6-sol", expected: responsesComposition },
- { model: "gpt-5.4", expected: chatCompletionsComposition },
- { model: "gpt-5.5", expected: chatCompletionsComposition },
- { model: "gpt-4o", expected: chatCompletionsComposition },
- { model: "gpt-5", expected: chatCompletionsComposition },
- { model: "gpt-5-mini", expected: chatCompletionsComposition },
- ] as const;
-
- for (const row of openAICompositionCases) {
- test(`openai ${row.model} uses ${row.expected.streamFormat} at ${row.expected.endpoint}`, async () => {
- expect(await describeHandler("openai", row.model)).toEqual(row.expected);
- });
- }
-
- test("a codex id routes to Responses regardless of where 'codex' appears in the name", async () => {
- expect(await describeHandler("openai", "codex-mini-latest")).toEqual(responsesComposition);
- });
-
- test("a codex id gets a Responses body AND a Responses endpoint (the two layers must agree)", async () => {
- for (const model of ["gpt-5.4-codex", "gpt-5.3-codex", "codex-mini-latest"]) {
- const composition = await describeHandler("openai", model);
-
- // The endpoint already follows the codex rule in transport/openai.ts:31,37;
- // streamFormat is what catches drift in the profile adapter choice.
- expect(composition.streamFormat).toBe("openai-responses-sse");
- expect(composition.endpoint.endsWith("/v1/responses")).toBe(true);
- }
- });
-
- test("a non-codex model keeps both layers on Chat Completions", async () => {
- const composition = await describeHandler("openai", "gpt-5.4");
-
- expect(composition.streamFormat).toBe("openai-sse");
- expect(composition.endpoint.endsWith("/v1/chat/completions")).toBe(true);
- });
-
- test("openai-codex remains Responses-only for codex and non-codex ids", async () => {
- const expected = { ...responsesComposition, transport: "openai-codex" };
-
- // This provider composes to Responses by construction, so the `openai` gate is not what decides it.
- expect(await describeHandler("openai-codex", "gpt-5.3-codex")).toEqual(expected);
- expect(await describeHandler("openai-codex", "gpt-4o")).toEqual(expected);
- });
-});
diff --git a/packages/cli/src/providers/provider-profiles.ts b/packages/cli/src/providers/provider-profiles.ts
index 3b9f3841..c74b5b56 100644
--- a/packages/cli/src/providers/provider-profiles.ts
+++ b/packages/cli/src/providers/provider-profiles.ts
@@ -24,7 +24,6 @@ import { CodexAPIFormat } from "../adapters/codex-api-format.js";
import { DevinAPIFormat } from "../adapters/devin-api-format.js";
import { GeminiAPIFormat } from "../adapters/gemini-api-format.js";
import { LiteLLMAPIFormat } from "../adapters/litellm-api-format.js";
-import { lookupModelEndpoint } from "../adapters/model-catalog.js";
import { OllamaAPIFormat } from "../adapters/ollama-api-format.js";
import { OpenAIAPIFormat } from "../adapters/openai-api-format.js";
import {
@@ -47,7 +46,7 @@ import { LiteLLMProviderTransport } from "./transport/litellm.js";
import { OllamaProviderTransport } from "./transport/ollamacloud.js";
import { OpenAICodexTransport } from "./transport/openai-codex.js";
import { OpenAIProviderTransport } from "./transport/openai.js";
-import { OpenCodeZenMessagesTransport, OpenCodeZenTransport } from "./transport/opencode-zen.js";
+import { OpenCodeZenTransport } from "./transport/opencode-zen.js";
import { PoeProvider } from "./transport/poe.js";
import { VertexProviderTransport, parseVertexModel } from "./transport/vertex-oauth.js";
import { RefusingHandler, buildWireHandler } from "./wire-handler.js";
@@ -74,7 +73,7 @@ export interface ProfileContext {
/**
* Catalog cache path override — a TEST SEAM, unset in production.
*
- * `requiresResponsesApi` reads the model catalog, which made the composition
+ * `buildWireHandler` reads the model catalog, which made the composition
* table in `provider-profiles.test.ts` depend on whichever
* `~/.claudish/cloud-models-catalog-v3.json` the machine happened to have. That is the
* v7.43.0 trap: green on every dev box, and a different answer on a cold CI
@@ -189,98 +188,6 @@ export const devinProfile: ProviderProfile = {
},
};
-/**
- * Models OpenAI will not serve over /v1/chat/completions.
- *
- * Two different reasons, one remedy. `gpt-5.6` rejects function tools together
- * with reasoning_effort ("use /v1/responses or set reasoning_effort to 'none'").
- * A `*codex*` model rejects the endpoint outright, and says so in as many words
- * — measured 2026-08-10 straight against api.openai.com with `gpt-5.3-codex`:
- *
- * POST /v1/chat/completions → 404 "This model is not supported in the
- * v1/chat/completions endpoint. Use the
- * v1/responses endpoint instead."
- * POST /v1/responses → 200
- *
- * So this is not the tools-plus-reasoning constraint wearing a second face; it
- * is a flatly Responses-only model. Claude Code sends tools on essentially every
- * request, which made every codex id unusable through `oai@` rather than merely
- * degraded.
- *
- * THE SUBSTRING TEST IS LOAD-BEARING, and it is not a style choice.
- * `OpenAIProviderTransport` has carried the same rule since long before this —
- * `modelName.toLowerCase().includes("codex")` decides both its stream format
- * (openai.ts:31) and its endpoint (openai.ts:37) — so Layer 3 was ALREADY
- * sending every codex id to /v1/responses. Only Layer 1 disagreed: this gate
- * matched `gpt-5.6` alone, so `openaiProfile` built an OpenAIAPIFormat and put
- * a Chat Completions body on a Responses endpoint. That mismatch is the whole
- * failure, and it is exactly what OpenAI reported back:
- *
- * 400 unsupported_parameter — "Unsupported parameter: 'messages'. In the
- * Responses API, this parameter has moved to 'input'."
- *
- * Right endpoint, wrong body. Any narrowing of this test (a `/^gpt-.*codex/`
- * prefix, an explicit id list) silently re-opens the split, because the
- * transport will keep routing ids this function no longer claims. The two tests
- * must stay identical; a test pins their agreement.
- *
- * THE GATE IS HOST-BLIND, and the comment here used to say otherwise ("only
- * OpenAI-served ids reach this gate"). `openaiProfile` is many-to-one — it also
- * serves x-ai, qwen, deepseek and mistralai (`provider-definitions.ts:228`) — so
- * every one of those hosts reaches this function. `endpoints.openai` is keyed by
- * TRANSPORT FAMILY, not by host, so the catalog cannot say "responses on OpenAI,
- * chat completions on x-ai" about one model id.
- *
- * Measured 2026-09-09 against the live catalog, nothing is mis-served by that:
- * all 8 Responses-only ids are `gpt-*`, which no other host under this profile
- * carries. The exposure is a future id served by two hosts on different APIs.
- *
- * `cx@` really is untouched, for a different reason than the old comment gave:
- * `openaiCodexProfile` builds `CodexAPIFormat` unconditionally and never calls
- * this function at all.
- *
- * Pick the verification model carefully. /v1/models is a dynamic models catalog,
- * NOT an entitlement: of those six ids, only `gpt-5.3-codex` actually answers 200 on
- * /v1/responses for the developer's account — the rest return 404 "Model not
- * found" there, and `gpt-5-codex` is additionally reported DEPRECATED on
- * /v1/chat/completions. Testing against any of them looks exactly like "the
- * routing fix did not work" when the model is simply not being served. It is the
- * same dynamic-models-catalog-vs-entitlement trap the Antigravity and Devin
- * providers document.
- *
- * THE CATALOG MAY ONLY WIDEN THIS GATE, NEVER NARROW IT. The name rule stays an
- * unconditional `||` below for the reason above: the transport routes every
- * `*codex*` id to /v1/responses on its own, so a catalog record that said "chat
- * completions" for one would restore the split in the other direction —
- * OpenAIAPIFormat's body on a Responses endpoint.
- *
- * The name rule alone could not stay correct, which is what this comment
- * predicted and what then happened. `gpt-6-astra` shipped 2026-09-03, matches
- * neither pattern, and is Responses-only. Its Chat Completions body carried the
- * catalog's own `tokenParam` and was rejected:
- *
- * 400 unknown_parameter — "Unknown parameter: 'max_output_tokens'."
- *
- * `max_output_tokens` is the Responses spelling. claudish was already reading
- * half of the catalog's endpoint contract — `tokenParam`, via
- * `OpenAIAPIFormat.tokenParamName` — while ignoring the sibling field that says
- * which wire API that spelling belongs to. Reading both is the fix. The name
- * rule survives only as the cold-cache fallback, where the catalog has no
- * opinion to read.
- *
- * @param cachePath Test seam. Points the catalog lookup at a fixture, so a test
- * never depends on a warm `~/.claudish/cloud-models-catalog-v3.json`.
- */
-export function requiresResponsesApi(modelName: string, cachePath?: string): boolean {
- const endpoint = lookupModelEndpoint(modelName, "openai", cachePath);
- if (endpoint?.api === "responses" || endpoint?.toolsWithReasoning === "requires-responses") {
- return true;
- }
-
- const name = modelName.toLowerCase();
- return /^gpt-5\.6/.test(name) || name.includes("codex");
-}
-
/**
* Grok Build subscription.
*
@@ -306,24 +213,14 @@ export const grokSubscriptionProfile: ProviderProfile = {
},
};
+/**
+ * OpenAI-compatible Chat Completions, for a provider the catalog does not route.
+ * A catalog connection never reaches this profile: `buildWireHandler` builds it
+ * from `wire.api` and the registry (Responses included), so no model name here
+ * decides an API.
+ */
export const openaiProfile: ProviderProfile = {
createHandler(ctx) {
- // Claude Code always sends tools, so requires-responses models must get the
- // whole Responses-API slice (endpoint + CodexAPIFormat payload + responses
- // SSE) swapped together — same composition the Zen profile uses for gpt-*.
- if (requiresResponsesApi(ctx.modelName, ctx.catalogCachePath)) {
- const responsesProvider = { ...ctx.provider, apiPath: "/v1/responses" };
- const transport = new OpenAIProviderTransport(responsesProvider, ctx.modelName, ctx.apiKey);
- const adapter = new CodexAPIFormat(ctx.modelName);
- const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
- adapter,
- tokenStrategy: "delta-aware",
- ...ctx.sharedOpts,
- });
- log(`[Proxy] Created OpenAI handler (Responses API composed): ${ctx.modelName}`);
- return handler;
- }
-
const transport = new OpenAIProviderTransport(ctx.provider, ctx.modelName, ctx.apiKey);
const adapter = new OpenAIAPIFormat(ctx.modelName);
const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
@@ -395,64 +292,22 @@ export const glmProfile: ProviderProfile = {
};
/**
- * OpenCode Zen and Go use model-specific wire APIs. The official endpoint tables
- * assign Qwen to Messages on both products, MiniMax to Messages on Go, GPT to
- * Responses, and most other listed families to Chat Completions. All paths
- * carry a stable per-conversation session header and the resolved product key.
+ * OpenCode Zen and Go. Each model's API (Chat, Responses or Messages) is its
+ * catalog connection's `wire.api`, built by `buildWireHandler`; this profile
+ * runs only when the catalog does not route the provider, and then speaks
+ * Chat Completions. The model-family list that used to choose the API here
+ * (qwen3/claude-/minimax- → Messages, gpt-/grok- → Responses) is gone.
*/
export const openCodeZenProfile: ProviderProfile = {
createHandler(ctx) {
- const zenApiKey = ctx.apiKey;
- const isGoProvider = ctx.provider.name === "opencode-zen-go";
- const model = ctx.modelName.toLowerCase();
-
- // OpenCode serves these model families over its Anthropic Messages endpoint.
- // The Go MiniMax route differs from the metered Zen route.
- if (
- model.startsWith("qwen3") ||
- (!isGoProvider && model.startsWith("claude-")) ||
- (isGoProvider && model.startsWith("minimax-"))
- ) {
- const messagesProvider = {
- ...ctx.provider,
- apiPath: "/v1/messages",
- authScheme: "x-api-key" as const,
- };
- const transport = new OpenCodeZenMessagesTransport(messagesProvider, zenApiKey);
- const adapter = new AnthropicAPIFormat(ctx.modelName, ctx.provider.name);
- return new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
- adapter,
- ...ctx.sharedOpts,
- });
- }
-
- // GPT and Grok models are served via the OpenAI Responses API (/v1/responses),
- // not /v1/chat/completions — on Go as well as Zen. Go's grok-4.7 answers chat
- // completions with 400 ModelProtocolUnsupported "Model does not support this
- // protocol." and /v1/responses with 200 (measured 2026-09-26).
- if (model.startsWith("gpt-") || model.startsWith("grok-")) {
- const responsesProvider = { ...ctx.provider, apiPath: "/v1/responses" };
- const transport = new OpenCodeZenTransport(responsesProvider, ctx.modelName, zenApiKey);
- const adapter = new CodexAPIFormat(ctx.modelName);
- const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
- adapter,
- tokenStrategy: "delta-aware",
- ...ctx.sharedOpts,
- });
- log(
- `[Proxy] Created OpenCode Zen${isGoProvider ? " Go" : ""} (Responses API composed): ${ctx.modelName}`
- );
- return handler;
- }
-
- const transport = new OpenCodeZenTransport(ctx.provider, ctx.modelName, zenApiKey);
+ const transport = new OpenCodeZenTransport(ctx.provider, ctx.modelName, ctx.apiKey);
const adapter = new OpenAIAPIFormat(ctx.modelName);
const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
adapter,
tokenStrategy: "delta-aware",
...ctx.sharedOpts,
});
- log(`[Proxy] Created OpenCode Zen${isGoProvider ? " Go" : ""} (composed): ${ctx.modelName}`);
+ log(`[Proxy] Created ${ctx.provider.name} handler (composed): ${ctx.modelName}`);
return handler;
},
};
diff --git a/packages/cli/src/providers/responses-api-gate.test.ts b/packages/cli/src/providers/responses-api-gate.test.ts
deleted file mode 100644
index 98975c8e..00000000
--- a/packages/cli/src/providers/responses-api-gate.test.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { afterAll, describe, expect, test } from "bun:test";
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
-import type { DiskCacheV3 } from "./all-models-cache.js";
-import { requiresResponsesApi } from "./provider-profiles.js";
-
-const fixtureDir = mkdtempSync(join(tmpdir(), "responses-api-gate-"));
-const cachePath = join(fixtureDir, "all-models.json");
-const missingCachePath = join(fixtureDir, "missing-all-models.json");
-
-afterAll(() => {
- rmSync(fixtureDir, { recursive: true, force: true });
-});
-
-const fixture: DiskCacheV3 = {
- catalogGenerationId: "test-generation",
- plans: [],
- version: 3,
- lastUpdated: new Date().toISOString(),
- entries: [
- {
- modelId: "acme-x1.0",
- aliases: ["openai/acme-x1.0"],
-
- contextWindow: 1050000,
- endpoints: { openai: { api: "responses" } },
- tokenParam: "max_output_tokens",
- },
- {
- modelId: "acme-x2.0",
- aliases: ["openai/acme-x2.0"],
-
- contextWindow: 1050000,
- endpoints: { openai: { toolsWithReasoning: "requires-responses" } },
- tokenParam: "max_output_tokens",
- },
- {
- modelId: "acme-x3.0",
- aliases: ["openai/acme-x3.0"],
-
- contextWindow: 1050000,
- tokenParam: "max_output_tokens",
- },
- {
- modelId: "acme-codex-x4.0",
- aliases: ["openai/acme-codex-x4.0"],
-
- contextWindow: 1050000,
- endpoints: { openai: { api: "chat-completions" } },
- tokenParam: "max_output_tokens",
- },
- ],
- models: [],
-};
-writeFileSync(cachePath, JSON.stringify(fixture));
-
-describe("requiresResponsesApi with an isolated catalog", () => {
- test("A: the catalog API widens the gate for an unrelated name", () => {
- expect(requiresResponsesApi("acme-x1.0", cachePath)).toBe(true);
- });
-
- test("B: toolsWithReasoning alone widens the gate", () => {
- expect(requiresResponsesApi("acme-x2.0", cachePath)).toBe(true);
- });
-
- test("C: a catalog entry without endpoints does not require Responses", () => {
- expect(requiresResponsesApi("acme-x3.0", cachePath)).toBe(false);
- });
-
- test("D: a model absent from the catalog does not require Responses", () => {
- expect(requiresResponsesApi("acme-x5.0", cachePath)).toBe(false);
- });
-
- test("E: the catalog cannot narrow the codex name rule", () => {
- expect(requiresResponsesApi("acme-codex-x4.0", cachePath)).toBe(true);
- });
-
- test("F: a cold catalog falls back to the name rule", () => {
- expect(requiresResponsesApi("acme-codex-x6.0", missingCachePath)).toBe(true);
- expect(requiresResponsesApi("acme-x7.0", missingCachePath)).toBe(false);
- });
-});
diff --git a/packages/cli/src/providers/transport/openai.test.ts b/packages/cli/src/providers/transport/openai.test.ts
index b4503229..615bbde8 100644
--- a/packages/cli/src/providers/transport/openai.test.ts
+++ b/packages/cli/src/providers/transport/openai.test.ts
@@ -182,3 +182,18 @@ describe("isTerminal429", () => {
expect(isTerminal429(transient)).toBe(false);
});
});
+
+test.each(["codex-mini-latest", "gpt-5-codex", "plain-model"])(
+ "transport uses baseUrl + apiPath and declares Chat Completions for %s",
+ (model) => {
+ const transport = new OpenAIProviderTransport(mockProvider, model, "test-key");
+ expect(transport.getEndpoint()).toBe(mockProvider.baseUrl + mockProvider.apiPath);
+ expect(transport.streamFormat).toBe("openai-sse");
+ const custom = new OpenAIProviderTransport(
+ { ...mockProvider, baseUrl: "https://fixture.invalid/custom", apiPath: "/endpoint" },
+ model,
+ "test-key"
+ );
+ expect(custom.getEndpoint()).toBe("https://fixture.invalid/custom/endpoint");
+ }
+);
diff --git a/packages/cli/src/providers/transport/openai.ts b/packages/cli/src/providers/transport/openai.ts
index 7cfa9e2b..479e46ce 100644
--- a/packages/cli/src/providers/transport/openai.ts
+++ b/packages/cli/src/providers/transport/openai.ts
@@ -29,16 +29,11 @@ export class OpenAIProviderTransport implements ProviderTransport {
this.name = provider.name;
this.displayName = OpenAIProviderTransport.formatDisplayName(provider.name);
- // Codex models use the Responses API which has a different streaming format
- this.streamFormat = modelName.toLowerCase().includes("codex")
- ? "openai-responses-sse"
- : "openai-sse";
+ // Declarative only: the parser is the adapter's (`wire.api` chooses it).
+ this.streamFormat = "openai-sse";
}
getEndpoint(): string {
- if (this.modelName.toLowerCase().includes("codex")) {
- return `${this.provider.baseUrl}/v1/responses`;
- }
return `${this.provider.baseUrl}${this.provider.apiPath}`;
}
diff --git a/packages/cli/src/providers/transport/opencode-zen.test.ts b/packages/cli/src/providers/transport/opencode-zen.test.ts
index 739268d1..ba1fad15 100644
--- a/packages/cli/src/providers/transport/opencode-zen.test.ts
+++ b/packages/cli/src/providers/transport/opencode-zen.test.ts
@@ -142,7 +142,7 @@ describe("OpenCodeZenMessagesTransport", () => {
describe("openCodeZenProfile", () => {
for (const providerName of ["opencode-zen-go", "opencode-zen"] as const) {
for (const modelName of ["minimax-m3", "gpt-5.4", "qwen3.7-plus"] as const) {
- test(`${providerName} ${modelName} uses the matching transport`, () => {
+ test(`${providerName} ${modelName} uses Chat Completions off catalog`, async () => {
const provider = remoteProvider(providerName);
const handler = openCodeZenProfile.createHandler({
provider,
@@ -153,12 +153,8 @@ describe("openCodeZenProfile", () => {
sharedOpts: {},
} as any);
- const messages =
- modelName.startsWith("qwen") ||
- (providerName === "opencode-zen-go" && modelName.startsWith("minimax"));
- expect((handler as any).provider).toBeInstanceOf(
- messages ? OpenCodeZenMessagesTransport : OpenCodeZenTransport
- );
+ expect((handler as any).provider).toBeInstanceOf(OpenCodeZenTransport);
+ await handler?.shutdown();
});
}
}
diff --git a/packages/cli/src/providers/wire-handler.test.ts b/packages/cli/src/providers/wire-handler.test.ts
index 0f62d6eb..8b026c96 100644
--- a/packages/cli/src/providers/wire-handler.test.ts
+++ b/packages/cli/src/providers/wire-handler.test.ts
@@ -7,7 +7,12 @@ import type { DiskCacheV3 } from "./all-models-cache.js";
import { connectionRequestUrl, resolveConnection } from "./connection-resolver.js";
import { getProviderByName, toRemoteProvider } from "./provider-definitions.js";
import type { ProfileContext } from "./provider-profiles.js";
-import { RefusingHandler, buildWireHandler, effectiveBaseUrl } from "./wire-handler.js";
+import {
+ RefusingHandler,
+ buildWireHandler,
+ describeConnectionWire,
+ effectiveBaseUrl,
+} from "./wire-handler.js";
import { TryInTurnHandler } from "./wire-try-in-turn.js";
const cachePath = new URL(
"../test-fixtures/catalog-v3/wire-g-20261012101007285-7770c36e.json",
@@ -419,3 +424,13 @@ test("RefusingHandler returns 400 and supplied message", async () => {
error: { type: "invalid_request_error", message: "claudish: unsupported protocol" },
});
});
+
+test("wire summary describes the exact connection API, URL, token field and effort path", () => {
+ const result = resolveConnection("openai", "gpt-6.1-sol", cachePath);
+ if (!result.ok) throw new Error("missing fixture connection");
+ const summary = describeConnectionWire(result.connection);
+ expect(summary).toContain("openai/direct-api · gpt-6.1-sol");
+ expect(summary).toContain("responses https://api.openai.com/v1/responses");
+ expect(summary).toContain("limit max_output_tokens");
+ expect(summary).toContain("effort /reasoning/effort");
+});
diff --git a/packages/cli/src/providers/wire-handler.ts b/packages/cli/src/providers/wire-handler.ts
index 3ede4d29..778f1be6 100644
--- a/packages/cli/src/providers/wire-handler.ts
+++ b/packages/cli/src/providers/wire-handler.ts
@@ -16,6 +16,7 @@ import type { BaseAPIFormat } from "../adapters/base-api-format.js";
import { CodexAPIFormat } from "../adapters/codex-api-format.js";
import { GeminiAPIFormat } from "../adapters/gemini-api-format.js";
import { OpenAIAPIFormat } from "../adapters/openai-api-format.js";
+import { OpenRouterAPIFormat } from "../adapters/openrouter-api-format.js";
import { ComposedHandler } from "../handlers/composed-handler.js";
import { wrapAnthropicError } from "../handlers/shared/anthropic-error.js";
import type { RemoteProvider } from "../handlers/shared/remote-provider-types.js";
@@ -74,6 +75,43 @@ export function effectiveBaseUrl(
return { baseUrl: resolvedBaseUrl.replace(/\/+$/, ""), overridden: true };
}
+/**
+ * One line saying how a connection is called, for `--probe`: the API and URL,
+ * the output-limit field, the reasoning encoding, and the modes and speeds it
+ * offers. Every part is the wire's own value or its status, never derived.
+ */
+export function describeConnectionWire(connection: ResolvedConnection): string {
+ const where = `${connection.route.routeId}/${connection.route.routeProfileId} · ${connection.externalModelId}`;
+ const { wire } = connection;
+ if (wire.status === "unsupported") return `${where}: unsupported (${wire.protocol})`;
+ if (wire.status === "unknown") {
+ const apis = Object.keys(connection.profile.apis).join(", ") || "none";
+ return `${where}: wire unknown — tries ${apis} in turn`;
+ }
+ const base = connectionBaseUrl(connection, wire.api);
+ const url = base ? wireRequestUrl(base, wire.api, connection.externalModelId) : "no base URL";
+ const status = (value: string | { status: string }) =>
+ typeof value === "string" ? value : value.status;
+ const parts = [`${wire.api} ${url}`, `limit ${status(wire.tokenParam)}`];
+ const reasoning = wire.reasoning;
+ if (reasoning.status === "supported") {
+ const effort = reasoning.effort;
+ parts.push(
+ "path" in effort
+ ? `effort ${effort.path} [${Object.keys(effort.values).join(",")}]`
+ : `effort ${effort.status}`
+ );
+ if (reasoning.mode.status === "supported") {
+ parts.push(`modes ${Object.keys(reasoning.mode.values).join(",")}`);
+ }
+ } else {
+ parts.push(`reasoning ${reasoning.status}`);
+ }
+ if (wire.speed.status === "supported")
+ parts.push(`speeds ${Object.keys(wire.speed.values).join(",")}`);
+ return `${where}: ${parts.join(" · ")}`;
+}
+
/** Pin a transport's endpoint to `url`, delegating everything else to it. */
function withEndpoint(inner: ProviderTransport, url: string): ProviderTransport {
return new Proxy(inner, {
@@ -89,11 +127,14 @@ function adapterFor(
api: WireApi,
modelName: string,
providerName: string,
- definitionName: string
+ definitionName: string,
+ vendor: string | undefined
): BaseAPIFormat {
switch (api) {
case "chat-completions":
- return new OpenAIAPIFormat(modelName);
+ return definitionName === "openrouter"
+ ? new OpenRouterAPIFormat(modelName, { vendor: vendor ?? "" })
+ : new OpenAIAPIFormat(modelName);
case "responses":
return new CodexAPIFormat(modelName, undefined, {
codexExtras: definitionName === "openai-codex",
@@ -275,7 +316,13 @@ export function buildKnownWireHandler(
if (overridden) log(`[Wire] ${definitionName}: base URL overridden by user config → ${baseUrl}`);
const transport = transportFor(definitionName, wire.api, ctx, url);
- const adapter = adapterFor(wire.api, ctx.modelName, ctx.provider.name, definitionName);
+ const adapter = adapterFor(
+ wire.api,
+ ctx.modelName,
+ ctx.provider.name,
+ definitionName,
+ connection.vendor
+ );
const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
adapter,
...(wire.api === "chat-completions" || wire.api === "responses"
diff --git a/packages/cli/src/proxy-server.ts b/packages/cli/src/proxy-server.ts
index 6791aca3..998acb83 100644
--- a/packages/cli/src/proxy-server.ts
+++ b/packages/cli/src/proxy-server.ts
@@ -378,7 +378,10 @@ export async function createProxyServer(
// the transport's getHeaders() (single source of truth) — the legacy
// openrouterApiKey param is no longer the signing source.
const orProvider = new OpenRouterProviderTransport("", modelId);
- const orAdapter = new OpenRouterAPIFormat(modelId);
+ const orAdapter = new OpenRouterAPIFormat(
+ modelId,
+ wired.connection ? { vendor: wired.connection.vendor ?? "" } : {}
+ );
openRouterHandlers.set(
modelId,
new ComposedHandler(orProvider, modelId, modelId, port, {
diff --git a/packages/cli/src/transform.ts b/packages/cli/src/transform.ts
index 9d2dbcd0..1ec23e50 100644
--- a/packages/cli/src/transform.ts
+++ b/packages/cli/src/transform.ts
@@ -379,11 +379,8 @@ export function stripBillingHeader(text: string): string {
export function transformOpenAIToClaude(claudeRequestInput: any): {
claudeRequest: any;
droppedParams: string[];
- isO3Model?: boolean;
} {
const req = JSON.parse(JSON.stringify(claudeRequestInput));
- const isO3Model =
- typeof req.model === "string" && (req.model.includes("o3") || req.model.includes("o1"));
if (Array.isArray(req.system)) {
// Extract text content from each system message item
@@ -438,6 +435,5 @@ export function transformOpenAIToClaude(claudeRequestInput: any): {
return {
claudeRequest: req,
droppedParams: dropped,
- isO3Model,
};
}