diff --git a/packages/ai/src/stream.ts b/packages/ai/src/stream.ts index 789fd937f..826104e6e 100644 --- a/packages/ai/src/stream.ts +++ b/packages/ai/src/stream.ts @@ -391,7 +391,7 @@ function resolveOpenAiReasoningEffort( options?: SimpleStreamOptions, ): Effort | undefined { const reasoning = options?.reasoning; - if (!reasoning) return undefined; + if (!reasoning || !model.reasoning) return undefined; return requireSupportedEffort(model, reasoning); } @@ -424,9 +424,9 @@ function mapOptionsForApi( switch (model.api) { case "anthropic-messages": { - // Explicitly disable thinking when reasoning is not specified + // Explicitly disable thinking when reasoning is not specified or model doesn't support it const reasoning = options?.reasoning; - if (!reasoning) { + if (!reasoning || !model.reasoning) { return castApi<"anthropic-messages">({ ...base, thinkingEnabled: false, @@ -548,10 +548,10 @@ function mapOptionsForApi( }); case "google-generative-ai": { - // Explicitly disable thinking when reasoning is not specified + // Explicitly disable thinking when reasoning is not specified or model doesn't support it // This is needed because Gemini has "dynamic thinking" enabled by default const reasoning = options?.reasoning; - if (!reasoning) { + if (!reasoning || !model.reasoning) { return castApi<"google-generative-ai">({ ...base, thinking: { enabled: false }, @@ -587,7 +587,7 @@ function mapOptionsForApi( case "google-gemini-cli": { const reasoning = options?.reasoning; - if (!reasoning) { + if (!reasoning || !model.reasoning) { return castApi<"google-gemini-cli">({ ...base, thinking: { enabled: false }, @@ -637,9 +637,9 @@ function mapOptionsForApi( } case "google-vertex": { - // Explicitly disable thinking when reasoning is not specified + // Explicitly disable thinking when reasoning is not specified or model doesn't support it const reasoning = options?.reasoning; - if (!reasoning) { + if (!reasoning || !model.reasoning) { return castApi<"google-vertex">({ ...base, thinking: { enabled: false },