@@ -8,6 +8,16 @@ import {
88
99 export type ThinkingEffort = "low" | "medium" | "high" | "xhigh";
1010
11+// Budget tokens used when routing through Zen (which only supports the
12+// legacy `thinking: { type: "enabled", budget_tokens: N }` API, not the
13+// newer effort-based API that requires the `effort-2025-11-24` beta).
14+const ANTHROPIC_ZEN_BUDGET: Record<ThinkingEffort, number> = {
15+ low: 4_096,
16+ medium: 8_192,
17+ high: 16_384,
18+ xhigh: 32_768,
19+};
20+
1121 type CacheFamily = "google" | "anthropic" | "none";
1222
1323 const GEMINI_BUDGET: Record<ThinkingEffort, number> = {
@@ -28,9 +38,24 @@ function clampEffort(
2838 }
2939
3040 function getAnthropicThinkingOptions(
31- modelId: string,
41+ modelString: string,
3242 effort: ThinkingEffort,
3343 ): Record<string, unknown> {
44+ const { provider, modelId } = parseModelString(modelString);
45+ // Zen proxies claude models but only supports the legacy
46+ // `thinking: { type: "enabled", budget_tokens: N }` API.
47+ // The newer effort-based API adds an `effort-2025-11-24` beta header and
48+ // sends `output_config: { effort }` which Zen rejects.
49+ if (provider === "zen") {
50+ return {
51+ anthropic: {
52+ thinking: {
53+ type: "enabled",
54+ budgetTokens: ANTHROPIC_ZEN_BUDGET[effort],
55+ },
56+ },
57+ };
58+ }
3459 const isOpus = /^claude-opus-4/.test(modelId);
3560 const xhighMapping = isOpus ? "max" : "high";
3661 const mapped = effort === "xhigh" ? xhighMapping : effort;
@@ -38,18 +63,20 @@ function getAnthropicThinkingOptions(
3863 }
3964
4065 function getOpenAIThinkingOptions(
41- modelId: string,
66+ modelString: string,
4267 effort: ThinkingEffort,
4368 ): Record<string, unknown> {
69+ const { modelId } = parseModelString(modelString);
4470 const supportsXhigh = /^gpt-5\.[2-9]/.test(modelId) || /^o4/.test(modelId);
4571 const clamped = supportsXhigh ? effort : clampEffort(effort, "high");
4672 return { openai: { reasoningEffort: clamped, reasoningSummary: "auto" } };
4773 }
4874
4975 function getGeminiThinkingOptions(
50- modelId: string,
76+ modelString: string,
5177 effort: ThinkingEffort,
5278 ): Record<string, unknown> {
79+ const { modelId } = parseModelString(modelString);
5380 if (/^gemini-3/.test(modelId)) {
5481 return {
5582 google: {
@@ -73,7 +100,10 @@ function getGeminiThinkingOptions(
73100
74101 interface ThinkingStrategy {
75102 supports: (modelString: string) => boolean;
76- build: (modelId: string, effort: ThinkingEffort) => Record<string, unknown>;
103+ build: (
104+ modelString: string,
105+ effort: ThinkingEffort,
106+ ) => Record<string, unknown>;
77107 }
78108
79109 const THINKING_STRATEGIES: readonly ThinkingStrategy[] = [
@@ -97,10 +127,9 @@ export function getThinkingProviderOptions(
97127 ): Record<string, unknown> | null {
98128 if (!supportsThinking(modelString)) return null;
99129
100- const { modelId } = parseModelString(modelString);
101130 for (const strategy of THINKING_STRATEGIES) {
102131 if (!strategy.supports(modelString)) continue;
103- return strategy.build(modelId, effort);
132+ return strategy.build(modelString, effort);
104133 }
105134
106135 return null;