Skip to content

Commit 433c1fd

Browse files
authored
fix(ai): take Claude thinking off support from Anthropic's models.dev entry (#12489)
Fixes #12429. ## Problem Claude Opus 5.5 and Sonnet 5.5 reject `thinking: {type: "disabled"}` on every host. pi's catalog only marked "off" unsupported through hand-written per-provider lists (`claude55ThinkingLevels()`, `DISABLED_THINKING_MODELS`, a Fable substring rule). Hosts the lists missed still offered "off", and `anthropic-messages` sent `disabled`: ``` pi -p --provider github-copilot --model claude-sonnet-5.5 --thinking off "hi" 400 ... To turn thinking off on this model, send "thinking": {"type": "between_tools"} instead of {"type": "disabled"} ... ``` Affected: GitHub Copilot (Sonnet 5.5), Cloudflare AI Gateway and Vercel AI Gateway (Opus 5.5, Sonnet 5.5). models.dev already records this. On Anthropic's own entries, `capabilities.reasoning.toggle` is set on every Claude model that can turn thinking off and is absent on Opus 5.5, Sonnet 5.5, and Fable 5.x. Hosts such as Copilot, OpenCode, and Cloudflare list no toggle on any Claude model, so the host entry cannot decide it. ## Fix One Claude family rule (`catalog/families/anthropic.ts`) marks `off: null` when Anthropic's own models.dev entry for the model has no thinking toggle. Every host uses it. The model is found through models.dev's `canonical_id` (newly normalized in `sources/models-dev.ts`). For hosts not built from models.dev (OpenRouter, Vercel, Radius), it falls back to the host's spelling of Anthropic's id: dotted, `anthropic/`-prefixed, or with a `-batch`/`-fast` suffix. It replaces `DISABLED_THINKING_MODELS` and the `off` part of `claude55ThinkingLevels()` (now `CLAUDE_55_THINKING_LEVELS`). The Fable `off: null` rule moves onto the authored `claude-fable-5-2` (used only when models.dev does not list it). New Claude models get the right "off" once models.dev lists them for Anthropic. `between_tools` is not used. Live on Copilot it is accepted only by Sonnet 5.5; Opus 5.5, Haiku 5.5, Sonnet 5, and Haiku 4.5 reject it. ## Catalog diff (`npm run diff:model-catalog` against main) Only additions of `"off": null`, on Opus 5.5 and Sonnet 5.5: - `github-copilot/claude-sonnet-5.5` - `cloudflare-ai-gateway/claude-{opus,sonnet}-5-5` - `vercel-ai-gateway/anthropic/claude-{opus,sonnet}-5.5` and their `-batch`/`-fast` variants - `amazon-bedrock/*claude-{opus,sonnet}-5-5`. Bedrock never sent `disabled`; "off" there sent no thinking field and silently used the model's default. Now it is clamped like everywhere else. Anthropic, OpenRouter, OpenCode, and Radius are unchanged, so the rule matches the lists it replaces. The change is catalog-only and works with released clients. ## Testing - `test/claude-model-generation.test.ts` generates the catalog from mocked models.dev data: Copilot entries follow Anthropic's toggle, a Bedrock id resolves only through `canonical_id`, and the authored Fable 5.2 keeps `off` unsupported without models.dev data. Each case fails without the code it covers. - `test/github-copilot-anthropic.test.ts`: Copilot Sonnet 5.5 does not offer "off". - Live on Copilot with `--thinking off`: Sonnet 5.5 and Opus 5.5 now succeed at the lowest offered level (1.6.0 returns 400). Haiku 5.5 and Sonnet 5 still run with thinking off.
1 parent 90ef46f commit 433c1fd

8 files changed

Lines changed: 167 additions & 30 deletions

File tree

