Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): use adaptive thinking for the Claude 5 models

Alex Castillo243df97f1624
diff --git a/packages/trilium-core/src/services/llm/providers/anthropic.spec.ts b/packages/trilium-core/src/services/llm/providers/anthropic.spec.ts
index f8c52dce2e..82e4f44cb3 100644
--- a/packages/trilium-core/src/services/llm/providers/anthropic.spec.ts
+++ b/packages/trilium-core/src/services/llm/providers/anthropic.spec.ts
@@ -234,6 +234,44 @@ describe("AnthropicProvider tool handling", () => {
});
}
});
+
+ it("uses adaptive thinking on the Claude 5 generation, which rejects manual budgets", () => {
+ const provider = new AnthropicProvider("sk-ant-test");
+
+ const models = [
+ "claude-opus-5", "claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5",
+ "claude-fable-5", "claude-fable-5-1", "claude-mythos-5-1"
+ ];
+ for (const model of models) {
+ streamTextMock.mockClear();
+ provider.chat([{ role: "user", content: "hi" }], { model, enableExtendedThinking: true });
+
+ const opts = streamTextMock.mock.calls[0][0] as any;
+ expect(opts.providerOptions.anthropic.thinking).toEqual({
+ type: "adaptive",
+ display: "summarized"
+ });
+ }
+ });
+
+ it("keeps the manual budget on models that require it", () => {
+ const provider = new AnthropicProvider("sk-ant-test");
+
+ const models = [
+ "claude-haiku-4-5-20251001", "claude-opus-4-5", "claude-sonnet-4-5-20250929",
+ "claude-mythos-preview"
+ ];
+ for (const model of models) {
+ streamTextMock.mockClear();
+ provider.chat([{ role: "user", content: "hi" }], { model, enableExtendedThinking: true });
+
+ const opts = streamTextMock.mock.calls[0][0] as any;
+ expect(opts.providerOptions.anthropic.thinking).toEqual({
+ type: "enabled",
+ budgetTokens: 10000
+ });
+ }
+ });
});
/**
diff --git a/packages/trilium-core/src/services/llm/providers/anthropic.ts b/packages/trilium-core/src/services/llm/providers/anthropic.ts
index 7fb419d8ca..9a0afd832f 100644
--- a/packages/trilium-core/src/services/llm/providers/anthropic.ts
+++ b/packages/trilium-core/src/services/llm/providers/anthropic.ts
@@ -24,13 +24,15 @@ const BROWSER_ACCESS_HEADER = { "anthropic-dangerous-direct-browser-access": "tr
const CACHE_CONTROL = { anthropic: { cacheControl: { type: "ephemeral" as const } } };
/**
- * Models that support adaptive extended thinking. Opus 4.7 / 4.8 and Sonnet 5
- * reject the manual `{ type: "enabled", budgetTokens }` form with a 400 and
- * accept adaptive only; Opus 4.6 and Sonnet 4.6 accept both but prefer adaptive.
- * Everything else (older Opus/Sonnet, Haiku 4.5) only supports the manual budget
+ * Models that support adaptive extended thinking. Opus 4.7 / 4.8 and the whole
+ * Claude 5 generation (Opus, Sonnet, Haiku, Fable, Mythos 5+) reject the manual
+ * `{ type: "enabled", budgetTokens }` form with a 400 and accept adaptive only;
+ * Opus 4.6 and Sonnet 4.6 accept both but prefer adaptive. Everything else
+ * (older Opus/Sonnet, Haiku 4.5, Mythos Preview) only supports the manual budget
* form.
*/
-const ADAPTIVE_THINKING_MODELS = /^claude-(?:opus-4-[678]|sonnet-(?:4-6|5))/;
+const ADAPTIVE_THINKING_MODELS =
+ /^claude-(?:opus-4-[678]|sonnet-4-6|(?:opus|sonnet|haiku|mythos)-[5-9]|fable-)/;
export class AnthropicProvider extends BaseProvider {
name = "anthropic";