@@ -27,6 +27,7 @@ import { CLAUDE_CODE_HEADERS, claudeCodeSessionId } from "./client-fingerprint";
2727import { buildNonOpenAIToolCatalogNudgeForTools } from "./tool-catalog-nudge" ;
2828import { decodeServerSentEvents } from "../lib/sse-decoder" ;
2929import { isTranslatorBudgetExceededError , retainTranslatedEventBatch , type TranslatorBudget } from "../lib/translator-budget" ;
30+ import { modelRecordValue } from "../reasoning-effort" ;
3031
3132/** Map a user content part to an Anthropic content block (text or image source). */
3233function toAnthropicContentPart ( p : OcxContentPart ) : unknown {
@@ -513,6 +514,11 @@ function supportsExplicitThinkingDisable(modelId: string): boolean {
513514 return meetsFamilyMinimum ( modelId , EXPLICIT_THINKING_DISABLE_FAMILY_MINIMUMS ) ;
514515}
515516
517+ function defaultReasoningEffort ( provider : OcxProviderConfig , modelId : string ) : string | undefined {
518+ const value = modelRecordValue ( provider . modelDefaultReasoningEfforts , modelId ) ;
519+ return typeof value === "string" && value . trim ( ) ? value . trim ( ) : undefined ;
520+ }
521+
516522/** `output_config.effort` accepts low|medium|high|xhigh|max — "minimal" is rejected with a 400. */
517523function adaptiveEffort ( effort : string ) : string {
518524 return effort === "minimal" ? "low" : effort ;
@@ -929,18 +935,19 @@ export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetenti
929935 // anyway, and thinking shares the caller's `max_tokens` — which truncates a small-budget
930936 // request before it can emit its stop sequence (#545). Say "disabled" out loud where the
931937 // model both defaults to thinking and accepts being told not to.
932- if ( parsed . options . reasoning === "none" && supportsExplicitThinkingDisable ( parsed . modelId ) ) {
938+ const effectiveReasoning = parsed . options . reasoning ?? defaultReasoningEffort ( provider , parsed . modelId ) ;
939+ if ( effectiveReasoning === "none" && supportsExplicitThinkingDisable ( parsed . modelId ) ) {
933940 body . thinking = { type : "disabled" } ;
934- } else if ( typeof parsed . options . reasoning === "string" && parsed . options . reasoning !== "none" ) {
941+ } else if ( typeof effectiveReasoning === "string" && effectiveReasoning !== "none" ) {
935942 if ( usesAdaptiveThinking ( parsed . modelId ) ) {
936943 // Adaptive-thinking models replace the token budget with an effort knob and reject
937944 // `thinking.type: "enabled"` outright. `max_tokens` still caps thinking plus visible
938945 // output, so high effort needs the same total-token headroom as budget thinking or a
939946 // default 8192-token request can spend everything on thought and return empty text.
940947 body . thinking = { type : "adaptive" } ;
941- body . output_config = { effort : adaptiveEffort ( parsed . options . reasoning ) } ;
948+ body . output_config = { effort : adaptiveEffort ( effectiveReasoning ) } ;
942949 const explicitMaxOut = parsed . options . maxOutputTokens ;
943- const wantBudget = reasoningBudget ( parsed . options . reasoning ) ;
950+ const wantBudget = reasoningBudget ( effectiveReasoning ) ;
944951 const floor = wantBudget + OUTPUT_HEADROOM ;
945952 // Preserve explicit caller limits as-is; for omitted limits use the adaptive ceiling
946953 // so effort=max (budget=32k) still leaves OUTPUT_HEADROOM tokens for visible output.
@@ -953,7 +960,7 @@ export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetenti
953960 // 400s ("max_tokens must be greater than thinking.budget_tokens"). Size them so max_tokens
954961 // always exceeds the budget within a model-safe ceiling, reserving room for visible output.
955962 const maxOut = parsed . options . maxOutputTokens ?? DEFAULT_MAX_TOKENS ;
956- const wantBudget = reasoningBudget ( parsed . options . reasoning ) ;
963+ const wantBudget = reasoningBudget ( effectiveReasoning ) ;
957964 const maxTokens = Math . min ( REASONING_MAX_TOKENS_CEILING , Math . max ( maxOut , wantBudget + OUTPUT_HEADROOM ) ) ;
958965 const budget = Math . max ( MIN_THINKING_BUDGET , Math . min ( wantBudget , maxTokens - OUTPUT_FLOOR ) ) ;
959966 body . max_tokens = maxTokens ;
0 commit comments