‎packages/ai/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- Fixed the model catalog still listing `gpt-5-chat-latest` for `openai` and `azure` after OpenAI shut it down on July 23, 2026 ([#12202](https://github.com/earendil-works/pi/issues/12202))
3838
- Fixed `openai-completions` dropping OpenRouter's `native_finish_reason`, the upstream provider's own finish reason. `rawStopReason` now records it next to `finish_reason`, e.g. `stop.MALFORMED_RESPONSE`, and error messages include it, e.g. `Provider finish_reason: error (native_finish_reason: MALFORMED_FUNCTION_CALL)`. Stop reasons are unchanged ([#11931](https://github.com/earendil-works/pi/issues/11931))
3939
- Fixed GitHub Copilot listing classifier models the account cannot use, such as `microsoft-decision-1` on accounts whose plan does not include it, where every call failed with HTTP 400. After OAuth login or the next token refresh, only the decision models in the account's Copilot model catalog are listed ([#12395](https://github.com/earendil-works/pi/issues/12395))
40+
- Fixed HTTP 400 with thinking `off` on Claude Sonnet 5.5 through GitHub Copilot, and on Claude Opus 5.5 and Sonnet 5.5 through Cloudflare AI Gateway and Vercel AI Gateway, which reject `thinking: {type: "disabled"}`. The catalog now takes whether a Claude model can turn thinking off from the thinking toggle on Anthropic's own models.dev entry, for every host that serves it, and selecting `off` on those models uses the lowest supported level ([#12429](https://github.com/earendil-works/pi/issues/12429))
4041

4142
## [1.6.0] - 2026-11-20
4243

‎packages/ai/catalog/build.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function buildCatalog(
141141
applyDeepSeekCompatRules(model);
142142
applyModelsDevEffort(model, ctx.modelsDevSource(model));
143143
applyOpenAiFamilyRules(model);
144-
applyClaudeFamilyRules(model);
144+
applyClaudeFamilyRules(model, ctx);
145145
applyDeepSeekFamilyRules(model);
146146
}
147147
for (const model of chat) definition.finalize?.(model, ctx);

‎packages/ai/catalog/families/anthropic.ts‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// (anthropic/claude-opus-4.8), and dated (claude-opus-5-20260723).
44

55
import type { Model, ThinkingLevelMap } from "../../src/types.ts";
6-
import { type ChatModel, mergeCompat, mergeThinking } from "../define.ts";
6+
import { type ChatModel, mergeCompat, mergeThinking, type ProviderContext } from "../define.ts";
7+
import { normalizeModelsDevModel } from "../sources/models-dev.ts";
78

89
function stripPrefix(modelId: string): string {
910
return modelId.toLowerCase().replace(/^~?anthropic\//, "");
@@ -19,11 +20,6 @@ export function supportsClaudeMidConvoEffort(modelId: string): boolean {
1920
);
2021
}
2122

22-
// Claude models that accept `thinking: {type: "disabled"}` alongside per-message effort.
23-
// Opus 5.5, Sonnet 5.5, Fable 5.1/5.2, and Mythos 5.1/5.2 reject it.
24-
// https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking
25-
const DISABLED_THINKING_MODELS = new Set(["claude-opus-5", "claude-haiku-5-5", "claude-haiku-5.5"]);
26-
2723
/** Models that accept system messages and tool changes after the conversation starts. */
2824
export function supportsClaudeMidConvoSystemMessages(modelId: string): boolean {
2925
return (
@@ -33,12 +29,9 @@ export function supportsClaudeMidConvoSystemMessages(modelId: string): boolean {
3329
);
3430
}
3531

36-
/** Enable per-message effort changes. Models that cannot disable thinking with it lose "off". */
32+
/** Enable per-message effort changes. */
3733
export function enableClaudeMidConvoEffort(model: Model<"anthropic-messages">): void {
3834
mergeCompat(model, { supportsMidConvoEffort: true });
39-
if (!DISABLED_THINKING_MODELS.has(stripPrefix(model.id).replace(/-\d{8}$/, ""))) {
40-
mergeThinking(model, { off: null });
41-
}
4235
}
4336

4437
function idIncludesAny(modelId: string, fragments: readonly string[]): boolean {
@@ -102,10 +95,11 @@ const XHIGH_AND_MAX_EFFORT = [
10295
* "max" is available on all adaptive-thinking Claude models; "xhigh" only on
10396
* Opus 4.7/4.8/5, Sonnet 5, Haiku 5.5, and Fable 5.
10497
*/
105-
export function applyClaudeFamilyRules(model: ChatModel): void {
98+
export function applyClaudeFamilyRules(model: ChatModel, ctx: ProviderContext): void {
10699
if (idIncludesAny(model.id, MAX_EFFORT_ONLY)) mergeThinking(model, { max: "max" });
107100
if (idIncludesAny(model.id, XHIGH_AND_MAX_EFFORT)) mergeThinking(model, { xhigh: "xhigh", max: "max" });
108-
if (model.id.includes("fable-5")) mergeThinking(model, { off: null, xhigh: "xhigh", max: "max" });
101+
if (model.id.includes("fable-5")) mergeThinking(model, { xhigh: "xhigh", max: "max" });
102+
if (cannotTurnThinkingOff(model, ctx)) mergeThinking(model, { off: null });
109103
if (model.api !== "anthropic-messages") return;
110104
const messagesModel = model as Model<"anthropic-messages">;
111105
if (isClaudeLatestAlias(model.id) || idIncludesAny(model.id, ADAPTIVE_THINKING)) {
@@ -117,18 +111,33 @@ export function applyClaudeFamilyRules(model: ChatModel): void {
117111
}
118112

119113
/**
120-
* models.dev may list Opus 5.5, Sonnet 5.5, and Haiku 5.5 before their effort
121-
* metadata is complete. Haiku 5.5 accepts disabled thinking; Opus 5.5 and
122-
* Sonnet 5.5 reject it.
114+
* Whether Anthropic's own models.dev entry for this Claude model lists no thinking toggle. Such
115+
* models reject `thinking: {type: "disabled"}` on every host (Opus 5.5, Sonnet 5.5, Fable 5.x),
116+
* but most other hosts' entries list no toggle on any Claude model (#12429). Hosts built from
117+
* models.dev name Anthropic's entry in `canonical_id`. Vercel's gateway, which has no thinking
118+
* metadata of its own, spells Anthropic's id dotted, `anthropic/`-prefixed, and with `-batch` or
119+
* `-fast` variants.
123120
*/
124-
export function claude55ThinkingLevels(modelId: string): ThinkingLevelMap {
125-
return {
126-
...(modelId.includes("haiku") ? {} : { off: null }),
127-
minimal: null,
128-
low: "low",
129-
medium: "medium",
130-
high: "high",
131-
xhigh: "xhigh",
132-
max: "max",
133-
};
121+
function cannotTurnThinkingOff(model: ChatModel, ctx: ProviderContext): boolean {
122+
const canonicalId = ctx.modelsDevSource(model)?.canonicalId ?? `anthropic/${anthropicModelId(model.id)}`;
123+
if (!canonicalId.startsWith("anthropic/")) return false;
124+
const entry = ctx.sources.modelsDev.anthropic?.models?.[canonicalId.slice("anthropic/".length)];
125+
const options = entry && normalizeModelsDevModel(entry).reasoningOptions;
126+
return options !== undefined && !options.some((option) => option.type === "toggle");
134127
}
128+
129+
function anthropicModelId(modelId: string): string {
130+
return stripPrefix(modelId)
131+
.replace(/[-:](?:batch|fast)$/, "")
132+
.replace(/(\d)\.(\d)/g, "$1-$2");
133+
}
134+
135+
/** models.dev may list Opus 5.5, Sonnet 5.5, and Haiku 5.5 before their effort metadata is complete. */
136+
export const CLAUDE_55_THINKING_LEVELS: ThinkingLevelMap = {
137+
minimal: null,
138+
low: "low",
139+
medium: "medium",
140+
high: "high",
141+
xhigh: "xhigh",
142+
max: "max",
143+
};

‎packages/ai/catalog/providers/anthropic.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Model } from "../../src/types.ts";
22
import { addMissing, defineProvider, mergeCompat, mergeThinking, modelsDevModels, withInputLimits } from "../define.ts";
33
import {
4-
claude55ThinkingLevels,
4+
CLAUDE_55_THINKING_LEVELS,
55
enableClaudeMidConvoEffort,
66
supportsClaudeMidConvoEffort,
77
supportsClaudeMidConvoSystemMessages,
@@ -30,6 +30,8 @@ const CLAUDE_FABLE_5_2: Model<"anthropic-messages"> = {
3030
cost: { input: 8, output: 40, cacheRead: 0.2, cacheWrite: 10 },
3131
contextWindow: 1000000,
3232
maxTokens: 128000,
33+
// Without a models.dev entry the shared rule cannot tell; Fable rejects `thinking: {type: "disabled"}`.
34+
thinkingLevelMap: { off: null },
3335
};
3436

3537
export default defineProvider({
@@ -40,7 +42,7 @@ export default defineProvider({
4042
api: "anthropic-messages",
4143
baseUrl: "https://api.anthropic.com",
4244
map: (model) => {
43-
if (MODELS_55.has(model.id)) mergeThinking(model, claude55ThinkingLevels(model.id));
45+
if (MODELS_55.has(model.id)) mergeThinking(model, CLAUDE_55_THINKING_LEVELS);
4446
if (MODELS_WITH_1M_CONTEXT.has(model.id)) model.contextWindow = 1000000;
4547
return model;
4648
},

‎packages/ai/catalog/providers/github-copilot.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Api, ClassifierModel, Model, ThinkingLevelMap } from "../../src/types.ts";
22
import { addMissing, type ChatModel, defineProvider, mergeCompat, mergeThinking, modelsDevModels } from "../define.ts";
3-
import { claude55ThinkingLevels, supportsClaudeMidConvoSystemMessages } from "../families/anthropic.ts";
3+
import { CLAUDE_55_THINKING_LEVELS, supportsClaudeMidConvoSystemMessages } from "../families/anthropic.ts";
44
import {
55
enableOpenAiGrammarTools,
66
enableOpenAiMidConvoSystemMessages,
@@ -119,7 +119,7 @@ export default defineProvider({
119119
source.reasoningOptions?.some((option) => option.type === "effort") ?? false,
120120
};
121121
}
122-
if (model.id === "claude-opus-5.5") mergeThinking(result, claude55ThinkingLevels(model.id));
122+
if (model.id === "claude-opus-5.5") mergeThinking(result, CLAUDE_55_THINKING_LEVELS);
123123
return result;
124124
},
125125
}),

‎packages/ai/catalog/sources/models-dev.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ interface V2ApiEntry {
4545
/** The subset of a models.dev v2 model the catalog reads. */
4646
export interface ModelsDevV2Model {
4747
id: string;
48+
/** The lab's own `<provider>/<id>`, e.g. `anthropic/claude-sonnet-5-5`. Some of the lab's own entries omit it. */
49+
canonical_id?: string;
4850
type: string;
4951
name: string;
5052
status?: string;
@@ -86,6 +88,8 @@ export interface ModelsDevApi {
8688
/** A models.dev model normalized for the catalog. */
8789
export interface ModelsDevModel {
8890
id: string;
91+
/** The model's id on its lab's own models.dev provider, e.g. `anthropic/claude-sonnet-5-5`. */
92+
canonicalId?: string;
8993
name: string;
9094
type: string;
9195
status?: string;
@@ -184,6 +188,7 @@ export function normalizeModelsDevModel(model: ModelsDevV2Model): ModelsDevModel
184188
const reasoning = model.capabilities?.reasoning;
185189
return {
186190
id: model.id,
191+
canonicalId: model.canonical_id,
187192
name: model.name,
188193
type: model.type,
189194
status: model.status,
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { spawnSync } from "node:child_process";
2+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3+
import { tmpdir } from "node:os";
4+
import { join } from "node:path";
5+
import { fileURLToPath, pathToFileURL } from "node:url";
6+
import { afterEach, describe, expect, it } from "vitest";
7+
import type { ModelsDevV2Catalog, ModelsDevV2Model } from "../catalog/sources/models-dev.ts";
8+
import { getSupportedThinkingLevels } from "../src/models.ts";
9+
import type { Api, Model } from "../src/types.ts";
10+
import { writeUpstreamMock } from "./catalog-generation-utils.ts";
11+
12+
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
13+
const temporaryRoots: string[] = [];
14+
15+
afterEach(() => {
16+
for (const root of temporaryRoots.splice(0)) rmSync(root, { force: true, recursive: true });
17+
});
18+
19+
function claudeModel(id: string, reasoning: ModelsDevV2Model["capabilities"]["reasoning"], canonicalId?: string) {
20+
return {
21+
id,
22+
...(canonicalId ? { canonical_id: canonicalId } : {}),
23+
type: "chat",
24+
name: id,
25+
modalities: { input: ["text"], output: ["text"] },
26+
capabilities: { tools: { supported: true }, reasoning },
27+
api: {},
28+
} satisfies ModelsDevV2Model;
29+
}
30+
31+
function generateCatalog(modelsDev: ModelsDevV2Catalog, provider: string): Record<string, Model<Api>> {
32+
const root = mkdtempSync(join(tmpdir(), "pi-claude-generation-"));
33+
temporaryRoots.push(root);
34+
const preloadPath = join(root, "mock-catalog.mjs");
35+
const outputPath = join(root, "catalog");
36+
writeUpstreamMock(preloadPath, modelsDev);
37+
const result = spawnSync(
38+
process.execPath,
39+
["--import", pathToFileURL(preloadPath).href, "catalog/generate.ts", "--json-only", "--json-output", outputPath],
40+
{ cwd: packageRoot, encoding: "utf8", timeout: 10_000 },
41+
);
42+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
43+
return JSON.parse(readFileSync(join(outputPath, `providers/${provider}.json`), "utf8")) as Record<
44+
string,
45+
Model<Api>
46+
>;
47+
}
48+
49+
const effort: NonNullable<ModelsDevV2Model["capabilities"]["reasoning"]["effort"]> = [
50+
"low",
51+
"medium",
52+
"high",
53+
"xhigh",
54+
"max",
55+
];
56+
57+
describe("Claude thinking off", () => {
58+
// Copilot lists no thinking toggle on any Claude model; Sonnet 5.5 rejects `disabled` there (#12429).
59+
it("follows the thinking toggle of Anthropic's own models.dev entry on other hosts", () => {
60+
const models = generateCatalog(
61+
{
62+
anthropic: {
63+
models: {
64+
"claude-sonnet-5-5": claudeModel("claude-sonnet-5-5", { supported: true, effort }),
65+
"claude-haiku-5-5": claudeModel("claude-haiku-5-5", { supported: true, toggle: true, effort }),
66+
},
67+
},
68+
"github-copilot": {
69+
models: {
70+
"claude-sonnet-5.5": claudeModel(
71+
"claude-sonnet-5.5",
72+
{ supported: true, effort },
73+
"anthropic/claude-sonnet-5-5",
74+
),
75+
"claude-haiku-5.5": claudeModel(
76+
"claude-haiku-5.5",
77+
{ supported: true, effort },
78+
"anthropic/claude-haiku-5-5",
79+
),
80+
},
81+
},
82+
},
83+
"github-copilot",
84+
);
85+
expect(getSupportedThinkingLevels(models["claude-sonnet-5.5"])).not.toContain("off");
86+
expect(getSupportedThinkingLevels(models["claude-haiku-5.5"])).toContain("off");
87+
});
88+
89+
it("finds Anthropic's entry through canonical_id when the host id does not resemble Anthropic's", () => {
90+
const models = generateCatalog(
91+
{
92+
anthropic: {
93+
models: { "claude-sonnet-5-5": claudeModel("claude-sonnet-5-5", { supported: true, effort }) },
94+
},
95+
"amazon-bedrock": {
96+
models: {
97+
"us.anthropic.claude-sonnet-5-5": claudeModel(
98+
"us.anthropic.claude-sonnet-5-5",
99+
{ supported: true, effort },
100+
"anthropic/claude-sonnet-5-5",
101+
),
102+
},
103+
},
104+
},
105+
"amazon-bedrock",
106+
);
107+
expect(getSupportedThinkingLevels(models["us.anthropic.claude-sonnet-5-5"])).not.toContain("off");
108+
});
109+
110+
it("keeps thinking off unsupported on the authored Fable 5.2 when models.dev does not list it", () => {
111+
const models = generateCatalog({}, "anthropic");
112+
expect(getSupportedThinkingLevels(models["claude-fable-5-2"])).not.toContain("off");
113+
});
114+
});

‎packages/ai/test/github-copilot-anthropic.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ describe("Copilot Claude via Anthropic Messages", () => {
7575
expect(getSupportedThinkingLevels(sonnet46)).not.toContain("xhigh");
7676
});
7777

78+
// Copilot rejects `thinking: {type: "disabled"}` on Sonnet 5.5 (#12429).
79+
it("does not offer thinking off on Claude Sonnet 5.5", () => {
80+
const sonnet55 = getModel("github-copilot", "claude-sonnet-5.5");
81+
expect(getSupportedThinkingLevels(sonnet55)).not.toContain("off");
82+
});
83+
7884
it("uses Bearer auth, Copilot headers, and valid Anthropic Messages payload", async () => {
7985
const model = getModel("github-copilot", "claude-sonnet-4.6");
8086
expect(model.api).toBe("anthropic-messages");

0 commit comments

Comments
 (0)