diff --git a/src/services/api/claude.ts b/src/services/api/claude.ts index af310af8f..a52df316d 100644 --- a/src/services/api/claude.ts +++ b/src/services/api/claude.ts @@ -1777,7 +1777,9 @@ async function* queryModel( // (messagesForAPI, system, allTools, betas — the entire request-building // context), which would otherwise be pinned until the promise resolves. // Also capture thinking params for Langfuse observability. - let langfuseThinking: { type: string; budgetTokens?: number } | undefined + // Pass the entire thinking config object so all fields (type, budget_tokens, + // and any future additions) flow through without cherry-picking. + let langfuseThinking: BetaMessageStreamParams['thinking'] | undefined { const queryParams = paramsFromContext({ model: options.model, @@ -1788,13 +1790,7 @@ async function* queryModel( const logThinkingType = queryParams.thinking?.type ?? 'disabled' const logEffortValue = queryParams.output_config?.effort if (queryParams.thinking && queryParams.thinking.type !== 'disabled') { - langfuseThinking = { - type: queryParams.thinking.type, - ...('budget_tokens' in queryParams.thinking && - typeof queryParams.thinking.budget_tokens === 'number' && { - budgetTokens: queryParams.thinking.budget_tokens, - }), - } + langfuseThinking = queryParams.thinking } void options.getToolPermissionContext().then(permissionContext => { logAPIQuery({ diff --git a/src/services/langfuse/tracing.ts b/src/services/langfuse/tracing.ts index ff57b334e..f0a2cebdd 100644 --- a/src/services/langfuse/tracing.ts +++ b/src/services/langfuse/tracing.ts @@ -78,9 +78,14 @@ export function recordLLMObservation( endTime?: Date completionStartTime?: Date tools?: unknown - /** Thinking depth configuration used for this request */ + /** Thinking depth configuration used for this request. + * Accepts the full API thinking config object. Fields: + * - type: thinking mode ("enabled", "adaptive", "disabled") + * - budget_tokens (snake_case, from Anthropic API) or budgetTokens (camelCase) + */ thinking?: { type: string + budget_tokens?: number budgetTokens?: number } }, @@ -103,8 +108,8 @@ export function recordLLMObservation( provider: params.provider, model: params.model, ...(params.thinking && { thinkingType: params.thinking.type }), - ...(params.thinking?.budgetTokens !== undefined && { - thinkingBudgetTokens: params.thinking.budgetTokens, + ...(params.thinking && (params.thinking.budget_tokens !== undefined || params.thinking.budgetTokens !== undefined) && { + thinkingBudgetTokens: (params.thinking.budget_tokens ?? params.thinking.budgetTokens) as number, }), }, ...(params.completionStartTime && { completionStartTime: params.completionStartTime }),