@@ -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 {
@@ -518,6 +519,11 @@ function adaptiveEffort(effort: string): string {
518519 return effort === "minimal" ? "low" : effort ;
519520}
520521
522+ function defaultReasoningEffort ( provider : OcxProviderConfig , modelId : string ) : string | undefined {
523+ const value = modelRecordValue ( provider . modelDefaultReasoningEfforts , modelId ) ;
524+ return typeof value === "string" && value . trim ( ) ? value . trim ( ) : undefined ;
525+ }
526+
521527function usageFromAnthropic ( usage : Record < string , number > | undefined ) : OcxUsage | undefined {
522528 if ( ! usage ) return undefined ;
523529 const hasCache = usage . cache_read_input_tokens !== undefined || usage . cache_creation_input_tokens !== undefined ;
@@ -926,16 +932,17 @@ export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetenti
926932 // anyway, and thinking shares the caller's `max_tokens` — which truncates a small-budget
927933 // request before it can emit its stop sequence (#545). Say "disabled" out loud where the
928934 // model both defaults to thinking and accepts being told not to.
929- if ( parsed . options . reasoning === "none" && supportsExplicitThinkingDisable ( parsed . modelId ) ) {
935+ const effectiveReasoning = parsed . options . reasoning ?? defaultReasoningEffort ( provider , parsed . modelId ) ;
936+ if ( effectiveReasoning === "none" && supportsExplicitThinkingDisable ( parsed . modelId ) ) {
930937 body . thinking = { type : "disabled" } ;
931- } else if ( typeof parsed . options . reasoning === "string" && parsed . options . reasoning !== "none" ) {
938+ } else if ( typeof effectiveReasoning === "string" && effectiveReasoning !== "none" ) {
932939 if ( usesAdaptiveThinking ( parsed . modelId ) ) {
933940 // Adaptive-thinking models replace the token budget with an effort knob and reject
934941 // `thinking.type: "enabled"` outright. `max_tokens` still caps thinking plus visible
935942 // output, so high effort needs the same total-token headroom as budget thinking or a
936943 // default 8192-token request can spend everything on thought and return empty text.
937944 body . thinking = { type : "adaptive" } ;
938- const effort = adaptiveEffort ( parsed . options . reasoning ) ;
945+ const effort = adaptiveEffort ( effectiveReasoning ) ;
939946 body . output_config = { effort } ;
940947 const explicitMaxOut = parsed . options . maxOutputTokens ;
941948 const wantBudget = reasoningBudget ( effort ) ;
@@ -951,7 +958,7 @@ export function createAnthropicAdapter(provider: OcxProviderConfig, cacheRetenti
951958 // 400s ("max_tokens must be greater than thinking.budget_tokens"). Size them so max_tokens
952959 // always exceeds the budget within a model-safe ceiling, reserving room for visible output.
953960 const maxOut = parsed . options . maxOutputTokens ?? DEFAULT_MAX_TOKENS ;
954- const wantBudget = reasoningBudget ( parsed . options . reasoning ) ;
961+ const wantBudget = reasoningBudget ( effectiveReasoning ) ;
955962 const maxTokens = Math . min ( REASONING_MAX_TOKENS_CEILING , Math . max ( maxOut , wantBudget + OUTPUT_HEADROOM ) ) ;
956963 const budget = Math . max ( MIN_THINKING_BUDGET , Math . min ( wantBudget , maxTokens - OUTPUT_FLOOR ) ) ;
957964 body . max_tokens = maxTokens ;
0 commit comments